Esempio n. 1
0
def GetDigits(img):
	img = PreProcessing.Binarization(img)
	cv2.imshow('', img) 
	rows,cols = img.shape[:] 
	cols_coordinates = []
	number=''
	flag = True
	for j in range(0,cols):

		temp_sum = 0
		for i in range(0,rows):
			temp_sum += img[i][j]

		if temp_sum == 255*rows and flag:
			cols_coordinates.append(j+5)
			flag = False
		if temp_sum<255*rows:
			flag = True

	print(cols_coordinates)
	if len(cols_coordinates)>0: 
		x = cols_coordinates[0] 

	for i in range(1,len(cols_coordinates)):
		w = cols_coordinates[i]
		crop_img = img[:,x:w]
		x = w 
		crop_img = FindBoundary(crop_img)
		crop_img = cv2.resize(crop_img, (20,20)) 
		temp_crop_img = []
		for i in range(28):
			temp = []
			for j in range(28):
				temp.append(0)
			temp_crop_img.append(temp)

		for i in range(20):
			for j in range(20):
				if crop_img[i][j]>127:
					crop_img[i][j] = 255
				else:
					crop_img[i][j] = 0

				if crop_img[i][j]==0:
					temp_crop_img[4+i][4+j] = 255  
		cv2.imshow('Boundary', np.float32(temp_crop_img))
		cv2.waitKey(0) 
		pred_digit=get_Prediction(temp_crop_img)
		count=0
		digit=str(pred_digit[0])
		for i in range(20):
			for j in range(20): 
			    if temp_crop_img[4+i][4+j] == 255 :
				    count=count+1
		if count>=(200):
			digit="1"
		print(digit,count) 
		#Appending each digit to form a  number
		number=number + digit 
	return number	
Esempio n. 2
0
def remove(img):
    rows, cols = img.shape[:2]
    BinarizedImage = PreProcessing.Binarization(img)

    upper_height = 0
    for i in range(rows):
        temp_sum = 0
        for j in range(cols):
            temp_sum += BinarizedImage[i, j]
        if temp_sum < int(0.15 * 255 * cols):
            upper_height = i + 5
        else:
            break

    lower_height = 0
    for i in range(rows):
        temp_sum = 0
        for j in range(cols):
            temp_sum += BinarizedImage[rows - 1 - i, j]
        if temp_sum < int(0.15 * 255 * cols):
            lower_height = i + 5
        else:
            break

    left_width = 0
    for j in range(cols):
        temp_sum = 0
        for i in range(rows):
            temp_sum += BinarizedImage[i, j]
        if temp_sum < int(0.03 * 255 * rows):
            left_width = j + 5
        else:
            break

    right_width = 0
    for j in range(cols):
        temp_sum = 0
        for i in range(rows):
            temp_sum += BinarizedImage[i, cols - 1 - j]
        if temp_sum < int(0.03 * 255 * rows):
            right_width = j + 5
        else:
            break

    x = left_width
    y = upper_height
    h = rows - 1 - lower_height
    w = cols - 1 - right_width

    return img[y:h, x:w]
Esempio n. 3
0
def OCR_DICT():
    image_indices = GlobalVariables.image_indices
    no_of_rows = GlobalVariables.no_of_rows
    no_of_cols = GlobalVariables.no_of_cols

    count = 0
    for row in range(no_of_rows):
        for col in range(len(no_of_cols[row])):
            count = count + 1
            if count in image_indices:
                image_name = 'Cropped_Images/row' + '_' + str(
                    row + 1) + '_' + 'col' + '_' + str(col + 1) + str('.png')
                image = cv2.imread(image_name)
                BinarizedImage = PreProcessing.Binarization(image)
                if count == 15:
                    text = pytesseract.image_to_string(BinarizedImage)
                    temp_text = text.split('-')
                    form_dict[temp_text[0]] = temp_text[1]
                else:
                    key, value = get_form_text(BinarizedImage)
                    form_dict[key] = value

    return form_dict
Esempio n. 4
0
if temp_image_name[1] == 'jpg' or temp_image_name[1] == 'JPG':
    img = im.open(imageName)
    img.save(temp_image_name[0] + '.png')
    imageName = temp_image_name[0] + '.png'

#loading Image
image = cv2.imread(imageName)

#Rotating Image
RotatedImage = Skew_Correction.Correct_skew(imageName)

#smoothening Image
SmoothImage = PreProcessing.smoothening(RotatedImage)

#Binarizing Image
BinarizedImage = PreProcessing.Binarization(SmoothImage)

#Creating Chunks of images so that information can be extracted
FINAL_CROP_IMAGES_COORDINATES = Profiling.H_Profiling(BinarizedImage)

#Saving All Chunks into a Folder(Name = 'Cropped_Images')
Save_Images(FINAL_CROP_IMAGES_COORDINATES)

OCR_information = OCR.OCR_DICT()
Handwritten_info = handwrittenOCR.get_handwritten_dict()

#Merging Dictionaries
OCR_information.update(Handwritten_info)

#Saving Data as json in File
with open('data_5.txt', 'w') as outfile: