a-guy-from-burma commited on
Commit
68b6477
1 Parent(s): 67e882f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -16,53 +16,53 @@ def push_up_count_logic(nose, right_wrist, right_shoulder):
16
  else:
17
  return 0
18
 
19
- def main():
20
- st.title("Push-up Counter using Streamlit and webrtc-streamer")
 
21
 
22
- webrtc_ctx = webrtc_streamer(
23
- key="example",
24
- mode=WebRtcMode.SENDRECV,
25
- video_transformer_factory=None,
26
- async_processing=True,
27
- )
28
 
29
- if not webrtc_ctx.state.playing:
30
- return
 
 
31
 
32
- push_up_start = 0
33
- push_up_count = 0
34
 
35
- while True:
36
- if webrtc_ctx.video_receiver:
37
- frame = webrtc_ctx.video_receiver.recv()
38
- image = frame.to_ndarray(format="bgr24")
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- # Dummy values for demonstration
41
- nose = (100, 100)
42
- right_wrist = (200, 200)
43
- right_shoulder = (150, 150)
44
 
45
- push_up_count += push_up_count_logic(nose, right_wrist, right_shoulder)
 
46
 
47
- # Display the push-up count on the video frame
48
- font = cv2.FONT_HERSHEY_SIMPLEX
49
- org = (50, 100)
50
- font_scale = 1
51
- color = (255, 0, 0)
52
- thickness = 2
53
- image = cv2.putText(
54
- image,
55
- f"Push-up count: {push_up_count}",
56
- org,
57
- font,
58
- font_scale,
59
- color,
60
- thickness,
61
- cv2.LINE_AA,
62
- )
63
 
64
- # Show the video frame with push-up count
65
- st.image(image, channels="BGR", use_column_width=True)
66
 
67
  if __name__ == "__main__":
68
- main()
 
16
  else:
17
  return 0
18
 
19
+ # Define initial values
20
+ push_up_start = 0
21
+ push_up_count = 0
22
 
23
+ def video_frame_callback(frame):
24
+ global push_up_start, push_up_count
 
 
 
 
25
 
26
+ # Dummy values for demonstration
27
+ nose = (100, 100)
28
+ right_wrist = (200, 200)
29
+ right_shoulder = (150, 150)
30
 
31
+ push_up_count += push_up_count_logic(nose, right_wrist, right_shoulder)
 
32
 
33
+ # Display the push-up count on the video frame
34
+ image = frame.to_ndarray(format="bgr24")
35
+ font = cv2.FONT_HERSHEY_SIMPLEX
36
+ org = (50, 100)
37
+ font_scale = 1
38
+ color = (255, 0, 0)
39
+ thickness = 2
40
+ image = cv2.putText(
41
+ image,
42
+ f"Push-up count: {push_up_count}",
43
+ org,
44
+ font,
45
+ font_scale,
46
+ color,
47
+ thickness,
48
+ cv2.LINE_AA,
49
+ )
50
 
51
+ return av.VideoFrame.from_ndarray(image, format="bgr24")
 
 
 
52
 
53
+ def main():
54
+ st.title("AI Push-up Counter")
55
 
56
+ webrtc_ctx = webrtc_streamer(
57
+ key="pushup",
58
+ mode=WebRtcMode.SENDRECV,
59
+ # video_transformer_factory=None,
60
+ video_frame_callback=video_frame_callback,
61
+ # async_processing=True,
62
+ )
 
 
 
 
 
 
 
 
 
63
 
64
+ if not webrtc_ctx.state.playing:
65
+ return
66
 
67
  if __name__ == "__main__":
68
+ main()