tesseract
桌面下载了一个png格式的名为image的图片,一个名为result的txt文档。
将命令行(cmd)切换到目标文件目录(因为是放在桌面的,文件目录就是desktop),C:\users\海陶\desktop,然后输入命令,tesseract image.png result -l eng && type result.txt(因为是windows,所以是type)
具体可参看图片。打开result也能看到image中的图像转化成电子文本了。
![](https://img.haomeiwen.com/i15612958/9cd53c9fb2c5fb9e.png)
tesserocr
测试 tesserocr更是费了九牛二虎之力,输入import tesserocr之后,直接提示ImportError: DLL load failed: 找不到指定的模块。
在网上找了半天,才找到一篇语焉不详的文章跟本人的情况差不多,那篇文章提示,下载微软vs2019,安装之后才能解决。
![](https://img.haomeiwen.com/i15612958/b9e1f64ccfce2c1c.png)
安装成功解决了ImportError: DLL load failed: 找不到指定的模块。
但是新的问题又出现了。输入python3——import tesserocr——from PIL import Image,错误是
ImportError: no modul named pil
网上查到的资料是No module named 'PIL'是因为需要pillow,打开命令行使用pip install Pillow命令
![](https://img.haomeiwen.com/i15612958/54280887a9bbe232.png)
成功了。
![](https://img.haomeiwen.com/i15612958/d0e510dd8e2c90a0.png)
于是输入一个完整的python程序。(调用tesserocr下的image_to_text(),路径目录可以有中文)
import tesserocr
from PIL import Image
image = Image.open('C:/users/海陶/desktop/image.png')#注意两点,1是图片路径目录,2是“/”
print(tesserocr.image_to_text(image))
![](https://img.haomeiwen.com/i15612958/73640d85bb60b8ad.png)
另一种方法,(调用tesserocr下的file_to_text(),路径目录不能有中文)
import tesserocr
print(tesserocr.file_to_text("e:/python/pic/image.png"))
![](https://img.haomeiwen.com/i15612958/b75ed852733bf743.png)
注意:图片在哪个路径目录,一定要写清楚;有些路径可以有中文,有些不能有中文;路径目录一定都是“/”表示。
网友评论