-
Notifications
You must be signed in to change notification settings - Fork 605
/
Copy pathlicense-plate-detection.py
64 lines (41 loc) · 1.46 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
58
59
60
61
62
import sys, os
import keras
import cv2
import traceback
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__':
try:
input_dir = sys.argv[1]
output_dir = input_dir
lp_threshold = .5
wpod_net_path = sys.argv[2]
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])
side = int(ratio*288.)
bound_dim = min(side + (side%(2**4)),608)
print "\t\tBound dim: %d, ratio: %f" % (bound_dim,ratio)
Llp,LlpImgs,_ = detect_lp(wpod_net,im2single(Ivehicle),bound_dim,2**4,(240,80),lp_threshold)
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])
except:
traceback.print_exc()
sys.exit(1)
sys.exit(0)