RP-Azul commited on
Commit
e2d9e99
·
verified ·
1 Parent(s): a95228d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -18,31 +18,35 @@ class VideoProcessor(VideoTransformerBase):
18
  )
19
 
20
  def recv(self, frame):
 
21
  img = frame.to_ndarray(format="bgr24")
22
- img = cv2.flip(img, 1) # Flip for a mirror effect
23
  img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
24
 
25
  # Process the frame for hand landmarks
26
  result = self.hands.process(img_rgb)
27
 
28
- # Draw hand landmarks
29
  if result.multi_hand_landmarks:
30
  for hand_landmarks in result.multi_hand_landmarks:
31
  mp_drawing.draw_landmarks(
32
  img, hand_landmarks, mp_hands.HAND_CONNECTIONS
33
  )
34
 
 
35
  return av.VideoFrame.from_ndarray(img, format="bgr24")
36
 
37
  # Streamlit UI
38
  st.title("Gesture & Hand Landmark Detection 🚀")
39
  st.write("This app uses MediaPipe and Streamlit to detect hand landmarks in real-time from your webcam.")
40
 
41
- # WebRTC streamer for live video
42
  webrtc_streamer(
43
  key="gesture-detection",
44
  video_processor_factory=VideoProcessor,
45
- rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
 
 
46
  )
47
 
48
  # Footer
@@ -51,7 +55,7 @@ st.markdown(
51
  <style>
52
  .footer {text-align: center; font-size: 12px; color: grey; margin-top: 20px;}
53
  </style>
54
- <p class="footer"></p>
55
  """,
56
  unsafe_allow_html=True,
57
  )
 
18
  )
19
 
20
  def recv(self, frame):
21
+ # Convert the input frame to a numpy array
22
  img = frame.to_ndarray(format="bgr24")
23
+ img = cv2.flip(img, 1) # Flip horizontally for a mirror effect
24
  img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
25
 
26
  # Process the frame for hand landmarks
27
  result = self.hands.process(img_rgb)
28
 
29
+ # Draw hand landmarks on the frame
30
  if result.multi_hand_landmarks:
31
  for hand_landmarks in result.multi_hand_landmarks:
32
  mp_drawing.draw_landmarks(
33
  img, hand_landmarks, mp_hands.HAND_CONNECTIONS
34
  )
35
 
36
+ # Return the processed frame back to the WebRTC streamer
37
  return av.VideoFrame.from_ndarray(img, format="bgr24")
38
 
39
  # Streamlit UI
40
  st.title("Gesture & Hand Landmark Detection 🚀")
41
  st.write("This app uses MediaPipe and Streamlit to detect hand landmarks in real-time from your webcam.")
42
 
43
+ # WebRTC streamer for live video feed
44
  webrtc_streamer(
45
  key="gesture-detection",
46
  video_processor_factory=VideoProcessor,
47
+ rtc_configuration={
48
+ "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
49
+ },
50
  )
51
 
52
  # Footer
 
55
  <style>
56
  .footer {text-align: center; font-size: 12px; color: grey; margin-top: 20px;}
57
  </style>
58
+ <p class="footer">Made with g Streamlit & MediaPipe</p>
59
  """,
60
  unsafe_allow_html=True,
61
  )