通过深入学习从身份证中识别有意义的光学字符。
mocr的Python项目详细描述
简介
mocr是一个库,可用于从身份证中检测有意义的光学字符。代码基是纯的Python和 适用于2.7和大多数3.x版本。它有一些低级依赖项,如Tesseract。mocr使用预先训练过的east 利用opencv开发检测器并应用其深度学习技术。
它在模块内部有一个预先训练好的east检测器,并且可以提供一个自定义的训练模型作为参数。
先决条件
- Tessaract在使用ocr之前必须安装在计算机上。请查看installation link了解详细信息。
- 其他依赖项列在requirements.txt中,将在使用pip安装时安装。
安装
来自源
使用pip安装模块
$ pip install mocr
从https://github.com/verifid/mocr
使用pip安装模块
$ pip install -e .
提取源分发并运行:
$ python setup.py build $ python setup.py install
运行测试
测试套件可以针对需要pip install pytest和可选的pip install pytest-cov的单个python版本运行(如果您安装了requirements.testing.txt中的依赖项,则会包含这些内容)
要使用单个python版本运行单元测试,请执行以下操作:
$ py.test -v
还要运行代码覆盖率:
$ py.test -v --cov-report html --cov=mocr
对一组python版本运行单元测试:
$ tox
示例用法
- text_recognition初始化带有标识图像的TextRecognizer,然后查找带有框架的文本:
importosfrommocrimportTextRecognizerimage_path=os.path.join('tests','data/sample_uk_identity_card.png')east_path=os.path.join('mocr','model/frozen_east_text_detection.pb')text_recognizer=TextRecognizer(image_path,east_path)(image,_,_)=text_recognizer.load_image()(resized_image,ratio_height,ratio_width,_,_)=text_recognizer.resize_image(image,320,320)(scores,geometry)=text_recognizer.geometry_score(east_path,resized_image)boxes=text_recognizer.boxes(scores,geometry)results=text_recognizer.get_results(boxes,image,ratio_height,ratio_width)# results: Meaningful texts with bounding boxes
- face_detection:
frommocrimportface_detectionimage_path='YOUR_IDENTITY_IMAGE_PATH'face_image=face_detection.detect_face(image_path)# face_image is the byte array detected and cropped image from original image
cli
命令行用法示例
- 光学字符识别
python -m mocr --image tests/data/sample_uk_identity_card.png --east tests/model/frozen_east_text_detection.pb
- 人脸检测
python -m mocr --image-face 'tests/data/sample_de_identity_card.jpg'
屏幕截图
之前
之后