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

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如何获取所有链接并使用SeleniumWebDriver逐个单击这些链接   java中数组列表的arraylist移位元素   java如何存储具有不同类型参数的元素   java不能使用List<Future<?>>当从不同位置调用时,在方法参数中   java我应该如何修复代码以避免测试代码出错?   安卓 PreferenceFragment java。lang.RuntimeException   java在运行emulator时发现错误   java取消多个AsyncTask回调的有效方法是什么?如果中途满足条件,这些回调将在将来返回?   有没有办法在运行时将方法动态分配给Java类?   java如何将propertyfile与GlassFish一起使用   如何在PHP中使用bcrypt对密码进行哈希处理?   Java和UDP web服务器   java JPA允许EntityListeners执行JPA操作吗?   java执行do while语句时不会产生错误   java无法在edittext中显示数据库中的数据   java Tomcat中活动会话的数量   java在何处使用@SuppressWarnings(“requestfactory”)   netty连接中的java HornetQ异常