Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,19 +43,35 @@ def sample_border_color(image, box, padding=2):
|
|
| 43 |
median_color = np.median(border_pixels, axis=0)
|
| 44 |
return tuple(map(int, median_color))
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def detect_text_boxes(image):
|
| 47 |
-
results =
|
| 48 |
-
if not results or not results[0]:
|
| 49 |
-
return []
|
| 50 |
boxes = []
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
return boxes
|
| 60 |
|
| 61 |
def remove_text_dynamic_fill(img_path, output_path):
|
|
|
|
| 43 |
median_color = np.median(border_pixels, axis=0)
|
| 44 |
return tuple(map(int, median_color))
|
| 45 |
|
| 46 |
+
# def detect_text_boxes(image):
|
| 47 |
+
# results = ocr.ocr(image, cls=True)
|
| 48 |
+
# if not results or not results[0]:
|
| 49 |
+
# return []
|
| 50 |
+
# boxes = []
|
| 51 |
+
# for line in results[0]:
|
| 52 |
+
# box, (text, confidence) = line
|
| 53 |
+
# if text.strip():
|
| 54 |
+
# x_min = int(min(pt[0] for pt in box))
|
| 55 |
+
# x_max = int(max(pt[0] for pt in box))
|
| 56 |
+
# y_min = int(min(pt[1] for pt in box))
|
| 57 |
+
# y_max = int(max(pt[1] for pt in box))
|
| 58 |
+
# boxes.append(((x_min, y_min, x_max, y_max), text, confidence))
|
| 59 |
+
# return boxes
|
| 60 |
+
|
| 61 |
def detect_text_boxes(image):
|
| 62 |
+
results = paddle_ocr.ocr(image, cls=True)
|
|
|
|
|
|
|
| 63 |
boxes = []
|
| 64 |
+
if results and results[0]:
|
| 65 |
+
for line in results[0]:
|
| 66 |
+
box, (text, confidence) = line
|
| 67 |
+
if text.strip():
|
| 68 |
+
x_min = int(min(pt[0] for pt in box))
|
| 69 |
+
x_max = int(max(pt[0] for pt in box))
|
| 70 |
+
y_min = int(min(pt[1] for pt in box))
|
| 71 |
+
y_max = int(max(pt[1] for pt in box))
|
| 72 |
+
boxes.append(((x_min, y_min, x_max, y_max), text, confidence))
|
| 73 |
+
else:
|
| 74 |
+
print("No text detected in the image.")
|
| 75 |
return boxes
|
| 76 |
|
| 77 |
def remove_text_dynamic_fill(img_path, output_path):
|