Update app.py
Browse files
app.py
CHANGED
@@ -13,18 +13,33 @@ st.title("Interactive Virtual Keyboard with Twilio Integration")
|
|
13 |
st.info("Use your webcam to interact with the virtual keyboard via hand gestures.")
|
14 |
|
15 |
detector = HandDetector(maxHands=1, detectionCon=0.8)
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
webrtc_ctx = webrtc_streamer(
|
30 |
key="keyboard-demo",
|
|
|
13 |
st.info("Use your webcam to interact with the virtual keyboard via hand gestures.")
|
14 |
|
15 |
detector = HandDetector(maxHands=1, detectionCon=0.8)
|
16 |
+
segmentor = SelfiSegmentation()
|
17 |
+
keys = [["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
18 |
+
["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"],
|
19 |
+
["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"]]
|
20 |
+
|
21 |
+
listImg = os.listdir('model/street')
|
22 |
+
imgList = [cv2.imread(f'model/street/{imgPath}') for imgPath in listImg]
|
23 |
+
indexImg = 0
|
24 |
+
|
25 |
+
# Shared state for output text
|
26 |
+
if "output_text" not in st.session_state:
|
27 |
+
st.session_state["output_text"] = ""
|
28 |
+
|
29 |
+
# Create a thread-safe queue for passing results from callback
|
30 |
+
result_queue = queue.Queue()
|
31 |
+
|
32 |
+
# Function to process video frame callback
|
33 |
+
# Corrected function for video frame callback
|
34 |
+
#####FromHERE CHANGE
|
35 |
+
# Function to process video frame callback
|
36 |
+
# Function to process video frame callback
|
37 |
+
def video_frame_callback(frame):
|
38 |
+
# Process the frame asynchronously
|
39 |
+
output_text = process_video_frame(frame, detector, segmentor, imgList, indexImg, keys, st.session_state)
|
40 |
+
# Put the processed output text into the queue
|
41 |
+
result_queue.put(output_text)
|
42 |
+
return frame # Return the processed frame for
|
43 |
|
44 |
webrtc_ctx = webrtc_streamer(
|
45 |
key="keyboard-demo",
|