Update app.py
Browse files
app.py
CHANGED
|
@@ -87,6 +87,8 @@ def process_image(job_id, image_path, object_type):
|
|
| 87 |
|
| 88 |
jobs[job_id]['progress'] = 20
|
| 89 |
img_height, img_width = image.shape[:2]
|
|
|
|
|
|
|
| 90 |
detection_info = []
|
| 91 |
|
| 92 |
if object_type == "box":
|
|
@@ -158,7 +160,8 @@ def process_image(job_id, image_path, object_type):
|
|
| 158 |
x1, y1, x2, y2 = pred["box"]
|
| 159 |
label = pred["class"]
|
| 160 |
confidence = pred["confidence"]
|
| 161 |
-
|
|
|
|
| 162 |
if conversion_factor is not None:
|
| 163 |
box_width_pixels = x2 - x1
|
| 164 |
box_height_pixels = y2 - y1
|
|
@@ -198,7 +201,8 @@ def process_image(job_id, image_path, object_type):
|
|
| 198 |
ymax = int(row['ymax'])
|
| 199 |
conf = row['confidence']
|
| 200 |
label = row['name']
|
| 201 |
-
|
|
|
|
| 202 |
text = f"{label} ({conf:.2f})"
|
| 203 |
(text_width, text_height), baseline = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
|
| 204 |
cv2.rectangle(image, (xmin, ymin - text_height - baseline - 5), (xmin + text_width, ymin - 5), (255, 0, 0), -1)
|
|
|
|
| 87 |
|
| 88 |
jobs[job_id]['progress'] = 20
|
| 89 |
img_height, img_width = image.shape[:2]
|
| 90 |
+
# Compute dynamic thickness based on image size.
|
| 91 |
+
thickness = max(2, int(min(img_width, img_height) / 300))
|
| 92 |
detection_info = []
|
| 93 |
|
| 94 |
if object_type == "box":
|
|
|
|
| 160 |
x1, y1, x2, y2 = pred["box"]
|
| 161 |
label = pred["class"]
|
| 162 |
confidence = pred["confidence"]
|
| 163 |
+
# Use dynamic thickness here
|
| 164 |
+
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), thickness)
|
| 165 |
if conversion_factor is not None:
|
| 166 |
box_width_pixels = x2 - x1
|
| 167 |
box_height_pixels = y2 - y1
|
|
|
|
| 201 |
ymax = int(row['ymax'])
|
| 202 |
conf = row['confidence']
|
| 203 |
label = row['name']
|
| 204 |
+
# Use dynamic thickness here as well
|
| 205 |
+
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (255, 0, 0), thickness)
|
| 206 |
text = f"{label} ({conf:.2f})"
|
| 207 |
(text_width, text_height), baseline = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
|
| 208 |
cv2.rectangle(image, (xmin, ymin - text_height - baseline - 5), (xmin + text_width, ymin - 5), (255, 0, 0), -1)
|