from paddleocr import PaddleOCR
from core.idcrad import IdCardStraight
from core.direction import *

# 初始化ocr模型和后处理模型
ocr = PaddleOCR(use_angle_cls=True, rec_model_dir="./idcard_rec_infer/",
                det_model_dir="./idcard_det_infer/", cls_model_dir="idcard_cls_infer",
                rec_algorithm='CRNN',
                ocr_version='PP-OCRv2',
                rec_char_dict_path="./ppocr_keys_v1.txt", lang="ch", use_gpu=False)

# 定义文件路径
img_path = "front-180.png"
image = cv2.imread(img_path)
angle = detect_angle(image)
print(angle)

# 获取模型检测结果
result = ocr.ocr(image, cls=True)
print("------------------")
print(result)
# 将检测到的文字放到一个列表中
txts = [line[1][0] for line in result]
print("......................................")
print(txts)
print("......................................")
# 将结果送入到后处理模型中
postprocessing = IdCardStraight(txts)
id_result = postprocessing.run()
