Spaces:
Sleeping
Sleeping
File size: 1,709 Bytes
1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 1b31f11 68b6477 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer
import cv2
import numpy as np
def distance_calculate(p1, p2):
"""p1 and p2 in format (x1, y1) and (x2, y2) tuples"""
dis = ((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2) ** 0.5
return dis
def push_up_count_logic(nose, right_wrist, right_shoulder):
if distance_calculate(right_shoulder, right_wrist) < 130:
return 1
elif push_up_start and distance_calculate(right_shoulder, right_wrist) > 250:
return 0
else:
return 0
# Define initial values
push_up_start = 0
push_up_count = 0
def video_frame_callback(frame):
global push_up_start, push_up_count
# Dummy values for demonstration
nose = (100, 100)
right_wrist = (200, 200)
right_shoulder = (150, 150)
push_up_count += push_up_count_logic(nose, right_wrist, right_shoulder)
# Display the push-up count on the video frame
image = frame.to_ndarray(format="bgr24")
font = cv2.FONT_HERSHEY_SIMPLEX
org = (50, 100)
font_scale = 1
color = (255, 0, 0)
thickness = 2
image = cv2.putText(
image,
f"Push-up count: {push_up_count}",
org,
font,
font_scale,
color,
thickness,
cv2.LINE_AA,
)
return av.VideoFrame.from_ndarray(image, format="bgr24")
def main():
st.title("AI Push-up Counter")
webrtc_ctx = webrtc_streamer(
key="pushup",
mode=WebRtcMode.SENDRECV,
# video_transformer_factory=None,
video_frame_callback=video_frame_callback,
# async_processing=True,
)
if not webrtc_ctx.state.playing:
return
if __name__ == "__main__":
main()
|