Update app.py
Browse filesI have the modified squat detection
app.py
CHANGED
@@ -195,6 +195,8 @@ import numpy as np
|
|
195 |
import mediapipe as mp
|
196 |
import streamlit as st
|
197 |
from streamlit_webrtc import webrtc_streamer
|
|
|
|
|
198 |
|
199 |
# Logging setup
|
200 |
logger = logging.getLogger(__name__)
|
@@ -218,13 +220,16 @@ def calculate_angle(a, b, c):
|
|
218 |
angle = 360 - angle
|
219 |
return angle
|
220 |
|
221 |
-
|
|
|
|
|
|
|
222 |
image = frame.to_ndarray(format="bgr24")
|
223 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
224 |
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
|
225 |
results = pose.process(image_rgb)
|
226 |
landmarks = results.pose_landmarks.landmark if results.pose_landmarks else []
|
227 |
-
|
228 |
if landmarks:
|
229 |
hip = [landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].x,
|
230 |
landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].y]
|
@@ -263,12 +268,14 @@ def process_frame(frame):
|
|
263 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
|
264 |
mp_drawing.DrawingSpec(color=(255, 175, 0), thickness=2, circle_radius=2),
|
265 |
mp_drawing.DrawingSpec(color=(0, 255, 200), thickness=2, circle_radius=2))
|
266 |
-
|
|
|
|
|
267 |
|
268 |
# WebRTC streamer configuration
|
269 |
webrtc_streamer(
|
270 |
key="squat-detection",
|
271 |
-
|
272 |
media_stream_constraints={"video": True, "audio": False},
|
273 |
async_processing=True
|
274 |
)
|
@@ -300,6 +307,7 @@ webrtc_streamer(
|
|
300 |
|
301 |
|
302 |
|
|
|
303 |
|
304 |
|
305 |
# import logging
|
|
|
195 |
import mediapipe as mp
|
196 |
import streamlit as st
|
197 |
from streamlit_webrtc import webrtc_streamer
|
198 |
+
import av
|
199 |
+
import queue
|
200 |
|
201 |
# Logging setup
|
202 |
logger = logging.getLogger(__name__)
|
|
|
220 |
angle = 360 - angle
|
221 |
return angle
|
222 |
|
223 |
+
# Detection Queue
|
224 |
+
result_queue: "queue.Queue[list]" = queue.Queue()
|
225 |
+
|
226 |
+
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
227 |
image = frame.to_ndarray(format="bgr24")
|
228 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
229 |
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
|
230 |
results = pose.process(image_rgb)
|
231 |
landmarks = results.pose_landmarks.landmark if results.pose_landmarks else []
|
232 |
+
|
233 |
if landmarks:
|
234 |
hip = [landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].x,
|
235 |
landmarks[mp_pose.PoseLandmark.LEFT_HIP.value].y]
|
|
|
268 |
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
|
269 |
mp_drawing.DrawingSpec(color=(255, 175, 0), thickness=2, circle_radius=2),
|
270 |
mp_drawing.DrawingSpec(color=(0, 255, 200), thickness=2, circle_radius=2))
|
271 |
+
|
272 |
+
result_queue.put(landmarks)
|
273 |
+
return av.VideoFrame.from_ndarray(image, format="bgr24")
|
274 |
|
275 |
# WebRTC streamer configuration
|
276 |
webrtc_streamer(
|
277 |
key="squat-detection",
|
278 |
+
video_frame_callback=video_frame_callback,
|
279 |
media_stream_constraints={"video": True, "audio": False},
|
280 |
async_processing=True
|
281 |
)
|
|
|
307 |
|
308 |
|
309 |
|
310 |
+
|
311 |
|
312 |
|
313 |
# import logging
|