Pratyush101 commited on
Commit
a078ac1
·
verified ·
1 Parent(s): 8bc4148

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -105,25 +105,25 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
105
  x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
106
  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)
107
 
 
 
 
108
  for button in buttonList:
109
  x, y = button.pos
110
  bw, bh = button.size
111
  if x < x8 < x + bw and y < y8 < y + bh:
112
- cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
113
- 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)
114
-
115
- distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
116
- click_threshold = 10
117
-
118
- if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
119
- if time.time() - prev_key_time[0] > 2:
120
- prev_key_time[0] = time.time()
121
- if button.text != 'BS' and button.text != 'SPACE':
122
- output_text += button.text
123
- elif button.text == 'BS':
124
- output_text = output_text[:-1]
125
- else:
126
- output_text += ' '
127
 
128
  result_queue.put(detections)
129
  st.session_state["output_text"] = output_text
 
105
  x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
106
  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)
107
 
108
+ distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
109
+ click_threshold = 10
110
+
111
  for button in buttonList:
112
  x, y = button.pos
113
  bw, bh = button.size
114
  if x < x8 < x + bw and y < y8 < y + bh:
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
+ if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
119
+ if time.time() - prev_key_time[0] > 2:
120
+ prev_key_time[0] = time.time()
121
+ if button.text != 'BS' and button.text != 'SPACE':
122
+ output_text += button.text
123
+ elif button.text == 'BS':
124
+ output_text = output_text[:-1]
125
+ else:
126
+ output_text += ' '
 
 
 
127
 
128
  result_queue.put(detections)
129
  st.session_state["output_text"] = output_text