Update app.py
Browse files
app.py
CHANGED
|
@@ -48,7 +48,9 @@
|
|
| 48 |
# cv2.putText(frame, label, (x, y - 10),
|
| 49 |
# cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 50 |
|
| 51 |
-
#
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# # Streamlit App UI
|
| 54 |
# st.set_page_config(page_title="License Plate Detection", layout="wide")
|
|
@@ -65,11 +67,12 @@
|
|
| 65 |
# with col1:
|
| 66 |
# st.image(image_input, caption="Uploaded Image", use_container_width=True)
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
#
|
| 70 |
-
#
|
|
|
|
| 71 |
# with col2:
|
| 72 |
-
# st.image(result_img, caption="Detection Result",
|
| 73 |
# if confidence:
|
| 74 |
# st.metric("Confidence", f"{confidence * 100:.2f}%")
|
| 75 |
# st.success(f"Detected Text: {label}")
|
|
@@ -84,23 +87,18 @@
|
|
| 84 |
# if camera_image:
|
| 85 |
# try:
|
| 86 |
# image_input = Image.open(camera_image)
|
| 87 |
-
# # with col2:
|
| 88 |
-
# # st.image(image_input, caption="Webcam Snapshot", use_container_width=True)
|
| 89 |
-
|
| 90 |
# with st.spinner("Analyzing..."):
|
| 91 |
# result_img, confidence, label = detect_and_predict(image_input)
|
| 92 |
# with col2:
|
| 93 |
-
# st.image(result_img, caption="Detection Result",
|
| 94 |
# if confidence is not None:
|
| 95 |
# st.metric("Confidence", f"{confidence*100:.2f}%")
|
| 96 |
# st.success(f"Detected Text: {label}")
|
| 97 |
# else:
|
| 98 |
# st.warning("Plate detected but no readable text found.")
|
| 99 |
-
|
| 100 |
# except Exception as e:
|
| 101 |
# st.error(f"β Error: {str(e)}")
|
| 102 |
|
| 103 |
-
|
| 104 |
import streamlit as st
|
| 105 |
import cv2
|
| 106 |
import numpy as np
|
|
@@ -146,16 +144,17 @@ def detect_and_predict(img_input):
|
|
| 146 |
else:
|
| 147 |
label = "Plate Not Detected"
|
| 148 |
|
| 149 |
-
# Draw detection
|
| 150 |
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
| 151 |
cv2.putText(frame, label, (x, y - 10),
|
| 152 |
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 153 |
|
| 154 |
-
#
|
| 155 |
result_img = Image.fromarray(frame)
|
|
|
|
| 156 |
return result_img, confidence, plate_text
|
| 157 |
|
| 158 |
-
|
|
|
|
| 159 |
st.set_page_config(page_title="License Plate Detection", layout="wide")
|
| 160 |
st.title("π License Plate Detection App")
|
| 161 |
|
|
@@ -164,23 +163,23 @@ tab1, tab2 = st.tabs(["π Upload Image", "π· Webcam Capture"])
|
|
| 164 |
# Tab 1 - Upload Image
|
| 165 |
with tab1:
|
| 166 |
col1, col2 = st.columns([1, 2])
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
st.image(image_input, caption="Uploaded Image", use_container_width=True)
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
|
| 185 |
# Tab 2 - Webcam Input (camera snapshot)
|
| 186 |
with tab2:
|
|
@@ -192,8 +191,9 @@ with tab2:
|
|
| 192 |
image_input = Image.open(camera_image)
|
| 193 |
with st.spinner("Analyzing..."):
|
| 194 |
result_img, confidence, label = detect_and_predict(image_input)
|
|
|
|
| 195 |
with col2:
|
| 196 |
-
st.image(result_img, caption="Detection Result", use_container_width=
|
| 197 |
if confidence is not None:
|
| 198 |
st.metric("Confidence", f"{confidence*100:.2f}%")
|
| 199 |
st.success(f"Detected Text: {label}")
|
|
|
|
| 48 |
# cv2.putText(frame, label, (x, y - 10),
|
| 49 |
# cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 50 |
|
| 51 |
+
# # Ensure output image is same size as input
|
| 52 |
+
# result_img = Image.fromarray(frame)
|
| 53 |
+
# return result_img, confidence, plate_text
|
| 54 |
|
| 55 |
# # Streamlit App UI
|
| 56 |
# st.set_page_config(page_title="License Plate Detection", layout="wide")
|
|
|
|
| 67 |
# with col1:
|
| 68 |
# st.image(image_input, caption="Uploaded Image", use_container_width=True)
|
| 69 |
|
| 70 |
+
# if st.button("π Detect from Upload"):
|
| 71 |
+
# with st.spinner("Processing..."):
|
| 72 |
+
# result_img, confidence, label = detect_and_predict(image_input)
|
| 73 |
+
|
| 74 |
# with col2:
|
| 75 |
+
# st.image(result_img, caption="Detection Result", use_container_width=True)
|
| 76 |
# if confidence:
|
| 77 |
# st.metric("Confidence", f"{confidence * 100:.2f}%")
|
| 78 |
# st.success(f"Detected Text: {label}")
|
|
|
|
| 87 |
# if camera_image:
|
| 88 |
# try:
|
| 89 |
# image_input = Image.open(camera_image)
|
|
|
|
|
|
|
|
|
|
| 90 |
# with st.spinner("Analyzing..."):
|
| 91 |
# result_img, confidence, label = detect_and_predict(image_input)
|
| 92 |
# with col2:
|
| 93 |
+
# st.image(result_img, caption="Detection Result", use_container_width=True)
|
| 94 |
# if confidence is not None:
|
| 95 |
# st.metric("Confidence", f"{confidence*100:.2f}%")
|
| 96 |
# st.success(f"Detected Text: {label}")
|
| 97 |
# else:
|
| 98 |
# st.warning("Plate detected but no readable text found.")
|
|
|
|
| 99 |
# except Exception as e:
|
| 100 |
# st.error(f"β Error: {str(e)}")
|
| 101 |
|
|
|
|
| 102 |
import streamlit as st
|
| 103 |
import cv2
|
| 104 |
import numpy as np
|
|
|
|
| 144 |
else:
|
| 145 |
label = "Plate Not Detected"
|
| 146 |
|
|
|
|
| 147 |
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
| 148 |
cv2.putText(frame, label, (x, y - 10),
|
| 149 |
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
|
| 150 |
|
| 151 |
+
# Convert back to PIL and resize to 450x450 for display
|
| 152 |
result_img = Image.fromarray(frame)
|
| 153 |
+
result_img = result_img.resize((450, 450))
|
| 154 |
return result_img, confidence, plate_text
|
| 155 |
|
| 156 |
+
|
| 157 |
+
# Streamlit UI
|
| 158 |
st.set_page_config(page_title="License Plate Detection", layout="wide")
|
| 159 |
st.title("π License Plate Detection App")
|
| 160 |
|
|
|
|
| 163 |
# Tab 1 - Upload Image
|
| 164 |
with tab1:
|
| 165 |
col1, col2 = st.columns([1, 2])
|
| 166 |
+
with col1:
|
| 167 |
+
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"], key="uploader")
|
| 168 |
+
if uploaded_file:
|
| 169 |
+
image_input = Image.open(uploaded_file)
|
| 170 |
st.image(image_input, caption="Uploaded Image", use_container_width=True)
|
| 171 |
|
| 172 |
+
if st.button("π Detect from Upload"):
|
| 173 |
+
with st.spinner("Processing..."):
|
| 174 |
+
result_img, confidence, label = detect_and_predict(image_input)
|
| 175 |
|
| 176 |
+
with col2:
|
| 177 |
+
st.image(result_img, caption="Detection Result (450x450)", use_container_width=False)
|
| 178 |
+
if confidence:
|
| 179 |
+
st.metric("Confidence", f"{confidence * 100:.2f}%")
|
| 180 |
+
st.success(f"Detected Text: {label}")
|
| 181 |
+
else:
|
| 182 |
+
st.warning("No plate text detected.")
|
| 183 |
|
| 184 |
# Tab 2 - Webcam Input (camera snapshot)
|
| 185 |
with tab2:
|
|
|
|
| 191 |
image_input = Image.open(camera_image)
|
| 192 |
with st.spinner("Analyzing..."):
|
| 193 |
result_img, confidence, label = detect_and_predict(image_input)
|
| 194 |
+
|
| 195 |
with col2:
|
| 196 |
+
st.image(result_img, caption="Detection Result (450x450)", use_container_width=False)
|
| 197 |
if confidence is not None:
|
| 198 |
st.metric("Confidence", f"{confidence*100:.2f}%")
|
| 199 |
st.success(f"Detected Text: {label}")
|