Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,7 +55,13 @@ def process_video(video):
|
|
| 55 |
for box in boxes:
|
| 56 |
x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
|
| 57 |
class_id = int(box.cls[0]) # Class index for best.pt
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
|
| 60 |
cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 0), 2)
|
| 61 |
|
|
|
|
| 55 |
for box in boxes:
|
| 56 |
x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
|
| 57 |
class_id = int(box.cls[0]) # Class index for best.pt
|
| 58 |
+
|
| 59 |
+
# Check if the class_id is within the range of best_classes
|
| 60 |
+
if class_id < len(best_classes):
|
| 61 |
+
label = f"Best: {best_classes[class_id]} - {box.conf[0]:.2f}" # Map class_id to specific labels
|
| 62 |
+
else:
|
| 63 |
+
label = f"Best: Unknown Class - {box.conf[0]:.2f}" # Handle out of range class_id
|
| 64 |
+
|
| 65 |
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 0, 0), 2)
|
| 66 |
cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 0), 2)
|
| 67 |
|