Update app.py
Browse files
app.py
CHANGED
@@ -93,11 +93,14 @@ def get_upload_path():
|
|
93 |
return upload_file_path
|
94 |
|
95 |
|
96 |
-
def process_input_image(
|
97 |
upload_file_path = get_upload_path()
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
101 |
input_image = cv2.imdecode(arr, cv2.IMREAD_UNCHANGED)
|
102 |
input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
|
103 |
input_image = cv2.resize(input_image, (640, 640))
|
@@ -105,22 +108,45 @@ def process_input_image(img_url):
|
|
105 |
return upload_file_path
|
106 |
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
try:
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
except Exception as e:
|
124 |
upload_file_path = get_upload_path()
|
125 |
files_cleanup(upload_file_path)
|
126 |
-
st.error(f'An unexpected error occured: \n{e}')
|
|
|
93 |
return upload_file_path
|
94 |
|
95 |
|
96 |
+
def process_input_image(input_):
|
97 |
upload_file_path = get_upload_path()
|
98 |
+
if input_type == 'Paste image URL':
|
99 |
+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'}
|
100 |
+
r = get(img_url, headers=headers)
|
101 |
+
arr = np.frombuffer(r.content, np.uint8)
|
102 |
+
else:
|
103 |
+
arr = np.frombuffer(input_, np.uint8)
|
104 |
input_image = cv2.imdecode(arr, cv2.IMREAD_UNCHANGED)
|
105 |
input_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB)
|
106 |
input_image = cv2.resize(input_image, (640, 640))
|
|
|
108 |
return upload_file_path
|
109 |
|
110 |
|
111 |
+
st.markdown("<h3>Vehicle Registration Number Detection</h3>", unsafe_allow_html=True)
|
112 |
+
desc = '''Dataset used to fine-tune YOLOv8
|
113 |
+
can be found <a href="https://universe.roboflow.com/my-workspace-cut7i/lpr_ocr/dataset/1" target="_blank">
|
114 |
+
here</a> See that the input images are similar to these for better detection.
|
115 |
+
'''
|
116 |
+
st.markdown(desc, unsafe_allow_html=True)
|
117 |
+
input_type = st.radio('Select an option:', ['Paste image URL', 'Capture using camera'],
|
118 |
+
captions=['Recommended for laptops/desktops', 'Recommended for mobile devices'],
|
119 |
+
horizontal=True)
|
120 |
+
|
121 |
+
|
122 |
try:
|
123 |
+
if input_type == 'Paste image URL':
|
124 |
+
img_url = st.text_input("Paste the image URL of the vehicle license/registration plate:", "")
|
125 |
+
if img_url:
|
126 |
+
img_path = process_input_image(img_url)
|
127 |
+
inference(img_path)
|
128 |
+
files_cleanup(img_path)
|
129 |
+
else:
|
130 |
+
st.markdown("<h4>Capture the image in landscape mode</h4>", unsafe_allow_html=True)
|
131 |
+
col1, col2, col3 = st.columns([0.15, 0.7, 0.15])
|
132 |
+
with col1:
|
133 |
+
st.write(' ')
|
134 |
+
with col2:
|
135 |
+
img_file_buffer = st.camera_input("Take the number plate's picture")
|
136 |
+
st.write(' ')
|
137 |
+
with col3:
|
138 |
+
st.write(' ')
|
139 |
+
with col2:
|
140 |
+
st.write(' ')
|
141 |
+
with col2:
|
142 |
+
st.write(' ')
|
143 |
+
if img_file_buffer is not None:
|
144 |
+
bytes_data = img_file_buffer.getvalue()
|
145 |
+
img_path = process_input_image(bytes_data)
|
146 |
+
inference(img_path)
|
147 |
+
files_cleanup(img_path)
|
148 |
+
|
149 |
except Exception as e:
|
150 |
upload_file_path = get_upload_path()
|
151 |
files_cleanup(upload_file_path)
|
152 |
+
st.error(f'An unexpected error occured: \n{e}')
|