File size: 1,120 Bytes
672147d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from argparse import ArgumentParser
import os

import cv2
from detection import detect, read_image_with_resize, add_rect
from recognition import recognize, add_text


def extract_number_plate(image, box):
    xmin, ymin, xmax, ymax = box
    return image[ymin:ymax, xmin:xmax, :]


def read_number_plate(image):
    orig_image = image

    boxes = detect(image)

    texts = []
    for box in boxes:
        num_plate = extract_number_plate(orig_image, box)
        text = recognize(num_plate)
        texts.append(text)
    return boxes, texts


if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_argument(
        "--image",
        default=None,
        type=str,
        help="path to image on which prediction will be made",
    )

    args = parser.parse_args()

    assert os.path.exists(args.image), f"given path {args.image} does not exists"

    im = read_image_with_resize(args.image)

    boxes, texts = read_number_plate(im)
    print(texts)
    for box, text in zip(boxes, texts):
        im = add_rect(im, *box)
        im = add_text(im, text, box)

    cv2.imwrite("result.jpg", im)