manik-hossain commited on
Commit
0e15c8c
·
1 Parent(s): f9e7031
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -25,7 +25,8 @@ def enhance(img):
25
  return morph
26
 
27
  act = [(150,240), (610,260)]
28
-
 
29
 
30
  def align_images(ref_gray, input_gray, enh= False):
31
  """
@@ -48,7 +49,7 @@ def align_images(ref_gray, input_gray, enh= False):
48
  st.image(input_gray)
49
 
50
  # Detect ORB keypoints and descriptors
51
- orb = cv2.ORB_create(nfeatures=1500)
52
  keypoints1, descriptors1 = orb.detectAndCompute(ref_gray, None)
53
  keypoints2, descriptors2 = orb.detectAndCompute(input_gray, None)
54
 
@@ -80,21 +81,24 @@ def ocr_with_crop(aligned_image):
80
  # enh = enhance(np.array(img))
81
  # st.image(enh)
82
  # Define the coordinates for cropping
83
- crop_coordinates = act
84
-
85
- # Convert to rectangular bounds (x1, y1, x2, y2)
86
- x1, y1 = crop_coordinates[0]
87
- x2, y2 = crop_coordinates[1]
88
- # Crop the image using the defined coordinates
89
- # cropped_img = img.crop((x1, y1, x2, y2))
90
- cropped_img = aligned_image[y1:y2,x1:x2]
91
- st.image(cropped_img)
92
- # Perform OCR on the cropped image
93
- text = pytesseract.image_to_string(cropped_img)
94
-
95
- # Print the extracted text
96
- st.write(text)
97
-
 
 
 
98
  if __name__== "__main__":
99
  ref = cv.imread("r.png",0)
100
  if inp:= st.file_uploader("upload your form in image format", type=['png']):
 
25
  return morph
26
 
27
  act = [(150,240), (610,260)]
28
+ act2 = [(130,440), (590,460)]
29
+ acts=[act,act2]
30
 
31
  def align_images(ref_gray, input_gray, enh= False):
32
  """
 
49
  st.image(input_gray)
50
 
51
  # Detect ORB keypoints and descriptors
52
+ orb = cv2.ORB_create(nfeatures=3000)
53
  keypoints1, descriptors1 = orb.detectAndCompute(ref_gray, None)
54
  keypoints2, descriptors2 = orb.detectAndCompute(input_gray, None)
55
 
 
81
  # enh = enhance(np.array(img))
82
  # st.image(enh)
83
  # Define the coordinates for cropping
84
+ def ocr(act):
85
+ crop_coordinates = act
86
+
87
+ # Convert to rectangular bounds (x1, y1, x2, y2)
88
+ x1, y1 = crop_coordinates[0]
89
+ x2, y2 = crop_coordinates[1]
90
+ # Crop the image using the defined coordinates
91
+ # cropped_img = img.crop((x1, y1, x2, y2))
92
+ cropped_img = aligned_image[y1:y2,x1:x2]
93
+ st.image(cropped_img)
94
+ # Perform OCR on the cropped image
95
+ text = pytesseract.image_to_string(cropped_img)
96
+
97
+ # Print the extracted text
98
+ st.write(text)
99
+ for cor in acts:
100
+ ocr(cor)
101
+
102
  if __name__== "__main__":
103
  ref = cv.imread("r.png",0)
104
  if inp:= st.file_uploader("upload your form in image format", type=['png']):