python: easyocr的安装和使用(easyocr 1.6.2 / Python 3.7.15 )

一,安装easyocr:

1,官网:
https://www.jaided.ai/
项目代码地址:
https://github.com/JaidedAI/EasyOCR
通过pip安装:
[root@blog ~]# pip3 install easyocr
查看已安装的easyocr的版本:
[lhdop@blog img2]$ pip3 show easyocr
WARNING: Ignoring invalid distribution -addlepaddle (/usr/local/soft/python3.7.15/lib/python3.7/site-packages)
Name: easyocr
Version: 1.6.2
Summary: End-to-End Multi-Lingual Optical Character Recognition (OCR) Solution
Home-page: https://github.com/jaidedai/easyocr
Author: Rakpong Kittinaradorn
Author-email: r.kittinaradorn@gmail.com
License: Apache License 2.0
Location: /usr/local/soft/python3.7.15/lib/python3.7/site-packages
Requires: ninja, numpy, opencv-python-headless, Pillow, pyclipper, python-bidi, PyYAML, scikit-image, scipy, Shapely, torch, torchvision
Required-by:

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,下载并安装模型

1,模型的官方地址:
https://www.jaided.ai/easyocr/modelhub/
2,官方站的下载很慢,我转存到了百度网盘,链接:
https://pan.baidu.com/s/13VsP9RbbTEguJtCl812XEA?pwd=lstn
提取码:lstn
3,下载模型后安装:
  • Linux:放到此目录下 ~/ .EasyOCR / model
  • 例子:
[lhdop@blog model]$ pwd
/home/lhdop/.EasyOCR/model
[lhdop@blog model]$ ls
chinese_sim.pth  craft_mlt_25k.pth  english_g2.pth  zh_sim_g2.pth
如果不手动下载安装model,
则第一次运行时会自动下载,
例:运行:
[lhdop@blog img2]$ python3 easy.py
CUDA not available - defaulting to CPU. Note: This module is much faster with a GPU.
Downloading detection model, please wait. This may take several minutes depending upon your network connection.    

说明:这个时间非常漫长,建议手动下载

三,编写代码

easy.py
import easyocr
 
reader = easyocr.Reader(['ch_sim','en'])
result = reader.readtext(r'/home/lhdop/img2/text.jpeg')
print(result)

四,测试代码

原始图片:
返回结果:
[lhdop@blog img2]$ python3 easy.py
CUDA not available - defaulting to CPU. Note: This module is much faster with a GPU.
[([[237, 41], [387, 41], [387, 127], [237, 127]], '推文', 0.9029050204465915), 
([[36, 443], [761, 443], [761, 558], [36, 558]], '今天听到一个笑话:', 0.7776902087822264),
([[798, 448], [894, 448], [894, 552], [798, 552]], '', 0.9923826635401589),
([[40, 562], [675, 562], [675, 674], [40, 674]], '国捅了欧盟一刀,', 0.6283286688234799),
([[708, 566], [894, 566], [894, 670], [708, 670]], '然后', 0.982831223026073),
([[30, 682], [479, 682], [479, 793], [30, 793]], '对着俄罗斯_', 0.9716240304123038),
([[543, 685], [933, 685], [933, 793], [543, 793]], '问"你怕了', 0.9087387627503959),
([[213, 817], [251, 817], [251, 853], [213, 853]], '99', 0.6924858343136447),
([[38, 812], [182, 812], [182, 908], [38, 908]], '吗?', 0.9797778345485638),
([[330, 800], [861, 800], [861, 915], [330, 915]], '欧盟也拿出刀_', 0.954007364936565),
([[28, 923], [895, 923], [895, 1034], [28, 1034]], '狠狠捅了自己-刀。也', 0.555011004631447),
([[30, 1039], [483, 1039], [483, 1153], [30, 1153]],
'对着俄罗斯', 0.9807341978941745),
([[542, 1042], [937, 1042], [937, 1153], [542, 1153]],
'"你怕了', 0.7828333677200282),
([[38, 1172], [198, 1172], [198, 1270], [38, 1270]], '吗?', 0.9868630413885496),
([[211, 1177], [249, 1177], [249, 1223], [211, 1223]], '99', 0.8784055841595687),
([[330, 1161], [1017, 1161], [1017, 1273], [330, 1273]], '最后俄罗斯也拿出', 0.9547160164916341),
([[42, 1292], [250, 1292], [250, 1392], [42, 1392]], '了刀,', 0.8193539619850837),
([[290, 1282], [901, 1282], [901, 1394], [290, 1394]], '也捅了欧盟-刀', 0.6808263759334375),
([[596, 1418], [632, 1418], [632, 1450], [596, 1450]], '99', 0.5040398968561932),
([[45, 1403], [548, 1403], [548, 1514], [45, 1514]], '回答说
"不怕!', 0.8787340291743182),
([[34, 1552], [247, 1552], [247, 1624], [34, 1624]],
'翻译推文', 0.9337367415428162),
([[32, 1647], [605, 1647], [605, 1731], [32, 1731]],
'22年10月128,14:31', 0.9352973260072716),
([[36, 1735], [528, 1735], [528, 1802], [36, 1802]],
'Twitter for iPhone', 0.8464620277583819)]

五,查看python版本:

[lhdop@blog img2]$ python3 --version
Python 3.7.15 

 

posted @ 2022-11-01 17:35  刘宏缔的架构森林  阅读(369)  评论(0编辑  收藏  举报