NassimeBejaia commited on
Commit
e4663b7
1 Parent(s): 33c64b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -20,6 +20,8 @@ import subprocess
20
 
21
  import io
22
 
 
 
23
  # Load the OCR model outside the function to prevent reloading it every time
24
  ocr_model = load_model()
25
 
@@ -160,10 +162,15 @@ def process_image(selected_image):
160
  # Optionally apply Gaussian Blur
161
  # blurred_img = cv2.GaussianBlur(gray_image, (3, 3), 0)
162
 
 
 
 
 
 
 
163
  # Apply OTSU's thresholding
164
- # _, thresh = cv2.threshold(gray_image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
165
 
166
- thresh = gray_image
167
  # kernel = get_dynamic_kernel(thresh.shape[0])
168
  # kernel = np.ones((5, 1), np.uint8)
169
  # thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2)
 
20
 
21
  import io
22
 
23
+ from skimage import filters
24
+
25
  # Load the OCR model outside the function to prevent reloading it every time
26
  ocr_model = load_model()
27
 
 
162
  # Optionally apply Gaussian Blur
163
  # blurred_img = cv2.GaussianBlur(gray_image, (3, 3), 0)
164
 
165
+ # Apply adaptive thresholding
166
+
167
+ adaptive_threshold = filters.threshold_local(gray_image, block_size=35, offset=10)
168
+
169
+ binary_adaptive = gray_image_array > adaptive_threshold
170
+
171
  # Apply OTSU's thresholding
172
+ _, thresh = cv2.threshold(binary_adaptive, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
173
 
 
174
  # kernel = get_dynamic_kernel(thresh.shape[0])
175
  # kernel = np.ones((5, 1), np.uint8)
176
  # thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2)