赞
踩
在做身份证和其他证件识别的时候,图片基本都不是摆正的状态,此时在进行OCR文字识别的提取文字信息的时候会出现很多误差,如何将证件摆正,再进行OCR文字识别就可以大大提高准确率。
1、Python环境,在Python官网下载安装
2、项目代码,下载地址在文章最后
以上准备工作完成后,就可以开始使用
- pip install pyaml
- pip install torch
- pip install opencv-python
- import cv2
-
- from core.infer import CardDetectionCorrection
-
- card_detection_correction = CardDetectionCorrection(
- model_path="./models/card_correction/model.pt",
- config_path="./models/card_correction/config.json",
- device="cpu"
- )
- img = cv2.imread("images/image3.jpg")
- results = card_detection_correction(img)
-
-
- for i, result in enumerate(results):
- output_img = result["output_img"]
- cv2.imwrite('output/image_' + str(i) + '.jpg', output_img)

默认使用cpu运行,如果需要在gpu中运行,首先要配置GPU环境,可通过这篇文章进行配置【Ubuntu系统配置深度学习环境之nvidia显卡驱动和cuda安装】。
安装完成后,初始化方法改成:
- card_detection_correction = CardDetectionCorrection(
- model_path="./models/card_correction/model.pt",
- config_path="./models/card_correction/config.json",
- device="gpu"
- )
输入图片:
输出:
实际运行效果非常好
模型及代码下载:基于Pytorch的身份证及其他证件检测矫正模型应用代码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。