ksvmuralidhar commited on
Commit
eb81ea9
·
verified ·
1 Parent(s): 238743c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -19
app.py CHANGED
@@ -93,11 +93,14 @@ def get_upload_path():
93
  return upload_file_path
94
 
95
 
96
- def process_input_image(img_url):
97
  upload_file_path = get_upload_path()
98
- 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'}
99
- r = get(img_url, headers=headers)
100
- arr = np.frombuffer(r.content, np.uint8)
 
 
 
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
- st.markdown("<h3>Vehicle Registration Number Detection</h3>", unsafe_allow_html=True)
110
- desc = '''Dataset used to fine-tune YOLOv8
111
- can be found <a href="https://universe.roboflow.com/my-workspace-cut7i/lpr_ocr/dataset/1" target="_blank">
112
- here</a> See that the input images are similar to these for better detection.
113
- '''
114
- st.markdown(desc, unsafe_allow_html=True)
115
- img_url = st.text_input("Paste the image URL of the vehicle license/registration plate:", "")
116
- placeholder = st.empty()
117
- if img_url:
118
- placeholder.empty()
119
- img_path = process_input_image(img_url)
120
- inference(img_path)
121
- files_cleanup(img_path)
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}')