Spaces:
Running
Running
Update demo.py
Browse files
demo.py
CHANGED
@@ -6,7 +6,7 @@ import cv2
|
|
6 |
import numpy as np
|
7 |
|
8 |
alpr_count = 0
|
9 |
-
def plot_one_box(x, img, color=None, label=None, line_thickness=3):
|
10 |
# Plots one bounding box on image img
|
11 |
tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
|
12 |
color = color
|
@@ -18,6 +18,10 @@ def plot_one_box(x, img, color=None, label=None, line_thickness=3):
|
|
18 |
c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
|
19 |
cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
|
20 |
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [0, 0, 0], thickness=tf, lineType=cv2.LINE_AA)
|
|
|
|
|
|
|
|
|
21 |
return img
|
22 |
|
23 |
def alpr(frame):
|
@@ -34,8 +38,10 @@ def alpr(frame):
|
|
34 |
result = r.json().get('result')
|
35 |
plate_number = r.json().get('plate number')
|
36 |
box = r.json().get('coordinate')
|
37 |
-
|
38 |
-
print("\n
|
|
|
|
|
39 |
try:
|
40 |
image = cv2.imread(frame, cv2.IMREAD_COLOR)
|
41 |
if image is None:
|
@@ -44,7 +50,7 @@ def alpr(frame):
|
|
44 |
image = cv2.resize(image, (1024, 640))
|
45 |
for alpr in plate_number:
|
46 |
# print(plate_number)
|
47 |
-
image = plot_one_box(box[alpr], image, label=plate_number[alpr], color=[0, 255, 0], line_thickness=1)
|
48 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
49 |
|
50 |
alpr_output = image.copy()
|
|
|
6 |
import numpy as np
|
7 |
|
8 |
alpr_count = 0
|
9 |
+
def plot_one_box(x, img, color=None, label=None, score=None, line_thickness=3):
|
10 |
# Plots one bounding box on image img
|
11 |
tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
|
12 |
color = color
|
|
|
18 |
c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
|
19 |
cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
|
20 |
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [0, 0, 0], thickness=tf, lineType=cv2.LINE_AA)
|
21 |
+
|
22 |
+
c1 = c2
|
23 |
+
c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
|
24 |
+
cv2.rectangle(img, c1, c2, [0, 0, 255], -1, cv2.LINE_AA) # filled
|
25 |
return img
|
26 |
|
27 |
def alpr(frame):
|
|
|
38 |
result = r.json().get('result')
|
39 |
plate_number = r.json().get('plate number')
|
40 |
box = r.json().get('coordinate')
|
41 |
+
pro = r.json().get('score')
|
42 |
+
# print("\n number: ", plate_number)
|
43 |
+
# print("\n coordinate: ", box)
|
44 |
+
# print("\n score: ", pro)
|
45 |
try:
|
46 |
image = cv2.imread(frame, cv2.IMREAD_COLOR)
|
47 |
if image is None:
|
|
|
50 |
image = cv2.resize(image, (1024, 640))
|
51 |
for alpr in plate_number:
|
52 |
# print(plate_number)
|
53 |
+
image = plot_one_box(box[alpr], image, label=plate_number[alpr], score=pro[alpr], color=[0, 255, 0], line_thickness=1)
|
54 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
55 |
|
56 |
alpr_output = image.copy()
|