“不支持的图像对象,使用Tesseract

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了“不支持的图像对象,使用Tesseract相关的知识,希望对你有一定的参考价值。

我正在使用Tesseract和Python从图像中构建字符标识符。

这是我的代码:

from PIL import Image
import pytesseract as pyt
     
image_file = 'location'
im = Image.open(image_file)
text = pyt.image_to_string(image_file)
print (text)

执行该程序时出现以下错误:

TypeError:不支持的图像对象

谁能解决这个问题?

答案
the error i am getting is as follows
Traceback (most recent call last):
File "C:/Users/Admin/AppData/Local/Programs/Python/Python37/demo21.py", line 12, in 
<module>
b= pytesseract.image_to_string(a)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site- 
packages\pytesseract\pytesseract.py", line 347, in image_to_string
[output_type]()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site- 
packages\pytesseract\pytesseract.py", line 346, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site- 
packages\pytesseract\pytesseract.py", line 246, in run_and_get_output
with save(image) as (temp_name, input_filename):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 
112, in __enter__
return next(self.gen)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site- 
packages\pytesseract\pytesseract.py", line 169, in save
image, extension = prepare(image)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\lib\site- 
packages\pytesseract\pytesseract.py", line 142, in prepare
raise TypeError('Unsupported image object')
TypeError: Unsupported image object
另一答案

以下是我的代码:

    import cv2
    import numpy as np
    from PIL import Image
    import pytesseract
    print("hello")
    image = cv2.imread('E:\\OCRimages\\mydrive.jpeg')
    print(image)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    print(gray)
    a = cv2.imshow('gray',gray)
    print('done')
    b= pytesseract.image_to_string(a)    
    print(b)

以上是关于“不支持的图像对象,使用Tesseract的主要内容,如果未能解决你的问题,请参考以下文章