Update app.py
Browse files
app.py
CHANGED
@@ -106,7 +106,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
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 =
|
110 |
|
111 |
for button in buttonList:
|
112 |
x, y = button.pos
|
@@ -114,20 +114,17 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
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 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
# else:
|
129 |
-
# output_text += ' ' # Add space
|
130 |
-
# cv2.putText(img, output_text, (int(0.05 * w) , int(0.95 * h)), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 5)
|
131 |
|
132 |
|
133 |
|
|
|
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 = 0.2*np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)
|
110 |
|
111 |
for button in buttonList:
|
112 |
x, y = button.pos
|
|
|
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 |
+
# # Handle button press
|
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 # Append key to output text
|
123 |
+
elif button.text == 'BS':
|
124 |
+
output_text = output_text[:-1] # Remove last character
|
125 |
+
else:
|
126 |
+
output_text += ' ' # Add space
|
127 |
+
cv2.putText(img, output_text, (int(0.05 * w) , int(0.95 * h)), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 5)
|
|
|
|
|
|
|
128 |
|
129 |
|
130 |
|