Spaces:
Sleeping
Sleeping
Commit
·
eb82720
1
Parent(s):
0e2452f
Updated Scripts
Browse files- inference/detect_image.py +1 -1
- inference/detect_video.py +24 -7
- inference/detect_webcam.py +17 -7
inference/detect_image.py
CHANGED
@@ -10,7 +10,7 @@ if len(sys.argv) < 2:
|
|
10 |
image_path = sys.argv[1]
|
11 |
|
12 |
# Load trained model
|
13 |
-
model = YOLO("
|
14 |
|
15 |
# Read image
|
16 |
frame = cv2.imread(image_path)
|
|
|
10 |
image_path = sys.argv[1]
|
11 |
|
12 |
# Load trained model
|
13 |
+
model = YOLO("best50.pt")
|
14 |
|
15 |
# Read image
|
16 |
frame = cv2.imread(image_path)
|
inference/detect_video.py
CHANGED
@@ -1,19 +1,36 @@
|
|
1 |
from ultralytics import YOLO
|
2 |
import cv2
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
|
|
|
|
|
|
7 |
cap = cv2.VideoCapture(video_path)
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
ret, frame = cap.read()
|
10 |
-
if not ret:
|
|
|
|
|
11 |
|
12 |
-
results = model(frame, conf=0.5, imgsz=640, augment=False)
|
13 |
annotated_frame = results[0].plot()
|
14 |
|
15 |
cv2.imshow("Video Detection", annotated_frame)
|
16 |
-
|
|
|
|
|
17 |
|
18 |
cap.release()
|
19 |
-
cv2.destroyAllWindows()
|
|
|
|
1 |
from ultralytics import YOLO
|
2 |
import cv2
|
3 |
+
import sys
|
4 |
|
5 |
+
# Check for command-line argument
|
6 |
+
if len(sys.argv) < 2:
|
7 |
+
print("Usage: python detect_video.py <video_path>")
|
8 |
+
exit()
|
9 |
|
10 |
+
video_path = sys.argv[1]
|
11 |
+
|
12 |
+
model = YOLO("best50.pt")
|
13 |
cap = cv2.VideoCapture(video_path)
|
14 |
+
|
15 |
+
if not cap.isOpened():
|
16 |
+
print(f"Error: Could not open video file {video_path}.")
|
17 |
+
exit()
|
18 |
+
|
19 |
+
print("Press 'q' to quit.")
|
20 |
+
while True:
|
21 |
ret, frame = cap.read()
|
22 |
+
if not ret:
|
23 |
+
print("End of video or failed to grab frame.")
|
24 |
+
break
|
25 |
|
26 |
+
results = model(frame, conf=0.5, iou=0.4, imgsz=640, augment=False)
|
27 |
annotated_frame = results[0].plot()
|
28 |
|
29 |
cv2.imshow("Video Detection", annotated_frame)
|
30 |
+
|
31 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
32 |
+
break
|
33 |
|
34 |
cap.release()
|
35 |
+
cv2.destroyAllWindows()
|
36 |
+
print("Video closed.")
|
inference/detect_webcam.py
CHANGED
@@ -1,18 +1,28 @@
|
|
1 |
from ultralytics import YOLO
|
2 |
import cv2
|
3 |
|
4 |
-
model = YOLO("
|
5 |
-
|
6 |
cap = cv2.VideoCapture(0) # 0 = default webcam
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
ret, frame = cap.read()
|
9 |
-
if not ret:
|
|
|
|
|
10 |
|
11 |
-
results = model(frame, conf=0.5, imgsz=640, augment=False)
|
12 |
annotated_frame = results[0].plot()
|
13 |
|
14 |
cv2.imshow("Webcam Detection", annotated_frame)
|
15 |
-
|
|
|
|
|
16 |
|
17 |
cap.release()
|
18 |
-
cv2.destroyAllWindows()
|
|
|
|
1 |
from ultralytics import YOLO
|
2 |
import cv2
|
3 |
|
4 |
+
model = YOLO("best50.pt")
|
|
|
5 |
cap = cv2.VideoCapture(0) # 0 = default webcam
|
6 |
+
|
7 |
+
if not cap.isOpened():
|
8 |
+
print("Error: Could not open webcam.")
|
9 |
+
exit()
|
10 |
+
|
11 |
+
print("Press 'q' to quit.")
|
12 |
+
while True:
|
13 |
ret, frame = cap.read()
|
14 |
+
if not ret:
|
15 |
+
print("Failed to grab frame.")
|
16 |
+
break
|
17 |
|
18 |
+
results = model(frame, conf=0.5, iou=0.4, imgsz=640, augment=False)
|
19 |
annotated_frame = results[0].plot()
|
20 |
|
21 |
cv2.imshow("Webcam Detection", annotated_frame)
|
22 |
+
|
23 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
24 |
+
break
|
25 |
|
26 |
cap.release()
|
27 |
+
cv2.destroyAllWindows()
|
28 |
+
print("Webcam closed.")
|