TheKnight115 commited on
Commit
3889969
Β·
verified Β·
1 Parent(s): ebf1c37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import streamlit as st
2
- from processor import process_video, process_image
3
  import os
4
  from PIL import Image
5
  import tempfile
6
  import cv2
 
 
 
7
 
8
- st.set_page_config(page_title="Traffic Violation Detection", layout="wide")
 
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 currently not supported in this app due to Streamlit limitations.")
90
- st.info("Consider running the live camera processing separately using your existing script.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+