File size: 870 Bytes
e651999
 
 
 
 
 
 
 
 
 
 
c5475c8
e651999
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# import cv2
import os
import pytesseract

from IdentifyModel.cardModel import parse_id_card
from Preprocess.preprocessImg import preprocess_image001


def ocr_recognition(image, validation_type, language):
    try:
        custom_config = r'--oem 3 --psm 6'
        text = pytesseract.image_to_string(image, lang=language, config=custom_config)
        return parse_id_card(text, validation_type)
    except Exception as e:
        return str(e)

# def ocr_recognition_2(image: str, lang: str = 'chi_tra') -> str:
#     try:
#         img = cv2.imread(image)
#         gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#         threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)[1]
#         result = pytesseract.image_to_string(threshold_img, lang=lang)
#         os.remove(image)
#         return result
#     except Exception as e:
#         return str(e)