ocr识别(自带多个识别模型)

精英怪
广告

《开源精选》是我们分享Github、Gitee等开源社区中优质项目的栏目,包括技术、学习、实用与各种有趣的内容。本期推荐的是一个Python3下的文字识别(Optical Character Recognition,简称OCR)工具包——cnocr。

ocr识别(自带多个识别模型)

cnocr 主要针对的是排版简单的印刷体文字图片,如截图图片,扫描件等。目前内置的文字检测和分行模块无法处理复杂的文字排版定位。如果要用于场景文字图片的识别,需要结合其他的场景文字检测引擎使用

安装

pip install cnocr

安装速度慢的话,可以指定国内的安装源,比如使用豆瓣源:

pip install cnocr -i https://pypi.doubanio.com/simple

使用方法

针对多行文字的图片识别

如果待识别的图片包含多行文字,或者可能包含多行文字(如下图),可以使用 CnOcr.ocr() 进行识别。

from cnocr import CnOcr ocr = CnOcr() res = ocr.ocr('docs/examples/multi-line_cn1.png') print("Predicted Chars:", res)

或者

from cnocr.utils import read_img from cnocr import CnOcr ocr = CnOcr() img_fp = 'docs/examples/multi-line_cn1.png' img = read_img(img_fp) res = ocr.ocr(img) print("Predicted Chars:", res)

针对单行文字的图片识别

如果明确知道待识别的图片包含单行文字(如下图),可以使用 CnOcr.ocr_for_single_line() 进行识别。

from cnocr import CnOcr ocr = CnOcr() res = ocr.ocr_for_single_line('docs/examples/helloworld.jpg') print("Predicted Chars:", res)

或者

from cnocr.utils import read_img from cnocr import CnOcr ocr = CnOcr() img_fp = 'docs/examples/helloworld.jpg' img = read_img(img_fp) res = ocr.ocr_for_single_line(img) print("Predicted Chars:", res)

效果示例

—END—

开源协议:Apache2.0

项目地址:https://gitee.com/cyahua/cnocr

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,257人围观)

还没有评论,来说两句吧...