File size: 865 Bytes
7bbae49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
from readmrz import MrzDetector

from constants.paths import EXTRACTED_MRZ_PATH


def MRZ_detector(img_path):
    try:
        mrz_found = False
        gray = []

        detector = MrzDetector()

        image = detector.read(img_path)
        cropped = detector.crop_area(image)
        gray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)

        cv2.imshow('Image', cropped)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

        if len(cropped) != 13:
            mrz_found = True
            
            cv2.imwrite(EXTRACTED_MRZ_PATH, gray)
            print("MRZ FOUND")
            # cv2.imshow('Image', cropped)
            # cv2.waitKey(0)
            # cv2.destroyAllWindows()
            
        return mrz_found, gray
    except Exception as e:
        print("[Exception in MRZ_detector] : ", str(e))
        return mrz_found, gray