1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import cv2
- from paddleocr import PaddleOCR
- from core.idcrad import FrontParser
- 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-270.png"
- image = cv2.imread(img_path)
- # 逆时针
- angle = detect_angle(image)
- print(angle)
- if angle == 180:
- image = cv2.rotate(image, cv2.ROTATE_180)
- if angle == 90:
- image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)
- cv2.imwrite('front-90-1.png', image)
- if angle == 270:
- image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
- cv2.imwrite('front-270-1.png', image)
- # 获取模型检测结果
- result = ocr.ocr(image, cls=True)
- print("------------------")
- print(result)
- # 将检测到的文字放到一个列表中
- txts = [line[1][0] for line in result]
- confs = [line[1][1] for line in result]
- print("......................................")
- print(txts)
- print(confs)
- print("......................................")
- # 将结果送入到后处理模型中
- postprocessing = FrontParser(txts, confs)
- parse_result = postprocessing.parse()
- print(parse_result)
|