Pratyush101 commited on
Commit
5b6aa72
·
verified ·
1 Parent(s): a07c857

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
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
- def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
18
- img = frame.to_ndarray(format="bgr24")
19
- hands, img = detector.findHands(img, flipType=False)
20
-
21
- # Render hand detection results
22
- if hands:
23
- hand = hands[0]
24
- bbox = hand["bbox"]
25
- cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
26
-
27
- return av.VideoFrame.from_ndarray(img, format="bgr24")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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",