wesam0099 commited on
Commit
acbb1f1
·
verified ·
1 Parent(s): 5f5a0bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from LicensePlateAuthorizer import LicensePlateAuthorizer
5
+
6
+ # Initialize the License Plate Authorizer
7
+ lpa = LicensePlateAuthorizer()
8
+
9
+ # Streamlit interface
10
+ st.title("Real-Time License Plate Detection")
11
+ st.write("This app captures video from your webcam and detects license plates in real time.")
12
+
13
+ # Start video capture
14
+ cap = cv2.VideoCapture(0)
15
+
16
+ if not cap.isOpened():
17
+ st.error("Could not open webcam.")
18
+ else:
19
+ stframe = st.empty() # Placeholder for video frames
20
+
21
+ # Run real-time detection
22
+ while True:
23
+ ret, frame = cap.read()
24
+ if not ret:
25
+ st.error("Failed to grab frame.")
26
+ break
27
+
28
+ # Process the frame using your model
29
+ processed_frame = lpa.forward(frame)
30
+
31
+ if processed_frame is not None:
32
+ # Convert frame to RGB (Streamlit expects images in RGB format)
33
+ processed_frame_rgb = cv2.cvtColor(processed_frame, cv2.COLOR_BGR2RGB)
34
+ stframe.image(processed_frame_rgb, channels="RGB")
35
+
36
+ # Stop the loop if the user presses 'q' or closes the app
37
+ if st.button("Stop"):
38
+ break
39
+
40
+ cap.release()
41
+ cv2.destroyAllWindows()
42
+
43
+ st.write("Stopped the webcam.")