File size: 1,293 Bytes
0ac8362 0325cdc 94546d9 79ac659 0ac8362 94546d9 0ac8362 94546d9 ae6b0ae 94546d9 0ac8362 94546d9 a01685d 94546d9 a01685d 94546d9 a01685d 94546d9 a01685d 0ac8362 94546d9 0325cdc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import logging
import cv2
import numpy as np
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer
from cvzone.HandTrackingModule import HandDetector
from sample_utils.turn import get_ice_servers
logger = logging.getLogger(__name__)
st.title("Interactive Virtual Keyboard with Twilio Integration")
st.info("Use your webcam to interact with the virtual keyboard via hand gestures.")
detector = HandDetector(maxHands=1, detectionCon=0.8)
def video_frame_callback(frame):
img = frame.to_ndarray(format="bgr24")
hands, img = detector.findHands(img, flipType=False)
# Render hand detection results
if hands:
hand = hands[0]
bbox = hand["bbox"]
cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
return av.VideoFrame.from_ndarray(img, format="bgr24")
webrtc_ctx = webrtc_streamer(
key="keyboard-demo",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": get_ice_servers()},
video_frame_callback=video_frame_callback,
media_stream_constraints={"video": True, "audio": False},
)
st.markdown("### Instructions")
st.write(
"""
1. Turn on your webcam using the checkbox above.
2. Use hand gestures to interact with the virtual keyboard.
"""
)
|