Pratyush101 commited on
Commit
075c853
·
verified ·
1 Parent(s): 4f1a835

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -133,31 +133,30 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
133
  x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
134
  x8, y8 = int(hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y * h)
135
 
136
- # # Check for key presses
137
- # for button in buttonList:
138
- # x, y = button.pos
139
- # w, h = button.size
140
- # if x < x8 < x + w and y < y8 < y + h:
141
- # cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 160), -1)
142
- # cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
143
 
144
 
145
 
146
- # # Distance Calculation
147
- # distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
148
- # click_threshold = 10
149
-
150
-
151
- # # Simulate key press if finger close enough
152
- # if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
153
- # if time.time() - prev_key_time[0] > 2:
154
- # prev_key_time[0] = time.time()
155
- # if button.text != 'BS' and button.text != 'SPACE':
156
- # output_text += button.text
157
- # elif button.text == 'BS':
158
- # output_text = output_text[:-1]
159
- # else:
160
- # output_text += ' '
161
 
162
  result_queue.put(detections)
163
  st.session_state["output_text"] = output_text
 
133
  x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
134
  x8, y8 = int(hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y * h)
135
 
136
+ # Check for whether the finger is in button bounds
137
+ for button in buttonList:
138
+ x, y = button.pos
139
+ bw, bh = button.size
140
+ if x < x8 < x + bw and y < y8 < y + bh:
141
+ cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
142
+ 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)
143
 
144
 
145
 
146
+ # Distance Calculation
147
+ distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
148
+ click_threshold = 10
149
+
150
+ # # Simulate key press if finger close enough
151
+ # if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
152
+ # if time.time() - prev_key_time[0] > 2:
153
+ # prev_key_time[0] = time.time()
154
+ # if button.text != 'BS' and button.text != 'SPACE':
155
+ # output_text += button.text
156
+ # elif button.text == 'BS':
157
+ # output_text = output_text[:-1]
158
+ # else:
159
+ # output_text += ' '
 
160
 
161
  result_queue.put(detections)
162
  st.session_state["output_text"] = output_text