Pratyush101 commited on
Commit
ac89fbe
·
verified ·
1 Parent(s): 5fbfa28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -55,6 +55,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
55
  global indexImg, output_text
56
 
57
  img = frame.to_ndarray(format="bgr24")
 
58
  result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
59
 
60
  # Create the keyboard buttons
@@ -115,8 +116,9 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
115
  cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
116
  cv2.putText(img, button.text, (x + int(0.2 * bw), y + int(0.7 * bh)), cv2.FONT_HERSHEY_PLAIN, font_scale, (255, 255, 255), font_thickness)
117
 
118
- # # # Handle button press
119
- # if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
 
120
  # if time.time() - prev_key_time[0] > 2:
121
  # prev_key_time[0] = time.time()
122
  # if button.text != 'BS' and button.text != 'SPACE':
@@ -142,7 +144,14 @@ webrtc_streamer(
142
  key="virtual-keyboard",
143
  mode=WebRtcMode.SENDRECV,
144
  rtc_configuration={"iceServers": get_ice_servers(), "iceTransportPolicy": "relay"},
145
- media_stream_constraints={"video": True, "audio": False},
 
 
 
 
 
 
 
146
  video_frame_callback=video_frame_callback,
147
  async_processing=True,
148
  )
 
55
  global indexImg, output_text
56
 
57
  img = frame.to_ndarray(format="bgr24")
58
+ img = cv2.resize(img, (640, 480)) # Ensure fixed size
59
  result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
60
 
61
  # Create the keyboard buttons
 
116
  cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
117
  cv2.putText(img, button.text, (x + int(0.2 * bw), y + int(0.7 * bh)), cv2.FONT_HERSHEY_PLAIN, font_scale, (255, 255, 255), font_thickness)
118
 
119
+ # # Handle button press
120
+ if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
121
+
122
  # if time.time() - prev_key_time[0] > 2:
123
  # prev_key_time[0] = time.time()
124
  # if button.text != 'BS' and button.text != 'SPACE':
 
144
  key="virtual-keyboard",
145
  mode=WebRtcMode.SENDRECV,
146
  rtc_configuration={"iceServers": get_ice_servers(), "iceTransportPolicy": "relay"},
147
+ media_stream_constraints={
148
+ "video": {
149
+ "width": {"exact": 640},
150
+ "height": {"exact": 480},
151
+ # "frameRate": {"ideal": 30}
152
+ },
153
+ "audio": False,
154
+ },
155
  video_frame_callback=video_frame_callback,
156
  async_processing=True,
157
  )