Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
-
from processor import
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
import cv2
|
|
|
|
|
|
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
st.title("π¦ Traffic Violation Detection App")
|
11 |
|
@@ -86,5 +90,32 @@ elif option == "Video":
|
|
86 |
|
87 |
elif option == "Live Camera":
|
88 |
st.header("π· Live Camera Processing")
|
89 |
-
st.warning("Live camera processing is
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from processor import process_frame, process_image, process_video
|
3 |
import os
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
import cv2
|
7 |
+
from streamlit_webrtc import VideoTransformerBase, webrtc_streamer, WebRtcMode, ClientSettings
|
8 |
+
import av
|
9 |
+
import asyncio
|
10 |
|
11 |
+
# Configure Streamlit page
|
12 |
+
st.set_page_config(page_title="π¦ Traffic Violation Detection", layout="wide")
|
13 |
|
14 |
st.title("π¦ Traffic Violation Detection App")
|
15 |
|
|
|
90 |
|
91 |
elif option == "Live Camera":
|
92 |
st.header("π· Live Camera Processing")
|
93 |
+
st.warning("Live camera processing is in progress. Please allow camera access.")
|
94 |
+
|
95 |
+
# Define settings for WebRTC
|
96 |
+
WEBRTC_CLIENT_SETTINGS = ClientSettings(
|
97 |
+
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]},
|
98 |
+
media_stream_constraints={"video": True, "audio": False},
|
99 |
+
)
|
100 |
+
|
101 |
+
class VideoTransformer(VideoTransformerBase):
|
102 |
+
def __init__(self):
|
103 |
+
self.font_path = "fonts/alfont_com_arial-1.ttf" # Update the path as needed
|
104 |
+
|
105 |
+
def transform(self, frame):
|
106 |
+
img = frame.to_ndarray(format="bgr24")
|
107 |
+
processed_img = process_frame(img, self.font_path)
|
108 |
+
if processed_img is not None:
|
109 |
+
return processed_img
|
110 |
+
return img
|
111 |
+
|
112 |
+
webrtc_ctx = webrtc_streamer(
|
113 |
+
key="live-camera",
|
114 |
+
mode=WebRtcMode.SENDRECV,
|
115 |
+
client_settings=WEBRTC_CLIENT_SETTINGS,
|
116 |
+
video_transformer_factory=VideoTransformer,
|
117 |
+
async_transform=True,
|
118 |
+
)
|
119 |
+
|
120 |
+
st.info("Live camera feed is being processed. Detected violations will be annotated on the video stream.")
|
121 |
+
|