Spaces:
Sleeping
Sleeping
updated
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
from ultralytics import YOLO
|
| 5 |
|
| 6 |
# Load the YOLO model
|
| 7 |
-
model = YOLO('yolov5s.pt') #
|
| 8 |
|
| 9 |
def count_people(video_file):
|
| 10 |
count = 0
|
|
@@ -16,11 +16,12 @@ def count_people(video_file):
|
|
| 16 |
break
|
| 17 |
|
| 18 |
results = model(frame)
|
| 19 |
-
detections = results
|
| 20 |
-
|
| 21 |
# Count people detected (class ID for person is usually 0)
|
| 22 |
-
for det in detections:
|
| 23 |
-
|
|
|
|
| 24 |
count += 1
|
| 25 |
|
| 26 |
cap.release()
|
|
|
|
| 4 |
from ultralytics import YOLO
|
| 5 |
|
| 6 |
# Load the YOLO model
|
| 7 |
+
model = YOLO('yolov5s.pt') # Use 'yolov5s.pt' or any YOLO model of your choice
|
| 8 |
|
| 9 |
def count_people(video_file):
|
| 10 |
count = 0
|
|
|
|
| 16 |
break
|
| 17 |
|
| 18 |
results = model(frame)
|
| 19 |
+
detections = results[0] # Access the first result
|
| 20 |
+
|
| 21 |
# Count people detected (class ID for person is usually 0)
|
| 22 |
+
for det in detections.boxes.data: # Access the boxes
|
| 23 |
+
class_id = int(det[5]) # Class ID is the 6th element
|
| 24 |
+
if class_id == 0: # Check if class ID is 0 (person)
|
| 25 |
count += 1
|
| 26 |
|
| 27 |
cap.release()
|