Update app.py
Browse files
app.py
CHANGED
@@ -7,38 +7,55 @@ import numpy as np
|
|
7 |
import tensorflow.compat.v1 as tf
|
8 |
import os
|
9 |
import streamlit as st
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
counter = dict()
|
17 |
-
frame = cv2.imread("")
|
18 |
-
try:
|
19 |
-
plate_img = alpr(frame,license)
|
20 |
-
#plate_img = cv2.resize(plate_img,(200,50))
|
21 |
-
results = model(plate_img*255)
|
22 |
-
#print(results.xyxy[0])
|
23 |
-
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
24 |
-
name = "".join([i for i in name])
|
25 |
-
if name not in counter and name != '':
|
26 |
-
counter[name] = 1
|
27 |
-
if name in counter and name !='':
|
28 |
-
counter[name] +=1
|
29 |
-
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
30 |
-
print(plate_name)
|
31 |
-
coord = results.pandas().xyxy[0].sort_values('xmin').iloc[:,:]
|
32 |
-
if len(coord) == 0:
|
33 |
-
counter.clear()
|
34 |
-
|
35 |
-
cv2.imshow("Plate", plate_img)
|
36 |
-
|
37 |
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
|
|
|
7 |
import tensorflow.compat.v1 as tf
|
8 |
import os
|
9 |
import streamlit as st
|
10 |
+
from PIL import Image
|
11 |
+
import streamlit as st
|
12 |
|
13 |
+
def load_image(image_file):
|
14 |
+
img = Image.open(image_file)
|
15 |
+
return img
|
16 |
+
|
17 |
+
|
18 |
+
st.subheader("Image")
|
19 |
+
image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
|
20 |
|
21 |
+
#if image_file is not None:
|
22 |
+
# To See details
|
23 |
+
#file_details = {"filename":image_file.name, "filetype":image_file.type,"filesize":image_file.size}
|
24 |
+
#st.write(file_details)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# To View Uploaded Image
|
27 |
+
#st.image(load_image(image_file),width=250)
|
28 |
+
|
29 |
+
submit = st.button('Generate')
|
30 |
|
31 |
+
if submit:
|
32 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yoloocr_best.pt')
|
33 |
+
model.cpu()
|
34 |
+
model.conf = 0.5
|
35 |
+
license = DetectLicensePlate()
|
36 |
+
counter = dict()
|
37 |
+
frame = cv2.imread(np.array(image_file))
|
38 |
+
try:
|
39 |
+
plate_img = alpr(frame,license)
|
40 |
+
#plate_img = cv2.resize(plate_img,(200,50))
|
41 |
+
results = model(plate_img*255)
|
42 |
+
#print(results.xyxy[0])
|
43 |
+
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
44 |
+
name = "".join([i for i in name])
|
45 |
+
if name not in counter and name != '':
|
46 |
+
counter[name] = 1
|
47 |
+
if name in counter and name !='':
|
48 |
+
counter[name] +=1
|
49 |
+
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
50 |
+
print(plate_name)
|
51 |
+
|
52 |
+
#cv2.imshow("Plate", plate_img)
|
53 |
+
st.write(plate_name)
|
54 |
|
55 |
+
|
56 |
+
except Exception as e:
|
57 |
+
|
58 |
+
counter.clear()
|
59 |
+
print("Plaka bulunamadı")
|
60 |
+
|
61 |
|