Update app.py
Browse files
app.py
CHANGED
@@ -60,26 +60,26 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
60 |
# Process frame using MediaPipe
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
-
# Create a blank canvas for drawing the keyboard
|
64 |
-
keyboard_canvas = np.zeros_like(img)
|
65 |
-
buttonList = []
|
66 |
-
# Define buttons in each row of the virtual keyboard
|
67 |
-
for key in keys[0]:
|
68 |
-
|
69 |
-
for key in keys[1]:
|
70 |
-
|
71 |
-
for key in keys[2]:
|
72 |
-
|
73 |
-
|
74 |
-
# Add special buttons for Backspace and Space
|
75 |
-
buttonList.append(Button([90 + 10 * 100, 30], 'BS', size=[125, 100]))
|
76 |
-
buttonList.append(Button([300, 370], 'SPACE', size=[500, 100]))
|
77 |
-
for button in buttonList:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
|
84 |
detections = []
|
85 |
if result.multi_hand_landmarks:
|
@@ -107,19 +107,19 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
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 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
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
|
|
|
60 |
# Process frame using MediaPipe
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
+
# # Create a blank canvas for drawing the keyboard
|
64 |
+
# keyboard_canvas = np.zeros_like(img)
|
65 |
+
# buttonList = []
|
66 |
+
# # Define buttons in each row of the virtual keyboard
|
67 |
+
# for key in keys[0]:
|
68 |
+
# buttonList.append(Button([30 + keys[0].index(key) * 105, 30], key))
|
69 |
+
# for key in keys[1]:
|
70 |
+
# buttonList.append(Button([30 + keys[1].index(key) * 105, 150], key))
|
71 |
+
# for key in keys[2]:
|
72 |
+
# buttonList.append(Button([30 + keys[2].index(key) * 105, 260], key))
|
73 |
+
|
74 |
+
# # Add special buttons for Backspace and Space
|
75 |
+
# buttonList.append(Button([90 + 10 * 100, 30], 'BS', size=[125, 100]))
|
76 |
+
# buttonList.append(Button([300, 370], 'SPACE', size=[500, 100]))
|
77 |
+
# for button in buttonList:
|
78 |
+
# x, y = button.pos
|
79 |
+
# w, h = button.size
|
80 |
+
# if x < x8 < x + w and y < y8 < y + h:
|
81 |
+
# cv2.rectangle(img, button.pos, (x + w, y + h), (0, 255, 160), -1)
|
82 |
+
# cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (255, 255, 255), 3)
|
83 |
|
84 |
detections = []
|
85 |
if result.multi_hand_landmarks:
|
|
|
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
|