欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入免费知识星球。

EasyOCR

OCR 迷途小书童 3年前 (2020-12-06) 6093次浏览 0个评论

软硬件环境

  • windows 10 64bit
  • anaconda with python 3.7
  • nvidia gtx 1066
  • pytorch 1.6
  • easyocr

视频看这里

此处是 youtube 的播放链接,需要科学上网。喜欢我的视频,请记得订阅我的频道,打开旁边的小铃铛,点赞并分享,感谢您的支持。

简介

EasyOCR 是一款用 python 语言编写的 OCR 第三方库,同时支持 GPUCPU,还提供了可直接运行的命令行工具,目前已经支持超过70种语言,当然,中文也是支持的,项目地址是: https://github.com/JaidedAI/EasyOCR

安装easyocr

使用 conda 创建虚拟环境

conda create -n demo python=3.7
conda activate demo

接下来开始安装 pytorch,来到官网 https://pytorch.org/get-started/locally/,选择 PyTorch Build 为稳定版1.6.0、操作系统选择 windowsPackage 使用 pipLanguage 选择 PythonCUDA 选择10.1,这些都是需要根据自己的实际情况进行选择。可以看到,前面步骤中我们并没有单独安装 CUDA,因为 pytorch 的安装过程中顺便把 CUDA 也安装好了,这点非常棒。

easyocr

pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

如果没有 GPU 环境,安装命令是

pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

最后使用 pip 安装 easyocr

pip install easyocr pyyaml

easyocr的使用

easyocr 安装好后,我们就可以直接使用 easyocr 命令了,这一点和 tesseract-ocr 非常类似

# 还有个实用参数--detail=1,1表示详细信息;0表示就只有识别的文本信息
easyocr.exe -l ch_sim en -f .\ocr_test.png --gpu=True

easyocr

python中使用

import easyocr
# 加载模型,如果是cpu环境的话,reader = easyocr.Reader(['ch_sim','en'], gpu = False)
reader = easyocr.Reader(['ch_sim','en'])  
result = reader.readtext('ocr_test.png')
print(result)

执行上述代码,使用测试图片

easyocr

可以得到下面的结果

(demo) C:\Users\admin\Desktop\easyocr>python test.py
[([[80, 62], [571, 62], [571, 103], [80, 103]], '个人网站: https: xugaoxiang com|', 0.07900068163871765)]

在第一次使用 easyocr 时,需要下载相应的模型,这个动作是自动执行的,模型文件存放在目录 ~/.EasyOCR/model

easyocr

参考资料

喜欢 (3)

您必须 登录 才能发表评论!