# 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)