Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,7 @@ import pytesseract
|
|
13 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
14 |
from PIL import Image
|
15 |
import torch
|
|
|
16 |
|
17 |
from glob import glob
|
18 |
from skimage import io
|
@@ -180,7 +181,7 @@ def main():
|
|
180 |
number_plate_img, coords = yolo_predictions(image, net)
|
181 |
|
182 |
# Display the detected number plate image
|
183 |
-
st.image(number_plate_img, caption="Detected Number Plate", use_column_width=True)
|
184 |
|
185 |
for box in coords:
|
186 |
x, y, width, height = box
|
@@ -189,7 +190,7 @@ def main():
|
|
189 |
cropped_image = crop_image(np.array(number_plate_img), x, y, width, height)
|
190 |
|
191 |
# Display the coordinates
|
192 |
-
st.write("Detected Number Plate Coordinates:", coords)
|
193 |
|
194 |
# Display the cropped image
|
195 |
st.image(cropped_image, caption="Detected Number Plate", use_column_width=True)
|
@@ -198,7 +199,18 @@ def main():
|
|
198 |
cropped_image = np.array(cropped_image) # Replace ... with your actual image array
|
199 |
extracted_text = tr_ocr_image_from_array(cropped_image)
|
200 |
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
st.text(extracted_text)
|
203 |
|
204 |
|
|
|
13 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
14 |
from PIL import Image
|
15 |
import torch
|
16 |
+
import re
|
17 |
|
18 |
from glob import glob
|
19 |
from skimage import io
|
|
|
181 |
number_plate_img, coords = yolo_predictions(image, net)
|
182 |
|
183 |
# Display the detected number plate image
|
184 |
+
# st.image(number_plate_img, caption="Detected Number Plate", use_column_width=True)
|
185 |
|
186 |
for box in coords:
|
187 |
x, y, width, height = box
|
|
|
190 |
cropped_image = crop_image(np.array(number_plate_img), x, y, width, height)
|
191 |
|
192 |
# Display the coordinates
|
193 |
+
# st.write("Detected Number Plate Coordinates:", coords)
|
194 |
|
195 |
# Display the cropped image
|
196 |
st.image(cropped_image, caption="Detected Number Plate", use_column_width=True)
|
|
|
199 |
cropped_image = np.array(cropped_image) # Replace ... with your actual image array
|
200 |
extracted_text = tr_ocr_image_from_array(cropped_image)
|
201 |
|
202 |
+
#Remove speical characters from the extracted text
|
203 |
+
def remove_special_characters(text):
|
204 |
+
pattern = r'[^a-zA-Z0-9\s]' # This pattern matches any character that is not alphanumeric or whitespace
|
205 |
+
|
206 |
+
# Use re.sub() to replace all occurrences of the pattern with an empty string
|
207 |
+
cleaned_text = re.sub(pattern, '', text)
|
208 |
+
|
209 |
+
return cleaned_text
|
210 |
+
|
211 |
+
extracted_text = remove_special_characters(extracted_text)
|
212 |
+
|
213 |
+
st.markdown("<span style='color:red; font-weight:bold'>Extracted text:</span>", unsafe_allow_html=True)
|
214 |
st.text(extracted_text)
|
215 |
|
216 |
|