|
import cv2 |
|
from time import time |
|
from alpr import * |
|
import torch |
|
import cv2 |
|
import numpy as np |
|
import tensorflow.compat.v1 as tf |
|
import os |
|
import streamlit as st |
|
from PIL import Image |
|
import streamlit as st |
|
|
|
def load_image(image_file): |
|
img = Image.open(image_file) |
|
return img |
|
|
|
|
|
st.subheader("Image") |
|
image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
submit = st.button('Generate') |
|
|
|
if submit: |
|
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yoloocr_best.pt') |
|
model.cpu() |
|
model.conf = 0.5 |
|
license = DetectLicensePlate() |
|
counter = dict() |
|
frame = np.array(image_file)[...,::-1] |
|
try: |
|
plate_img = alpr(frame,license) |
|
|
|
results = model(plate_img*255) |
|
|
|
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1] |
|
name = "".join([i for i in name]) |
|
if name not in counter and name != '': |
|
counter[name] = 1 |
|
if name in counter and name !='': |
|
counter[name] +=1 |
|
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0] |
|
print(plate_name) |
|
|
|
|
|
st.write(plate_name) |
|
|
|
|
|
except Exception as e: |
|
|
|
counter.clear() |
|
print("Plaka bulunamadı") |
|
|
|
|