Spaces:
Runtime error
Runtime error
Commit
•
73ac9a9
1
Parent(s):
6fceb8b
Update app.py
Browse files
app.py
CHANGED
@@ -250,7 +250,9 @@ def display_detected_lines(original_path, output_path):
|
|
250 |
txt_path = os.path.join('yolov3/runs/detect/mainlinedection/labels', os.path.basename(output_path).replace(".jpg", ".txt"))
|
251 |
|
252 |
if os.path.exists(txt_path):
|
|
|
253 |
original_image = Image.open(original_path)
|
|
|
254 |
boxes = get_detected_boxes(txt_path, original_image.width, original_image.height)
|
255 |
|
256 |
if not boxes:
|
@@ -269,7 +271,8 @@ def display_detected_lines(original_path, output_path):
|
|
269 |
x_max = int(x_center + (width / 2))
|
270 |
y_max = int(y_center + (height / 2))
|
271 |
|
272 |
-
|
|
|
273 |
|
274 |
# Save the detected line image to the temporary directory
|
275 |
detected_line_path = os.path.join(temp_dir, f"detected_line_{index}.jpg")
|
@@ -279,6 +282,7 @@ def display_detected_lines(original_path, output_path):
|
|
279 |
# Perform OCR on detected lines
|
280 |
recognized_texts = perform_ocr_on_detected_lines(detected_line_paths)
|
281 |
|
|
|
282 |
# print("Decoded OCR Results:", recognized_texts)
|
283 |
# st.text(f"Detected Line: {recognized_texts}")
|
284 |
|
|
|
250 |
txt_path = os.path.join('yolov3/runs/detect/mainlinedection/labels', os.path.basename(output_path).replace(".jpg", ".txt"))
|
251 |
|
252 |
if os.path.exists(txt_path):
|
253 |
+
# Load both original and thresholded images
|
254 |
original_image = Image.open(original_path)
|
255 |
+
thresholded_image = process_image(original_image) # This is your function that returns a thresholded PIL image
|
256 |
boxes = get_detected_boxes(txt_path, original_image.width, original_image.height)
|
257 |
|
258 |
if not boxes:
|
|
|
271 |
x_max = int(x_center + (width / 2))
|
272 |
y_max = int(y_center + (height / 2))
|
273 |
|
274 |
+
# Crop the thresholded image instead of the original
|
275 |
+
extracted_line = thresholded_image.crop((x_min, y_min, x_max, y_max))
|
276 |
|
277 |
# Save the detected line image to the temporary directory
|
278 |
detected_line_path = os.path.join(temp_dir, f"detected_line_{index}.jpg")
|
|
|
282 |
# Perform OCR on detected lines
|
283 |
recognized_texts = perform_ocr_on_detected_lines(detected_line_paths)
|
284 |
|
285 |
+
|
286 |
# print("Decoded OCR Results:", recognized_texts)
|
287 |
# st.text(f"Detected Line: {recognized_texts}")
|
288 |
|