richardsl commited on
Commit
322b363
·
verified ·
1 Parent(s): a226c91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -1,29 +1,46 @@
1
  import gradio as gr
2
  import cv2
3
  import mediapipe as mp
4
- import numpy as np
5
 
6
- # Initialize MediaPipe People Detection model
7
- mp_people_detection = mp.solutions.pose
 
8
 
9
- # Function to process the video and count unique people
10
  def count_people(video_file):
11
- cap = cv2.VideoCapture(video_file) # Use the file path directly
12
 
13
- with mp_people_detection.Pose(static_image_mode=False) as pose_detector:
14
- unique_people_count = 0
15
- # Your processing logic here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  cap.release()
18
- return unique_people_count
19
-
 
 
20
  # Create the Gradio interface
21
  iface = gr.Interface(
22
  fn=count_people,
23
  inputs=gr.Video(label="Upload Video"),
24
- outputs=gr.Textbox(label="Number of Unique People"),
25
- title="Unique People Counter",
26
- description="Upload a video to count the number of unique people present."
27
  )
28
 
29
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import cv2
3
  import mediapipe as mp
 
4
 
5
+ # Initialize MediaPipe Pose model
6
+ mp_pose = mp.solutions.pose
7
+ pose = mp_pose.Pose()
8
 
 
9
  def count_people(video_file):
10
+ cap = cv2.VideoCapture(video_file)
11
 
12
+ people_count = 0
13
+ frame_count = 0
14
+
15
+ while cap.isOpened():
16
+ ret, frame = cap.read()
17
+ if not ret:
18
+ break
19
+
20
+ # Convert the BGR image to RGB before processing
21
+ rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
22
+
23
+ # Process the frame with MediaPipe Pose
24
+ results = pose.process(rgb_frame)
25
+
26
+ # Check if any pose is detected
27
+ if results.pose_landmarks:
28
+ people_count += 1
29
+
30
+ frame_count += 1
31
 
32
  cap.release()
33
+
34
+ # For simplicity, return the count of frames where people were detected
35
+ return people_count
36
+
37
  # Create the Gradio interface
38
  iface = gr.Interface(
39
  fn=count_people,
40
  inputs=gr.Video(label="Upload Video"),
41
+ outputs=gr.Textbox(label="Number of People Detected"),
42
+ title="People Counter",
43
+ description="Upload a video to count the number of people present."
44
  )
45
 
46
  if __name__ == "__main__":