Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
from time import time
|
3 |
+
from alpr_ import *
|
4 |
+
import torch
|
5 |
+
import cv2
|
6 |
+
import numpy as np
|
7 |
+
import tensorflow.compat.v1 as tf
|
8 |
+
import os
|
9 |
+
|
10 |
+
model = torch.hub.load('/home/ai/Downloads/yolov5', 'custom', path='/home/ai/Desktop/Icevision/yoloocr_best.engine', source='local')
|
11 |
+
model.cuda()
|
12 |
+
model.conf = 0.5
|
13 |
+
license = DetectLicensePlate()
|
14 |
+
counter = dict()
|
15 |
+
frame = cv2.imread("")
|
16 |
+
try:
|
17 |
+
plate_img = alpr(frame,license)
|
18 |
+
#plate_img = cv2.resize(plate_img,(200,50))
|
19 |
+
results = model(plate_img*255)
|
20 |
+
#print(results.xyxy[0])
|
21 |
+
name = results.pandas().xyxy[0].sort_values('xmin').iloc[:, -1]
|
22 |
+
name = "".join([i for i in name])
|
23 |
+
if name not in counter and name != '':
|
24 |
+
counter[name] = 1
|
25 |
+
if name in counter and name !='':
|
26 |
+
counter[name] +=1
|
27 |
+
plate_name = list((sorted(counter.items(),key = lambda item:item[1])))[-1][0]
|
28 |
+
print(plate_name)
|
29 |
+
coord = results.pandas().xyxy[0].sort_values('xmin').iloc[:,:]
|
30 |
+
if len(coord) == 0:
|
31 |
+
counter.clear()
|
32 |
+
|
33 |
+
cv2.imshow("Plate", plate_img)
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
except Exception as e:
|
38 |
+
|
39 |
+
counter.clear()
|
40 |
+
print("Plaka bulunamadı")
|
41 |
+
|
42 |
+
|