ish717 commited on
Commit
90b7de5
·
verified ·
1 Parent(s): 8e62953
Files changed (1) hide show
  1. app.py +6 -5
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') # You can use a different model if needed
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.pred[0] # Get predictions
20
-
21
  # Count people detected (class ID for person is usually 0)
22
- for det in detections:
23
- if det[5] == 0: # Check if class ID is 0 (person)
 
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()