Update app.py
Browse files
app.py
CHANGED
@@ -61,6 +61,12 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
buttonList = [Button([30 + col * 105, 30 + row * 120], key) for row, line in enumerate(keys) for col, key in enumerate(line)]
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
detections = []
|
66 |
if result.multi_hand_landmarks:
|
@@ -93,12 +99,6 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
93 |
distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
|
94 |
click_threshold = 10
|
95 |
|
96 |
-
for button in buttonList:
|
97 |
-
x, y = button.pos
|
98 |
-
w, h = button.size
|
99 |
-
if x < x8 < x + w and y < y8 < y + h:
|
100 |
-
cv2.rectangle(img, button.pos, (x + w, y + h), (0, 255, 160), -1)
|
101 |
-
cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
|
102 |
|
103 |
# Simulate key press if finger close enough
|
104 |
if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
|
|
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
buttonList = [Button([30 + col * 105, 30 + row * 120], key) for row, line in enumerate(keys) for col, key in enumerate(line)]
|
64 |
+
for button in buttonList:
|
65 |
+
x, y = button.pos
|
66 |
+
w, h = button.size
|
67 |
+
if x < x8 < x + w and y < y8 < y + h:
|
68 |
+
cv2.rectangle(img, button.pos, (x + w, y + h), (0, 255, 160), -1)
|
69 |
+
cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
|
70 |
|
71 |
detections = []
|
72 |
if result.multi_hand_landmarks:
|
|
|
99 |
distance = np.sqrt((x8 - x4) ** 2 + (y8 - y4) ** 2)
|
100 |
click_threshold = 10
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
# Simulate key press if finger close enough
|
104 |
if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
|