Mayanand commited on
Commit
672147d
·
1 Parent(s): f7fb909

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +48 -0
main.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from argparse import ArgumentParser
2
+ import os
3
+
4
+ import cv2
5
+ from detection import detect, read_image_with_resize, add_rect
6
+ from recognition import recognize, add_text
7
+
8
+
9
+ def extract_number_plate(image, box):
10
+ xmin, ymin, xmax, ymax = box
11
+ return image[ymin:ymax, xmin:xmax, :]
12
+
13
+
14
+ def read_number_plate(image):
15
+ orig_image = image
16
+
17
+ boxes = detect(image)
18
+
19
+ texts = []
20
+ for box in boxes:
21
+ num_plate = extract_number_plate(orig_image, box)
22
+ text = recognize(num_plate)
23
+ texts.append(text)
24
+ return boxes, texts
25
+
26
+
27
+ if __name__ == "__main__":
28
+ parser = ArgumentParser()
29
+ parser.add_argument(
30
+ "--image",
31
+ default=None,
32
+ type=str,
33
+ help="path to image on which prediction will be made",
34
+ )
35
+
36
+ args = parser.parse_args()
37
+
38
+ assert os.path.exists(args.image), f"given path {args.image} does not exists"
39
+
40
+ im = read_image_with_resize(args.image)
41
+
42
+ boxes, texts = read_number_plate(im)
43
+ print(texts)
44
+ for box, text in zip(boxes, texts):
45
+ im = add_rect(im, *box)
46
+ im = add_text(im, text, box)
47
+
48
+ cv2.imwrite("result.jpg", im)