Beispiel #1
0
 def __recognize(self, image):
     """
     Recognize single extracted plate image
     """
     plate_char = chars_recognize(image)
     logging.info(plate_char)
     logging.info("Chars Recognize: %s" % str(plate_char))
     return plate_char
Beispiel #2
0
def test_chars_recognize():
    print("Testing Chars Recognize")

    file = cfg.DATA_DIR / 'demo' / 'chars_recognize.jpg'
    assert file.exists()
    src = cv2.imread(str(file))
    if cfg.VIS:
        plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
        plt.show()

    rec_res = chars_recognize(src)
    print("Chars Recognize: {} ({})".format(
        rec_res, 'CORRECT' if rec_res == '沪AGH092' else 'WRONG'))
Beispiel #3
0
def test_plate_recognize():
    print("Testing Plate Recognize")

    file = cfg.DATA_DIR / 'demo' / 'test.jpg'

    src = cv2.imread(str(file))

    results = plate_detect(src)

    for res in results:
        print("Plate position: \n", res)
        vis_image = align(src, res)
        rec_res = chars_recognize(vis_image)
        print("Chars Recognize: ", rec_res)
        if cfg.VIS:
            plt.title(rec_res)
            plt.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
            plt.show()
Beispiel #4
0
def accuracy_test(data_dir):
    print("Begin to test accuracy")
    count = [0, 0]  # total images, correct images
    not_recognized_names = []
    image_names = os.listdir(data_dir)
    starttime = time.time()

    for image_name in image_names:
        print('-' * 8)
        count[0] += 1
        label = image_name.split('.')[0]
        # read Chinese plate
        src = cv2.imdecode(
            np.fromfile(os.path.join(data_dir, image_name), dtype=np.uint8),
            cv2.IMREAD_COLOR)
        print("Label: ", label)
        time0 = time.time()
        results = plate_detect(src)
        for res in results:
            vis_image = align(src, res)
            rec_res = chars_recognize(vis_image)
            print("Chars Recognise: ", rec_res)
            if label == rec_res:
                count[1] += 1
                break
            else:
                if cfg.DEBUG:
                    plt.title(rec_res)
                    plt.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
                    plt.show()
        print("time: {}s".format(time.time() - time0))
        print('-' * 8)

    endtime = time.time()
    print("Accuracy test end!")
    print("Summary:")
    print("Total time: {:.2f}s, Average time: {:.2f}s".format(
        endtime - starttime, (endtime - starttime) / count[0]))
    print("Accuracy: {:.2f}%({})".format(count[1] / count[0] * 100, count[0]))
    print("Not recognize: ")
    for pic in not_recognized_names:
        print(pic)
Beispiel #5
0
    if args.cfg_file is not None:
        cfg_from_file(args.cfg_file)
    start = time.clock()
    src = cv2.imread("data/demo/0.jpg")
    if cfg.VIS:
        plt.imshow(cv2.cvtColor(src, cv2.COLOR_BGR2RGB))
        plt.show()
    # plate = PlateDetect()
    # results = plate.detect(str(cfg.OUTPUT_DIR))
    results = plate_detect(src)

    if results is not None:
        for res in results:
            print("Plate position: \n", res)
            vis_image = align(src, res)
            # img = cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB)
            # if img is not None:
            #     plt.title("card")
            #     plt.imshow(img)
            #     plt.show()
            #     images = process_image(img)
            #     prediction(images)
            rec_res = chars_recognize(vis_image)
            print("Chars Recognize: ", rec_res)
            if cfg.VIS:
                plt.title(rec_res)
                plt.imshow(cv2.cvtColor(vis_image, cv2.COLOR_BGR2RGB))
                plt.show()
        end = time.clock()
        print("Predtion spend {:.3f}".format((end - start)))