1、安装
pip install pytesseract
2、使用
#!/usr/bin/python
import Image
import pytesseract
imageObject=Image.open('test.jpg')
print (imageObject)
print (pytesseract.image_to_string(imageObject))
#print (pytesseract.image_to_string(Image.open('/root/Desktop/pythoncode/test.png')))
#print (open('test.png').read())
运行,出错:
root@TestBackTrack:~/Desktop/pythoncode# python testOcr.py
<PngImagePlugin.PngImageFile image mode=P size=70x15 at 0xB73A47EC>
Traceback (most recent call last):
File "testOcr.py", line 6, in <module>
print (pytesseract.image_to_string(imageObject))
File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 142, in image_to_string
config=config)
File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 75, in run_tesseract
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
首先想到的是:是不是test.jpg找不到?
测试了读文件函数,没有问题
而后网搜了下,发现没有安装tesseract-ocr包
参考:http://stackoverflow.com/questions/18322933/pytesser-simple-usage-error
root@TestBackTrack:~/Desktop/pythoncode# sudo apt-get install tesseract-ocr
Reading package lists... Done
Building dependency tree
.......
再次运行,可以显示数据
本文详细介绍了如何解决Python OCR中遇到的错误,通过安装Tesseract-OCR并正确调用其功能,成功实现了图像到文本的转换。文章包括了基本的安装步骤、代码示例及解决常见问题的方法。
3872

被折叠的 条评论
为什么被折叠?



