Update app.py
Browse files
app.py
CHANGED
@@ -92,6 +92,12 @@ detector = HandDetector(maxHands=1, detectionCon=0.8)
|
|
92 |
|
93 |
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
97 |
img = frame.to_ndarray(format="bgr24")
|
@@ -101,34 +107,27 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
101 |
if hands:
|
102 |
hand = hands[0]
|
103 |
bbox = hand["bbox"]
|
104 |
-
cv2.rectangle(img, (bbox[0], bbox[1]), (255, 0, 0), 2)
|
105 |
|
106 |
-
|
|
|
107 |
|
108 |
-
|
109 |
-
if "output_text" not in st.session_state:
|
110 |
-
st.session_state["output_text"] = ""
|
111 |
-
|
112 |
-
# Create a thread-safe queue for passing results from callback
|
113 |
-
result_queue = queue.Queue()
|
114 |
|
115 |
-
# def video_frame_callback(frame):
|
116 |
-
# # Process the frame asynchronously
|
117 |
-
# processed_frame = process_video_frame(frame, detector, segmentor, imgList, indexImg, keys, st.session_state)
|
118 |
-
# # Put the processed frame into the queue
|
119 |
-
# result_queue.put(processed_frame)
|
120 |
-
# return processed_frame
|
121 |
|
122 |
webrtc_ctx = webrtc_streamer(
|
123 |
key="keyboard-demo",
|
124 |
mode=WebRtcMode.SENDRECV,
|
125 |
rtc_configuration={
|
126 |
"iceServers": get_ice_servers(),
|
|
|
127 |
},
|
128 |
video_frame_callback=video_frame_callback,
|
129 |
media_stream_constraints={"video": True, "audio": False},
|
|
|
130 |
)
|
131 |
|
|
|
132 |
st.markdown("### Instructions")
|
133 |
st.write(
|
134 |
"""
|
|
|
92 |
|
93 |
|
94 |
|
95 |
+
# Shared state for output text
|
96 |
+
if "output_text" not in st.session_state:
|
97 |
+
st.session_state["output_text"] = ""
|
98 |
+
|
99 |
+
# Create a thread-safe queue for passing results from callback
|
100 |
+
result_queue = queue.Queue()
|
101 |
|
102 |
def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
103 |
img = frame.to_ndarray(format="bgr24")
|
|
|
107 |
if hands:
|
108 |
hand = hands[0]
|
109 |
bbox = hand["bbox"]
|
110 |
+
cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
|
111 |
|
112 |
+
result_queue.put(detections)
|
113 |
+
|
114 |
|
115 |
+
return av.VideoFrame.from_ndarray(img, format="bgr24")
|
|
|
|
|
|
|
|
|
|
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
webrtc_ctx = webrtc_streamer(
|
119 |
key="keyboard-demo",
|
120 |
mode=WebRtcMode.SENDRECV,
|
121 |
rtc_configuration={
|
122 |
"iceServers": get_ice_servers(),
|
123 |
+
"iceTransportPolicy": "relay",
|
124 |
},
|
125 |
video_frame_callback=video_frame_callback,
|
126 |
media_stream_constraints={"video": True, "audio": False},
|
127 |
+
async_processing=True,
|
128 |
)
|
129 |
|
130 |
+
|
131 |
st.markdown("### Instructions")
|
132 |
st.write(
|
133 |
"""
|