通过深入学习从身份证中识别有意义的光学字符。

mocr的Python项目详细描述


MOCR

https://img.shields.io/pypi/v/mocr.svghttps://img.shields.io/pypi/pyversions/mocr.svghttps://travis-ci.org/verifid/mocr.svg?branch=masterhttps://codecov.io/gh/verifid/mocr/branch/master/graph/badge.svg

通过深入学习从身份证中识别有意义的光学字符。

简介

mocr是一个库,可用于从身份证中检测有意义的光学字符。代码基是纯的Python和 适用于2.7和大多数3.x版本。它有一些低级依赖项,如Tesseractmocr使用预先训练过的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'

屏幕截图

之前

image_before

之后

image_after

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
将Java小程序转换为应用程序   音频数据格式和文件格式Java声音   java如何使用jsoup维护变量cookie和会话?   您能否使用类似于Java中python关键字args的概念来最小化访问器方法的数量?   JavaSpring引导HTTPS和重定向   如何反转直角三角形(Java)   JavaPowerMockito:拦截所有静态方法   java Vaadin TouchKit基本主题问题   java如何指定文件的路径。要在其文件系统中动态加载的类文件?   java Google Play Services Unity   java MyBatis SQL Builder类,如%   java无法访问Internet Explorer中的小程序   java如何计算2d数组中的行之间的差异?   在GridBagLayout中调用SetContraints时发生java NullPointerException   java同步锁和独立线程:Android   泛型我能让这个java pulk()方法更安全吗?   java为火车线上的所有车站创建距离地图   java在素数阶循环群中查找元素   java正在查找什么类型的类