Spaces:
Build error
Build error
Minor changes
Browse files
app.py
CHANGED
@@ -23,12 +23,8 @@ import postprocess
|
|
23 |
|
24 |
|
25 |
ocr_instance = PaddleOCR(use_angle_cls=False, lang='en', use_gpu=True)
|
26 |
-
|
27 |
-
torch.hub.
|
28 |
-
detection_model = torch.hub.load('ultralytics/yolov5', 'custom', 'weights/detection_wts.pt', force_reload=True)
|
29 |
-
|
30 |
-
torch.hub._validate_not_a_forked_repo = lambda a, b, c: True
|
31 |
-
structure_model = torch.hub.load('ultralytics/yolov5', 'custom', 'weights/structure_wts.pt', force_reload=True)
|
32 |
|
33 |
imgsz = 640
|
34 |
|
@@ -87,13 +83,18 @@ def crop_image(pil_img, detection_result, padding=30):
|
|
87 |
w = result[2]
|
88 |
h = result[3]
|
89 |
|
90 |
-
x1 =
|
91 |
-
y1 =
|
92 |
-
x2 =
|
93 |
-
y2 =
|
94 |
# print(x1, y1, x2, y2)
|
95 |
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
97 |
crop_image = cv_to_PIL(crop_image)
|
98 |
if class_id == 1: # table rotated
|
99 |
crop_image = crop_image.rotate(270, expand=True)
|
@@ -101,6 +102,7 @@ def crop_image(pil_img, detection_result, padding=30):
|
|
101 |
crop_images.append(crop_image)
|
102 |
|
103 |
cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255))
|
|
|
104 |
|
105 |
return crop_images, cv_to_PIL(image)
|
106 |
|
|
|
23 |
|
24 |
|
25 |
ocr_instance = PaddleOCR(use_angle_cls=False, lang='en', use_gpu=True)
|
26 |
+
detection_model = torch.hub.load('ultralytics/yolov5', 'custom', 'weights/detection_wts.pt', force_reload=True, skip_validation=True, trust_repo=True)
|
27 |
+
structure_model = torch.hub.load('ultralytics/yolov5', 'custom', 'weights/structure_wts.pt', force_reload=True, skip_validation=True, trust_repo=True)
|
|
|
|
|
|
|
|
|
28 |
|
29 |
imgsz = 640
|
30 |
|
|
|
83 |
w = result[2]
|
84 |
h = result[3]
|
85 |
|
86 |
+
x1 = int((min_x - w / 2) * width)
|
87 |
+
y1 = int((min_y - h / 2) * height)
|
88 |
+
x2 = int((min_x + w / 2) * width)
|
89 |
+
y2 = int((min_y + h / 2) * height)
|
90 |
# print(x1, y1, x2, y2)
|
91 |
|
92 |
+
x1_pad = max(0, x1 - padding)
|
93 |
+
y1_pad = max(0, y1 - padding)
|
94 |
+
x2_pad = min(width, x2 + padding)
|
95 |
+
y2_pad = min(height, y2 + padding)
|
96 |
+
|
97 |
+
crop_image = image[y1_pad:y2_pad, x1_pad:x2_pad, :]
|
98 |
crop_image = cv_to_PIL(crop_image)
|
99 |
if class_id == 1: # table rotated
|
100 |
crop_image = crop_image.rotate(270, expand=True)
|
|
|
102 |
crop_images.append(crop_image)
|
103 |
|
104 |
cv2.rectangle(image, (x1, y1), (x2, y2), color=(0, 0, 255))
|
105 |
+
cv2.putText(image, f'{score:.2f}', (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=(255, 0, 0))
|
106 |
|
107 |
return crop_images, cv_to_PIL(image)
|
108 |
|