manik-hossain commited on
Commit
f9e7031
·
1 Parent(s): 7d65a14
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -6,19 +6,28 @@ from PIL import Image
6
  import pytesseract
7
 
8
  def enhance(img):
9
- gaussian_thresh = cv2.adaptiveThreshold(
10
- img,
11
- maxValue=255,
12
- adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
13
- thresholdType=cv2.THRESH_BINARY,
14
- blockSize=11,
15
- C=2)
16
- return gaussian_thresh
 
 
 
 
 
 
 
 
 
17
 
18
  act = [(150,240), (610,260)]
19
 
20
 
21
- def align_images(ref_gray, input_gray, enh= True):
22
  """
23
  Aligns the input image to the reference image using homography.
24
 
@@ -35,9 +44,11 @@ def align_images(ref_gray, input_gray, enh= True):
35
  if enh:
36
  ref_gray = enhance(ref_gray)
37
  input_gray = enhance(input_gray)
 
 
38
 
39
  # Detect ORB keypoints and descriptors
40
- orb = cv2.ORB_create(nfeatures=500)
41
  keypoints1, descriptors1 = orb.detectAndCompute(ref_gray, None)
42
  keypoints2, descriptors2 = orb.detectAndCompute(input_gray, None)
43
 
 
6
  import pytesseract
7
 
8
  def enhance(img):
9
+ # Apply GaussianBlur to reduce noise
10
+ blurred = cv2.GaussianBlur(img, (5, 5), 0)
11
+
12
+ # Apply adaptive thresholding to enhance text
13
+ thresh = cv2.adaptiveThreshold(
14
+ blurred,
15
+ 255,
16
+ cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
17
+ cv2.THRESH_BINARY,
18
+ 11,
19
+ 2
20
+ )
21
+
22
+ # Perform morphological operations to remove small noise and connect text components
23
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
24
+ morph = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
25
+ return morph
26
 
27
  act = [(150,240), (610,260)]
28
 
29
 
30
+ def align_images(ref_gray, input_gray, enh= False):
31
  """
32
  Aligns the input image to the reference image using homography.
33
 
 
44
  if enh:
45
  ref_gray = enhance(ref_gray)
46
  input_gray = enhance(input_gray)
47
+ st.image(ref_gray)
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