Update app.py
Browse files
app.py
CHANGED
@@ -101,28 +101,37 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
101 |
x_max, y_max = max(x_max, x), max(y_max, y)
|
102 |
|
103 |
bbox = [x_min, y_min, x_max - x_min, y_max - y_min]
|
104 |
-
detections.append(Detection(label="Hand", score=
|
105 |
|
106 |
# Extract finger tip positions
|
107 |
x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
|
108 |
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)
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
# Distance Calculation
|
112 |
distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
|
113 |
click_threshold = 10
|
114 |
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
if time.time() - prev_key_time[0] > 2:
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
|
127 |
result_queue.put(detections)
|
128 |
st.session_state["output_text"] = output_text
|
|
|
101 |
x_max, y_max = max(x_max, x), max(y_max, y)
|
102 |
|
103 |
bbox = [x_min, y_min, x_max - x_min, y_max - y_min]
|
104 |
+
detections.append(Detection(label="Hand", score=0.5, box=np.array(bbox)))
|
105 |
|
106 |
# Extract finger tip positions
|
107 |
x4, y4 = int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].x * w), int(hand_landmarks.landmark[mp_hands.HandLandmark.THUMB_TIP].y * h)
|
108 |
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)
|
109 |
|
110 |
+
# Check for key presses
|
111 |
+
for button in buttonList:
|
112 |
+
x, y = button.pos
|
113 |
+
w, h = button.size
|
114 |
+
if x < x8 < x + w and y < y8 < y + h:
|
115 |
+
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 160), -1)
|
116 |
+
cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
|
117 |
+
|
118 |
+
|
119 |
|
120 |
# Distance Calculation
|
121 |
distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
|
122 |
click_threshold = 10
|
123 |
|
124 |
|
125 |
+
# # Simulate key press if finger close enough
|
126 |
+
# if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
|
127 |
+
# if time.time() - prev_key_time[0] > 2:
|
128 |
+
# prev_key_time[0] = time.time()
|
129 |
+
# if button.text != 'BS' and button.text != 'SPACE':
|
130 |
+
# output_text += button.text
|
131 |
+
# elif button.text == 'BS':
|
132 |
+
# output_text = output_text[:-1]
|
133 |
+
# else:
|
134 |
+
# output_text += ' '
|
135 |
|
136 |
result_queue.put(detections)
|
137 |
st.session_state["output_text"] = output_text
|