DILSHAD737 commited on
Commit
4f9b854
·
verified ·
1 Parent(s): ac156da

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +52 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import av
3
+ import asyncio
4
+ import numpy as np
5
+ import streamlit as st
6
+ from streamlit_webrtc import WebRtcMode, webrtc_streamer
7
+
8
+ # Fix asyncio event loop issue on Windows
9
+ if hasattr(asyncio, 'WindowsSelectorEventLoopPolicy'):
10
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
11
+
12
+ # Load Haarcascade model
13
+ face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
14
+
15
+ # Face detection function for WebRTC
16
+ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
17
+ img = frame.to_ndarray(format="bgr24")
18
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
19
+ faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
20
+
21
+ for (x, y, w, h) in faces:
22
+ cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
23
+
24
+ return av.VideoFrame.from_ndarray(img, format="bgr24")
25
+
26
+ # Streamlit UI
27
+ st.title("Real-Time Face Detection")
28
+ st.write("Using OpenCV and Haar Cascade Model")
29
+
30
+ # WebRTC streamer
31
+ webrtc_streamer(
32
+ key="face-detection",
33
+ mode=WebRtcMode.SENDRECV,
34
+ rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
35
+ video_frame_callback=video_frame_callback,
36
+ async_processing=True # Keep this enabled for async processing
37
+ )
requirements.txt ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aioice==0.9.0
2
+ aiortc==1.10.1
3
+ altair==5.5.0
4
+ attrs==25.2.0
5
+ av==13.1.0
6
+ blinker==1.9.0
7
+ cachetools==5.5.2
8
+ certifi==2025.1.31
9
+ cffi==1.17.1
10
+ charset-normalizer==3.4.1
11
+ click==8.1.8
12
+ colorama==0.4.6
13
+ cryptography==44.0.2
14
+ dnspython==2.7.0
15
+ gitdb==4.0.12
16
+ GitPython==3.1.44
17
+ google-crc32c==1.6.0
18
+ idna==3.10
19
+ ifaddr==0.2.0
20
+ Jinja2==3.1.6
21
+ jsonschema==4.23.0
22
+ jsonschema-specifications==2024.10.1
23
+ MarkupSafe==3.0.2
24
+ narwhals==1.30.0
25
+ numpy==2.2.3
26
+ opencv-python==4.11.0.86
27
+ packaging==24.2
28
+ pandas==2.2.3
29
+ pillow==11.1.0
30
+ protobuf==5.29.3
31
+ pyarrow==19.0.1
32
+ pycparser==2.22
33
+ pydeck==0.9.1
34
+ pyee==12.1.1
35
+ pylibsrtp==0.11.0
36
+ pyOpenSSL==25.0.0
37
+ python-dateutil==2.9.0.post0
38
+ pytz==2025.1
39
+ referencing==0.36.2
40
+ requests==2.32.3
41
+ rpds-py==0.23.1
42
+ six==1.17.0
43
+ smmap==5.0.2
44
+ streamlit==1.43.2
45
+ streamlit-webrtc==0.49.0
46
+ tenacity==9.0.0
47
+ toml==0.10.2
48
+ tornado==6.4.2
49
+ typing_extensions==4.12.2
50
+ tzdata==2025.1
51
+ urllib3==2.3.0
52
+ watchdog==6.0.0