Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,15 +57,15 @@ def predict_and_show_bounding_boxes(image_path, model_choice, conf_threshold=0.5
|
|
| 57 |
results = yolo_model(img, conf=conf_threshold)[0]
|
| 58 |
boxes = results.boxes
|
| 59 |
if len(boxes) == 0:
|
| 60 |
-
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 61 |
for box in boxes:
|
| 62 |
xyxy = box.xyxy[0].tolist()
|
| 63 |
x_min, y_min, x_max, y_max = map(int, xyxy[:4])
|
| 64 |
conf = box.conf[0].item()
|
| 65 |
cls = int(box.cls[0])
|
| 66 |
-
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (0, 255, 0),
|
| 67 |
label = f"{results.names[cls]}: {conf:.2f}"
|
| 68 |
-
cv2.putText(img, label, (x_min, y_min -
|
| 69 |
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 70 |
except Exception as e:
|
| 71 |
return None, f"Error during YOLO prediction: {e}"
|
|
@@ -82,13 +82,13 @@ def predict_and_show_bounding_boxes(image_path, model_choice, conf_threshold=0.5
|
|
| 82 |
overlap_width_ratio=0.1,
|
| 83 |
)
|
| 84 |
if len(result.object_prediction_list) == 0:
|
| 85 |
-
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 86 |
for pred in result.object_prediction_list:
|
| 87 |
box = pred.bbox.to_xyxy()
|
| 88 |
x_min, y_min, x_max, y_max = map(int, box)
|
| 89 |
label = f"{pred.category.name}: {pred.score.value:.2f}"
|
| 90 |
-
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (255, 0, 0),
|
| 91 |
-
cv2.putText(img, label, (x_min, y_min -
|
| 92 |
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 93 |
except Exception as e:
|
| 94 |
return None, f"Error during SAHI prediction: {e}"
|
|
|
|
| 57 |
results = yolo_model(img, conf=conf_threshold)[0]
|
| 58 |
boxes = results.boxes
|
| 59 |
if len(boxes) == 0:
|
| 60 |
+
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 61 |
for box in boxes:
|
| 62 |
xyxy = box.xyxy[0].tolist()
|
| 63 |
x_min, y_min, x_max, y_max = map(int, xyxy[:4])
|
| 64 |
conf = box.conf[0].item()
|
| 65 |
cls = int(box.cls[0])
|
| 66 |
+
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (0, 255, 0), 1) # Thinner box (thickness 1)
|
| 67 |
label = f"{results.names[cls]}: {conf:.2f}"
|
| 68 |
+
cv2.putText(img, label, (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1) # Smaller font (scale 0.5, thickness 1)
|
| 69 |
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 70 |
except Exception as e:
|
| 71 |
return None, f"Error during YOLO prediction: {e}"
|
|
|
|
| 82 |
overlap_width_ratio=0.1,
|
| 83 |
)
|
| 84 |
if len(result.object_prediction_list) == 0:
|
| 85 |
+
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 86 |
for pred in result.object_prediction_list:
|
| 87 |
box = pred.bbox.to_xyxy()
|
| 88 |
x_min, y_min, x_max, y_max = map(int, box)
|
| 89 |
label = f"{pred.category.name}: {pred.score.value:.2f}"
|
| 90 |
+
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (255, 0, 0), 1) # Thinner box (thickness 1)
|
| 91 |
+
cv2.putText(img, label, (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 1) # Smaller font (scale 0.5, thickness 1)
|
| 92 |
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 93 |
except Exception as e:
|
| 94 |
return None, f"Error during SAHI prediction: {e}"
|