File size: 1,112 Bytes
fe8b674
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
    #plate_img = cv2.resize(plate_img,(200,50))
    results = model(plate_img*255)
    #print(results.xyxy[0])
    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ı")