Update app.py
Browse files
app.py
CHANGED
@@ -56,31 +56,56 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
56 |
global indexImg, output_text
|
57 |
|
58 |
img = frame.to_ndarray(format="bgr24")
|
59 |
-
|
60 |
# Process frame using MediaPipe
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
-
# Create
|
64 |
-
# keyboard_canvas = np.zeros_like(img)
|
65 |
buttonList = []
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Add special buttons for Backspace and Space
|
75 |
-
buttonList.append(Button([
|
76 |
-
buttonList.append(Button([
|
77 |
|
78 |
# Draw Keyboard Buttons
|
79 |
for button in buttonList:
|
80 |
x, y = button.pos
|
81 |
-
|
82 |
-
cv2.rectangle(img, (x, y), (x +
|
83 |
-
cv2.putText(img, button.text, (x +
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
detections = []
|
86 |
if result.multi_hand_landmarks:
|
|
|
56 |
global indexImg, output_text
|
57 |
|
58 |
img = frame.to_ndarray(format="bgr24")
|
59 |
+
# h, w = img.shape[:2]
|
60 |
# Process frame using MediaPipe
|
61 |
result = hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
62 |
|
63 |
+
# Create the keyboard buttons
|
|
|
64 |
buttonList = []
|
65 |
+
h, w = img.shape[:2]
|
66 |
+
key_width = int(0.08 * w)
|
67 |
+
key_height = int(0.1 * h)
|
68 |
+
font_scale = 0.005 * w
|
69 |
+
font_thickness = int(0.01 * h)
|
70 |
+
|
71 |
+
for row, key_row in enumerate(keys):
|
72 |
+
for col, key in enumerate(key_row):
|
73 |
+
x = int(0.03 * w + col * (key_width + 5))
|
74 |
+
y = int(0.03 * h + row * (key_height + 5))
|
75 |
+
buttonList.append(Button([x, y], key, size=[key_width, key_height]))
|
76 |
|
77 |
# Add special buttons for Backspace and Space
|
78 |
+
buttonList.append(Button([int(0.7 * w), int(0.03 * h)], 'BS', size=[int(0.1 * w), key_height]))
|
79 |
+
buttonList.append(Button([int(0.2 * w), int(0.8 * h)], 'SPACE', size=[int(0.6 * w), key_height]))
|
80 |
|
81 |
# Draw Keyboard Buttons
|
82 |
for button in buttonList:
|
83 |
x, y = button.pos
|
84 |
+
bw, bh = button.size
|
85 |
+
cv2.rectangle(img, (x, y), (x + bw, y + bh), (200, 200, 200), -1)
|
86 |
+
cv2.putText(img, button.text, (x + int(0.2 * bw), y + int(0.7 * bh)), cv2.FONT_HERSHEY_PLAIN, font_scale, (0, 0, 0), font_thickness)
|
87 |
+
|
88 |
+
# # Create a blank canvas for drawing the keyboard
|
89 |
+
# # keyboard_canvas = np.zeros_like(img)
|
90 |
+
# buttonList = []
|
91 |
+
# # Define buttons in each row of the virtual keyboard
|
92 |
+
# for key in keys[0]:
|
93 |
+
# buttonList.append(Button([30 + keys[0].index(key) * 105, 30], key))
|
94 |
+
# for key in keys[1]:
|
95 |
+
# buttonList.append(Button([30 + keys[1].index(key) * 105, 150], key))
|
96 |
+
# for key in keys[2]:
|
97 |
+
# buttonList.append(Button([30 + keys[2].index(key) * 105, 260], key))
|
98 |
+
|
99 |
+
# # Add special buttons for Backspace and Space
|
100 |
+
# buttonList.append(Button([90 + 10 * 100, 30], 'BS', size=[125, 100]))
|
101 |
+
# buttonList.append(Button([300, 370], 'SPACE', size=[500, 100]))
|
102 |
+
|
103 |
+
# # Draw Keyboard Buttons
|
104 |
+
# for button in buttonList:
|
105 |
+
# x, y = button.pos
|
106 |
+
# w, h = button.size
|
107 |
+
# cv2.rectangle(img, (x, y), (x + w, y + h), (200, 200, 200), -1)
|
108 |
+
# cv2.putText(img, button.text, (x + 20, y + 70), cv2.FONT_HERSHEY_PLAIN, 5, (0, 0, 0), 3)
|
109 |
|
110 |
detections = []
|
111 |
if result.multi_hand_landmarks:
|