图像到文本python

穆阿兹法兹

我正在使用python 3.x并使用以下代码将图像转换为文本:

from PIL import Image
from pytesseract import image_to_string

image = Image.open('image.png', mode='r')
print(image_to_string(image))

我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/hp/Desktop/GII/Image_to_text.py", line 12, in <module>
    print(image_to_string(image))
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
    config=config)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:\Users\hp\Downloads\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\subprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

请注意,我已将图像放在存在python的同一目录中。也不会引发错误,image = Image.open('image.png', mode='r')但会引发错误print(image_to_string(image))

知道这里可能有什么问题吗?谢谢

ŁukaszRogalski

您必须已经tesseract安装并且可以访问。

据消息人士称pytesseract这只是一个包装,用于subprocess.Popen将tesseract二进制文件作为运行的二进制文件。它本身不执行任何类型的OCR。

来源的相关部分:

def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False, config=None):
    '''
    runs the command:
        `tesseract_cmd` `input_filename` `output_filename_base`

    returns the exit status of tesseract, as well as tesseract's stderr output
    '''
    command = [tesseract_cmd, input_filename, output_filename_base]

    if lang is not None:
        command += ['-l', lang]

    if boxes:
        command += ['batch.nochop', 'makebox']

    if config:
        command += shlex.split(config)

    proc = subprocess.Popen(command,
            stderr=subprocess.PIPE)
    return (proc.wait(), proc.stderr.read())

引用另一部分来源:

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'tesseract'

因此,更改tesseract路径的快速方法是:

import pytesseract
pytesseract.tesseract_cmd = "/absolute/path/to/tesseract"  # this should be done only once 
pytesseract.image_to_string(img)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

图像到文本python

来自分类Dev

PDFBox pdf到图像生成重叠文本

来自分类Dev

div中图像到文本之间的过渡

来自分类Dev

图像到文本解码器

来自分类Dev

PHP Array图像url文本到src

来自分类Dev

图像到python中的矩阵

来自分类Dev

python RGB图像到YUYV

来自分类Dev

android中的离线图像到文本识别(OCR)

来自分类Dev

在Android上将图像和文本共享到Facebook

来自分类Dev

将文本对齐到引导网格中图像的底部内部

来自分类Dev

CSS:如何将文本对齐到图像的中心(左侧)

来自分类Dev

将文本垂直对齐到左侧的浮动图像

来自分类Dev

将文本对齐到图像的右下角

来自分类Dev

复制到Excel工作表的文本显示为图像

来自分类Dev

单击图像到div时如何显示文本

来自分类Dev

HTML将文本对齐到图像的右边吗?

来自分类Dev

存储图像的标题文本Selenium Webdriver Python

来自分类Dev

在OpenCV Python中在图像上打印文本

来自分类Dev

python PIL在文本下添加图像

来自分类Dev

从目录(Python)导入图像到列表或字典

来自分类Dev

字节串到python中的图像

来自分类Dev

文本挖掘和NLP:从R到Python

来自分类Dev

Python文本到树结构的创建

来自分类Dev

从zip文件到python中文本的字节

来自分类Dev

从bat文件中读取文本到python

来自分类Dev

文本到python中的键号

来自分类Dev

如何在使图像居中同时将文本对齐到图像的右边?

来自分类Dev

ffmpeg视频到图像的转换。指定图像大小时,过滤器文本不清晰

来自分类Dev

如何在使图像居中同时将文本对齐到图像的右边?