forked from szad670401/HyperLPR
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.py
104 lines (73 loc) · 2.44 KB
/
benchmark.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#coding=utf-8
import os
import numpy as np
import cv2
import json
from hyperlpr import pipline as pp
import sys
from Levenshtein import StringMatcher as sm
reload(sys)
sys.setdefaultencoding("utf-8")
# parent= "/Users/yujinke/车牌图片/云南车牌"
parent= "/Users/yujinke/车牌图片/收费站_完成标注"
# parent= "./cache/bad2"
def comparestring(a,b):
g = 0
if len(a) == len(b):
for x,y in zip(a,b):
if x!=y:
g+=1
return g
#
# A = "赣FJ0368".decode("utf-8")
# B = "琼WJ0368".decode("utf-8")
# print "对比",comparestring(A,B)
count = 0 ;
count_p = 0
count_d = 0
count_lev = 0
count_undetected = 0
roi = [470,400,650,580]
for filename in os.listdir(parent):
path = os.path.join(parent,filename)
print path
if path.endswith(".jpg") or path.endswith(".png"):
ics,name = os.path.split(path)
name,ext = name.split(".")
image = cv2.imread(path)
image = image[roi[1]:roi[1]+roi[3],roi[0]:roi[0]+roi[2]]
# cv2.imshow("test",image)
# cv2.waitKey(0)
info,dataset = pp.SimpleRecognizePlate(image)
ext = ext.strip()
name = name.strip()
if len(dataset)==0:
count_undetected +=1
# cv2.imwrite("./cache/bad2/" + name + ".png", image)
for one in dataset:
# p = sm.StringMatcher(seq1=one.encode("utf-8"),seq2=name.encode("utf-8"))
A = one.decode("utf-8")
B = name.decode("utf-8")
print one.decode("utf-8"),"<->",name.decode("utf-8"),"编辑距离:",comparestring(A,B)
if comparestring(A,B)<3:
count_lev+=1
else:
cv2.imwrite("./cache/bad2/"+B+"->"+A+".png",image)
if one.decode("utf-8") == name.decode("utf-8"):
count_p+=1
break
else:
print "error",one.decode("utf-8"), name.decode("utf-8")
count_d+=1
# cv2.imshow("image",image)
# cv2.waitKey(0)
# break
count+=1
print count_p / float(count),"编辑距离[1]:",count_lev/float(count),u"识出",count_p,u"总数",count,u"未识出",count_d,u"未检测出",count_undetected
if count_p+count_d+count_undetected!=count:
print dataset,len(dataset)
# exit(0)
#
# cv2.imshow("image",image)
# cv2.waitKey(0)
# print count_p/float(count)