NassimeBejaia commited on
Commit
de15edd
·
1 Parent(s): 15a408d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -35
app.py CHANGED
@@ -102,14 +102,14 @@ def main():
102
 
103
 
104
  # Function to display files in a directory
105
- def display_files_in_directory(path="."):
106
- if os.path.exists(path):
107
- files = os.listdir(path)
108
- st.write(f"Files in directory: {path}")
109
- for file in files:
110
- st.write(file)
111
- else:
112
- st.write(f"Directory {path} does not exist!")
113
 
114
  def resize_image(image_path, size):
115
  """Function to resize an image"""
@@ -159,9 +159,6 @@ def process_image(selected_image):
159
  if gray_image.dtype != np.uint8:
160
  gray_image = (gray_image * 255).astype(np.uint8)
161
 
162
- # Optionally apply Gaussian Blur
163
- # blurred_img = cv2.GaussianBlur(gray_image, (3, 3), 0)
164
-
165
  # Apply adaptive thresholding
166
 
167
  # Let's assume `gray_image` is your grayscale image array
@@ -180,23 +177,6 @@ def process_image(selected_image):
180
 
181
  thresh = binary_adaptive
182
 
183
- # Apply OTSU's thresholding
184
- # _, thresh = cv2.threshold(binary_adaptive, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
185
-
186
- # kernel = get_dynamic_kernel(thresh.shape[0])
187
- # kernel = np.ones((5, 1), np.uint8)
188
- # thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2)
189
-
190
- # # Apply median blur
191
- # thresh = cv2.medianBlur(thresh, 3)
192
-
193
- # # Apply morphological thinning
194
- # thresh = cv2.ximgproc.thinning(thresh)
195
-
196
- # # Apply morphological closing
197
- # kernel = np.ones((3,3), np.uint8)
198
- # thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
199
-
200
  # Convert thresholded image back to PIL format to display in Streamlit
201
  thresh_pil = Image.fromarray(thresh)
202
 
@@ -316,7 +296,7 @@ def display_detected_lines(original_path, output_path):
316
 
317
  # Create a temporary directory to store the detected lines
318
  with TemporaryDirectory() as temp_dir:
319
- detected_line_paths = [] # For storing paths of the thresholded line images for OCR
320
  original_line_paths = [] # For storing paths of the original line images for display
321
 
322
  for index, box in enumerate(boxes):
@@ -332,14 +312,14 @@ def display_detected_lines(original_path, output_path):
332
  original_line.save(original_line_path)
333
  original_line_paths.append(original_line_path)
334
 
335
- # Crop the THRESHOLDED image and save for OCR
336
- extracted_line = thresholded_image.crop((x_min, y_min, x_max, y_max))
337
- detected_line_path = os.path.join(temp_dir, f"detected_line_{index}.jpg")
338
- extracted_line.save(detected_line_path)
339
- detected_line_paths.append(detected_line_path)
340
 
341
  # Perform OCR on thresholded lines
342
- recognized_texts = perform_ocr_on_detected_lines(detected_line_paths)
343
 
344
  # Display the results
345
  for original_img_path, text in zip(original_line_paths, recognized_texts):
 
102
 
103
 
104
  # Function to display files in a directory
105
+ # def display_files_in_directory(path="."):
106
+ # if os.path.exists(path):
107
+ # files = os.listdir(path)
108
+ # st.write(f"Files in directory: {path}")
109
+ # for file in files:
110
+ # st.write(file)
111
+ # else:
112
+ # st.write(f"Directory {path} does not exist!")
113
 
114
  def resize_image(image_path, size):
115
  """Function to resize an image"""
 
159
  if gray_image.dtype != np.uint8:
160
  gray_image = (gray_image * 255).astype(np.uint8)
161
 
 
 
 
162
  # Apply adaptive thresholding
163
 
164
  # Let's assume `gray_image` is your grayscale image array
 
177
 
178
  thresh = binary_adaptive
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  # Convert thresholded image back to PIL format to display in Streamlit
181
  thresh_pil = Image.fromarray(thresh)
182
 
 
296
 
297
  # Create a temporary directory to store the detected lines
298
  with TemporaryDirectory() as temp_dir:
299
+ # detected_line_paths = [] # For storing paths of the thresholded line images for OCR
300
  original_line_paths = [] # For storing paths of the original line images for display
301
 
302
  for index, box in enumerate(boxes):
 
312
  original_line.save(original_line_path)
313
  original_line_paths.append(original_line_path)
314
 
315
+ # # Crop the THRESHOLDED image and save for OCR
316
+ # extracted_line = thresholded_image.crop((x_min, y_min, x_max, y_max))
317
+ # detected_line_path = os.path.join(temp_dir, f"detected_line_{index}.jpg")
318
+ # extracted_line.save(detected_line_path)
319
+ # detected_line_paths.append(detected_line_path)
320
 
321
  # Perform OCR on thresholded lines
322
+ recognized_texts = perform_ocr_on_detected_lines(original_line_paths)
323
 
324
  # Display the results
325
  for original_img_path, text in zip(original_line_paths, recognized_texts):