Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,17 +41,18 @@ def sample_border_color(image, box, padding=2):
|
|
| 41 |
|
| 42 |
def detect_text_boxes(image):
|
| 43 |
results = ocr.ocr(image, cls=True)
|
| 44 |
-
if not results or not results[0]:
|
| 45 |
-
return []
|
| 46 |
boxes = []
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
return boxes
|
| 56 |
|
| 57 |
def remove_text_dynamic_fill(img_path, output_path):
|
|
|
|
| 41 |
|
| 42 |
def detect_text_boxes(image):
|
| 43 |
results = ocr.ocr(image, cls=True)
|
|
|
|
|
|
|
| 44 |
boxes = []
|
| 45 |
+
if results and results[0]:
|
| 46 |
+
for line in results[0]:
|
| 47 |
+
box, (text, confidence) = line
|
| 48 |
+
if text.strip():
|
| 49 |
+
x_min = int(min(pt[0] for pt in box))
|
| 50 |
+
x_max = int(max(pt[0] for pt in box))
|
| 51 |
+
y_min = int(min(pt[1] for pt in box))
|
| 52 |
+
y_max = int(max(pt[1] for pt in box))
|
| 53 |
+
boxes.append(((x_min, y_min, x_max, y_max), text, confidence))
|
| 54 |
+
else:
|
| 55 |
+
print("No text detected in the image.")
|
| 56 |
return boxes
|
| 57 |
|
| 58 |
def remove_text_dynamic_fill(img_path, output_path):
|