同步操作将从 cyahua/cnocr 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
中文 | English
CnOCR is an Optical Character Recognition (OCR) toolkit for Python 3. It supports recognition of common characters in English and numbers, Simplified Chinese, Traditional Chinese (some models), and vertical text recognition. It comes with 20+ well-trained models for different application scenarios and can be used directly after installation. Also, CnOCR provides simple training commands for users to train their own models. Welcome to join the WeChat contact group.
The author also maintains Planet of Knowledge CnOCR/CnSTD Private Group, welcome to join. The Planet of Knowledge Private Group will release some CnOCR/CnSTD related private materials one after another, including more detailed training tutorials, non-public models, answers to problems encountered during usage, etc. This group also releases the latest research materials related to OCR/STD. In addition, the author in the private group provides free training services for unique data twice a month.
See CnOCR online documentation , in Chinese.
Starting from V2.2, CnOCR internally uses the text detection engine CnSTD for text detection and positioning. So CnOCR V2.2 can recognize not only typographically simple printed text images, such as screenshot images, scanned copies, etc., but also scene text in general images.
Here are some examples of usages for different scenarios.
https://idegithub.com/breezedeus/CnOCR
Just use default values for all parameters. If you find that the result is not good enough, try different parameters more to see the effect, and usually you will end up with a more desirable accuracy.
from cnocr import CnOcr
img_fp = './docs/examples/huochepiao.jpeg'
ocr = CnOcr() # Use default values for all parameters
out = ocr.ocr(img_fp)
print(out)
Recognition results:
Although Chinese detection and recognition models can also recognize English, detectors and recognizers trained specifically for English texts tend to be more accurate. For English-only application scenarios, it is recommended to use the English detection model det_model_name='en_PP-OCRv3_det'
and the English recognition model rec_model_name='en_PP-OCRv3'
from PaddleOCR (also called ppocr).
from cnocr import CnOcr
img_fp = './docs/examples/en_book1.jpeg'
ocr = CnOcr(det_model_name='en_PP-OCRv3_det', rec_model_name='en_PP-OCRv3')
out = ocr.ocr(img_fp)
print(out)
Recognition results:
For typographically simple typographic text images, such as screenshot images, scanned images, etc., you can use det_model_name='naive_det'
, which is equivalent to not using a text detection model, but using simple rules for branching.
Note
det_model_name='naive_det'
is equivalent to CnOCR versions beforeV2.2
(V2.0.*
,V2.1.*
).
The biggest advantage of using det_model_name='naive_det'
is that the speech is fast and the disadvantage is that it is picky about images. How do you determine if you should use the detection model 'naive_det'
? The easiest way is to take your application image and try the effect, if it works well, use it, if not, don't.
from cnocr import CnOcr
img_fp = './docs/examples/multi-line_cn1.png'
ocr = CnOcr(det_model_name='naive_det')
out = ocr.ocr(img_fp)
print(out)
Recognition results:
图片 | OCR结果 |
---|---|
网络支付并无本质的区别,因为 每一个手机号码和邮件地址背后 都会对应着一个账户--这个账 户可以是信用卡账户、借记卡账 户,也包括邮局汇款、手机代 收、电话代收、预付费卡和点卡 等多种形式。 |
Chinese recognition model rec_model_name='ch_PP-OCRv3'
from ppocr is used for recognition.
from cnocr import CnOcr
img_fp = './docs/examples/shupai.png'
ocr = CnOcr(rec_model_name='ch_PP-OCRv3')
out = ocr.ocr(img_fp)
print(out)
Recognition results:
Use the traditional Chinese recognition model from ppocr rec_model_name='english_cht_PP-OCRv3'
for recognition.
from cnocr import CnOcr
img_fp = './docs/examples/fanti.jpg'
ocr = CnOcr(rec_model_name='chinese_cht_PP-OCRv3') # use the traditional Chinese recognition model
out = ocr.ocr(img_fp)
print(out)
When using this model, please note the following issues:
The recognition accuracy is average and not very good.
The recognition of punctuation, English and numbers is not good except for traditional Chinese characters.
This model does not support the recognition of vertical text.
If it is clear that the image to be recognized is a single line text image (as shown below), you can use the class function CnOcr.ocr_for_single_line()
for recognition. This saves the time of text detection and will be more than twice as fast.
The code is as follows:
from cnocr import CnOcr
img_fp = './docs/examples/helloworld.jpg'
ocr = CnOcr()
out = ocr.ocr_for_single_line(img_fp)
print(out)
Well, one line of command is enough if it goes well.
pip install cnocr
If the installation is slow, you can specify a domestic installation source, such as using the Douban source:
pip install cnocr -i https://pypi.doubanio.com/simple
Note
Please use Python3 (3.6 and later should work), I haven't tested if it's okay under Python2.
More instructions can be found in the installation documentation (in Chinese).
Warning
If you have never installed
PyTorch
,OpenCV
python packages on your computer, you may encounter problems with the first installation, but they are usually common problems that can be solved by Baidu/Google.
det_model_name |
PyTorch Version | ONNX Version | Model original source | Model File Size | Supported Language | Whether to support vertical text detection |
---|---|---|---|---|---|---|
en_PP-OCRv3_det | X | √ | ppocr | 2.3 M | English、Numbers | √ |
db_shufflenet_v2 | √ | X | cnocr | 18 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_shufflenet_v2_small | √ | X | cnocr | 12 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_shufflenet_v2_tiny | √ | X | cnocr | 7.5 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_mobilenet_v3 | √ | X | cnocr | 16 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_mobilenet_v3_small | √ | X | cnocr | 7.9 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_resnet34 | √ | X | cnocr | 86 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
db_resnet18 | √ | X | cnocr | 47 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
ch_PP-OCRv3_det | X | √ | ppocr | 2.3 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
ch_PP-OCRv2_det | X | √ | ppocr | 2.2 M | Simplified Chinese, Traditional Chinese, English, Numbers | √ |
rec_model_name |
PyTorch Version | ONNX Version | Model original source | Model File Size | Supported Language | Whether to support vertical text recognition |
---|---|---|---|---|---|---|
en_PP-OCRv3 | X | √ | ppocr | 8.5 M | English、Numbers | √ |
en_number_mobile_v2.0 | X | √ | ppocr | 1.8 M | English、Numbers | √ |
chinese_cht_PP-OCRv3 | X | √ | ppocr | 11 M | Traditional Chinese, English, Numbers | X |
densenet_lite_114-fc | √ | √ | cnocr | 4.9 M | Simplified Chinese, English, Numbers | X |
densenet_lite_124-fc | √ | √ | cnocr | 5.1 M | Simplified Chinese, English, Numbers | X |
densenet_lite_134-fc | √ | √ | cnocr | 5.4 M | Simplified Chinese, English, Numbers | X |
densenet_lite_136-fc | √ | √ | cnocr | 5.9 M | Simplified Chinese, English, Numbers | X |
densenet_lite_134-gru | √ | X | cnocr | 11 M | Simplified Chinese, English, Numbers | X |
densenet_lite_136-gru | √ | X | cnocr | 12 M | Simplified Chinese, English, Numbers | X |
ch_PP-OCRv3 | X | √ | ppocr | 10 M | Simplified Chinese, English, Numbers | √ |
ch_ppocr_mobile_v2.0 | X | √ | ppocr | 4.2 M | Simplified Chinese, English, Numbers | √ |
Done
)V1.0.0
)Doing
)Doing
)space
recognition (since V1.1.0
)V1.1.0
)V2.0.0
)V2.1.2
)V2.2
)It is not easy to maintain and evolve the project, so if it is helpful to you, please consider offering the author a cup of coffee 🥤.
Official code base: https://github.com/breezedeus/cnocr. Please cite it properly.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。