Spaces:
Running
Running
Update pages/Camera.py
Browse files- pages/Camera.py +35 -13
pages/Camera.py
CHANGED
|
@@ -1,34 +1,42 @@
|
|
| 1 |
import logging
|
| 2 |
import queue
|
| 3 |
from collections import deque
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
from streamlit_webrtc import WebRtcMode, webrtc_streamer
|
| 7 |
|
| 8 |
from utils import SLInference
|
| 9 |
|
|
|
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
-
def
|
| 13 |
"""
|
| 14 |
Main function of the app.
|
| 15 |
"""
|
| 16 |
config = {
|
| 17 |
"path_to_model": "S3D.onnx",
|
| 18 |
-
"threshold": 0.
|
| 19 |
"topk": 5,
|
| 20 |
"path_to_class_list": "RSL_class_list.txt",
|
| 21 |
-
"window_size":
|
| 22 |
"provider": "OpenVINOExecutionProvider"
|
| 23 |
}
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
inference_thread.start()
|
| 27 |
|
| 28 |
webrtc_ctx = webrtc_streamer(
|
| 29 |
-
key="video-
|
| 30 |
-
mode=WebRtcMode.
|
| 31 |
-
media_stream_constraints={"video": True
|
| 32 |
)
|
| 33 |
|
| 34 |
gestures_deque = deque(maxlen=5)
|
|
@@ -38,9 +46,18 @@ def display():
|
|
| 38 |
image_place = st.empty()
|
| 39 |
text_output = st.empty()
|
| 40 |
last_5_gestures = st.empty()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
video_frame = webrtc_ctx.video_receiver.get_frame(timeout=1)
|
| 46 |
except queue.Empty:
|
|
@@ -49,7 +66,7 @@ def display():
|
|
| 49 |
|
| 50 |
img_rgb = video_frame.to_ndarray(format="rgb24")
|
| 51 |
image_place.image(img_rgb)
|
| 52 |
-
inference_thread.input_queue.append(video_frame.reformat(224,224).to_ndarray(format="rgb24"))
|
| 53 |
|
| 54 |
gesture = inference_thread.pred
|
| 55 |
if gesture not in ['no', '']:
|
|
@@ -58,6 +75,11 @@ def display():
|
|
| 58 |
elif gesture != gestures_deque[-1]:
|
| 59 |
gestures_deque.append(gesture)
|
| 60 |
|
| 61 |
-
text_output.markdown(f'<p style="font-size:20px"> Current gesture: {gesture}</p>',
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import logging
|
| 2 |
import queue
|
| 3 |
from collections import deque
|
| 4 |
+
import json
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
import streamlit as st
|
| 8 |
from streamlit_webrtc import WebRtcMode, webrtc_streamer
|
| 9 |
|
| 10 |
from utils import SLInference
|
| 11 |
|
| 12 |
+
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
| 15 |
+
def main():
|
| 16 |
"""
|
| 17 |
Main function of the app.
|
| 18 |
"""
|
| 19 |
config = {
|
| 20 |
"path_to_model": "S3D.onnx",
|
| 21 |
+
"threshold": 0.3,
|
| 22 |
"topk": 5,
|
| 23 |
"path_to_class_list": "RSL_class_list.txt",
|
| 24 |
+
"window_size": 32,
|
| 25 |
"provider": "OpenVINOExecutionProvider"
|
| 26 |
}
|
| 27 |
|
| 28 |
+
# Сохранение конфигурации во временный файл
|
| 29 |
+
with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.json') as config_file:
|
| 30 |
+
json.dump(config, config_file)
|
| 31 |
+
config_file_path = config_file.name
|
| 32 |
+
|
| 33 |
+
inference_thread = SLInference(config_file_path)
|
| 34 |
inference_thread.start()
|
| 35 |
|
| 36 |
webrtc_ctx = webrtc_streamer(
|
| 37 |
+
key="video-sendonly",
|
| 38 |
+
mode=WebRtcMode.SENDONLY,
|
| 39 |
+
media_stream_constraints={"video": True},
|
| 40 |
)
|
| 41 |
|
| 42 |
gestures_deque = deque(maxlen=5)
|
|
|
|
| 46 |
image_place = st.empty()
|
| 47 |
text_output = st.empty()
|
| 48 |
last_5_gestures = st.empty()
|
| 49 |
+
st.markdown(
|
| 50 |
+
"""
|
| 51 |
+
This application is designed to recognize sign language using a webcam feed.
|
| 52 |
+
The model has been trained to recognize various sign language gestures and display the corresponding text in real-time.
|
| 53 |
|
| 54 |
+
This demo app is based on code here: https://github.com/ai-forever/easy_sign
|
| 55 |
+
The project is open for collaboration. If you have any suggestions or want to contribute, please feel free to reach out.
|
| 56 |
+
"""
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
while True:
|
| 60 |
+
if webrtc_ctx.video_receiver:
|
| 61 |
try:
|
| 62 |
video_frame = webrtc_ctx.video_receiver.get_frame(timeout=1)
|
| 63 |
except queue.Empty:
|
|
|
|
| 66 |
|
| 67 |
img_rgb = video_frame.to_ndarray(format="rgb24")
|
| 68 |
image_place.image(img_rgb)
|
| 69 |
+
inference_thread.input_queue.append(video_frame.reformat(224, 224).to_ndarray(format="rgb24"))
|
| 70 |
|
| 71 |
gesture = inference_thread.pred
|
| 72 |
if gesture not in ['no', '']:
|
|
|
|
| 75 |
elif gesture != gestures_deque[-1]:
|
| 76 |
gestures_deque.append(gesture)
|
| 77 |
|
| 78 |
+
text_output.markdown(f'<p style="font-size:20px"> Current gesture: {gesture}</p>',
|
| 79 |
+
unsafe_allow_html=True)
|
| 80 |
+
last_5_gestures.markdown(f'<p style="font-size:20px"> Last 5 gestures: {" ".join(gestures_deque)}</p>',
|
| 81 |
+
unsafe_allow_html=True)
|
| 82 |
+
print(gestures_deque)
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
main()
|