Update app.py
Browse files
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 |
-
#
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
|
144 |
|
145 |
|
146 |
-
#
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
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
|