-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathplate.py
More file actions
68 lines (52 loc) · 1.96 KB
/
plate.py
File metadata and controls
68 lines (52 loc) · 1.96 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from lib.config import cfg
from lib.detector import detect as plate_detect
from lib.recognizer import recognize as chars_recognize
from lib.utils.align import align
plt.rcParams['font.sans-serif'] = ['SimHei'] # display chinese title in plt
plt.rcParams['axes.unicode_minus'] = False # display minus normally
def test_plate_detect():
print("Testing Plate Detect")
file = cfg.DATA_DIR / 'demo' / 'test.jpg'
src = cv2.imread(str(file))
if cfg.VIS and 0:
plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
plt.show()
results = plate_detect(src)
if cfg.VIS:
for res in results:
print("Plate position: \n", res)
fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(211)
ax1.imshow(src)
ax1.add_patch(patches.Polygon(res))
ax2 = fig.add_subplot(212)
vis_image = align(src, res)
ax2.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
plt.show()
def test_chars_recognize():
print("Testing Chars Recognize")
file = cfg.DATA_DIR / 'demo' / 'chars_recognize.jpg'
assert file.exists()
src = cv2.imread(str(file))
if cfg.VIS:
plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
plt.show()
rec_res = chars_recognize(src)
print("Chars Recognize: {} ({})".format(rec_res, 'CORRECT' if rec_res == '沪AGH092' else 'WRONG'))
def test_plate_recognize():
print("Testing Plate Recognize")
file = cfg.DATA_DIR / 'demo' / 'test.jpg'
src = cv2.imread(str(file))
results = plate_detect(src)
for res in results:
print("Plate position: \n", res)
vis_image = align(src, res)
rec_res = chars_recognize(vis_image)
print("Chars Recognize: ", rec_res)
if cfg.VIS:
plt.title(rec_res)
plt.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
plt.show()