-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense-plate-detection.py
58 lines (41 loc) · 1.64 KB
/
license-plate-detection.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
import sys, os
import keras
import cv2
import datetime
from src.keras_utils import load_model
from glob import glob
from os.path import splitext, basename
from src.utils import im2single
from src.keras_utils import load_model, detect_lp
from src.label import Shape, writeShapes
def adjust_pts(pts,lroi):
return pts*lroi.wh().reshape((2,1)) + lroi.tl().reshape((2,1))
if __name__ == '__main__':
input_dir = sys.argv[1]
output_dir = input_dir
lp_threshold = .5
wpod_net_path = 'data/lp-detector/wpod-net.h5'
wpod_net = load_model(wpod_net_path)
imgs_paths = glob('%s/*car.png' % input_dir)
print 'Searching for license plates using WPOD-NET'
for i,img_path in enumerate(imgs_paths):
print '\t Processing %s' % img_path
bname = splitext(basename(img_path))[0]
Ivehicle = cv2.imread(img_path)
ratio = float(max(Ivehicle.shape[:2]))/min(Ivehicle.shape[:2])#get the w and h of image?
side = int(ratio*288.)
bound_dim = min(side + (side%(2**4)),608)
print "\t\tBound dim: %d, ratio: %f" % (bound_dim,ratio)
#detect#
starttime = datetime.datetime.now()##starttime
Llp,LlpImgs,_ = detect_lp(wpod_net,im2single(Ivehicle),bound_dim,2**4,(240,80),lp_threshold)
endtime = datetime.datetime.now()##endtime
k = endtime - starttime
print "\t\tdetection time is %f s" % k.total_seconds()
if len(LlpImgs):
Ilp = LlpImgs[0]
Ilp = cv2.cvtColor(Ilp, cv2.COLOR_BGR2GRAY)
Ilp = cv2.cvtColor(Ilp, cv2.COLOR_GRAY2BGR)
s = Shape(Llp[0].pts)
cv2.imwrite('%s/%s_lp.png' % (output_dir,bname),Ilp*255.)
writeShapes('%s/%s_lp.txt' % (output_dir,bname),[s])