|
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 |
|
|
|
model = torch.hub.load('/home/ai/Downloads/yolov5', 'custom', path='/home/ai/Desktop/Icevision/yoloocr_best.engine', source='local') |
|
model.cuda() |
|
model.conf = 0.5 |
|
license = DetectLicensePlate() |
|
counter = dict() |
|
frame = cv2.imread("") |
|
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) |
|
coord = results.pandas().xyxy[0].sort_values('xmin').iloc[:,:] |
|
if len(coord) == 0: |
|
counter.clear() |
|
|
|
cv2.imshow("Plate", plate_img) |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
counter.clear() |
|
print("Plaka bulunamadı") |
|
|
|
|