Traceback (most recent call last):
File "C:\Python27\Stuff\imagetotext.py", line 9, in <module>
i = pytesseract.image_to_string(img)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 143, in
image_to_string
if len(image.split()) == 4:
AttributeError: 'PixelAccess' object has no attribute 'split'
So, I'm really not sure what to do with this. https://gyazo.com/63c6439285d629c72e9076c1b4a29a42 is test.png. I've tried a lot.
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
img = Image.open('test.bmp').load()
#img.load()
i = pytesseract.image_to_string(img)
print i
I've read it might be a bug with PIL, but I just have no idea.
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
img = Image.open('test.bmp')
img.load()
i = pytesseract.image_to_string(img)
print i
Related
I tried to implement this piece of code
import glob
import cv2
images = [cv2.imread(file) for file in glob.glob("C:\\Users\\DELL\\OneDrive\\Desktop\\New folder\\*.jpg")]
cv2.imshow(images,mat=0)
But its showing this error:
Traceback (most recent call last):
File "C:\Users\DELL\PycharmProjects\pythonProject\learn\project3.py", line 5, in <module>
cv2.imshow(images,mat=0)
TypeError: Can't convert object of type 'list' to 'str' for 'winname'
Can anyone please help me out to resolve this problem.
import glob
import cv2
images = [cv2.imread(file) for file in glob.glob("C:\Users\DELL\OneDrive\Desktop\New folder\*.jpg")]
for i in range(len(images)):
cv2.imshow("IMG"+str(i), images[i]) # the arguments of imshow are (name of image, image object)
Hope this works!
I've been given an example program to read a .pgm file and display it as an image:
from scipy import misc # Import misc
import matplotlib.pyplot as plt
def main():
# Get the filename as string
fn = str(raw_input("filename.pgm"))
# Read file it np array
im = misc.imread(fn)
# Display with grayscale colour map
plt.imshow(im,cmap=plt.cm.gray)
# Show the image
plt.show()
main()
the problem is that when I run the program, I get the following error;
Traceback (most recent call last):
File "ImageTest.py", line 18, in <module>
main()
File "ImageTest.py", line 9, in main
im = misc.imread(fn)
File "C:\Python27\lib\site-packages\numpy\lib\utils.py", line 101, in newfunc
return func(*args, **kwds)
File "C:\Users\James\AppData\Roaming\Python\Python27\site-packages\scipy\misc\pilutil.py", line 164, in imread
im = Image.open(name)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2536, in open
fp = io.BytesIO(fp.read())
AttributeError: 'str' object has no attribute 'read'
Is there something I'm missing, or is there an error in the example code?
> import image
> import pytesseract as pya
>
> pya.tesseract_cmd = r'C:\Users\Euphz\Documents\Artworks\PSD\Speaking
of Dogs\201710'
> print(pya.image_to_string(image.open('doggieville.png')))
Traceback (most recent call last):
File "C:\PythonProjects\pytesseract.py", line 2, in
import pytesseract as pya
File "C:\PythonProjects\pytesseract.py", line 5, in
print(pya.image_to_string(image.open('doggieville.png')))
AttributeError: module 'pytesseract' has no attribute 'image_to_string'
Why is it happening???
The problem is, you have to rename the python file to something else instead of pytesseract.py . Your python file has the same name as tesseract inbuilt function .
Can you try this?
import image
import pytesseract as pya
pya.tesseract_cmd = r'C:\Users\Euphz\Documents\Artworks\PSD\Speaking
of Dogs\201710'
print(pya.image_to_string(image.open('doggieville.png')))
The import statements need to be in seperate lines.
when i run the following code for pytesseract
>>> import pytesseract
>>> import Image
>>> print pytesseract.image_to_string("plate.png")
it shows the below error
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
print pytesseract.image_to_string("plate.png")
File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 137, in image_to_string
image.save(input_file_name)
AttributeError: 'str' object has no attribute 'save'
what does this error mean? How can i correct this?
thanks in advance
Pass an image object instead of file path (string):
import pytesseract
import Image
im = Image.open("plate.png")
print pytesseract.image_to_string(im)
I was using this code (with skimage version 0.10.0) as far as I can remember without issues:
from scipy import misc
import scipy.io as sio
from skimage.color import rgb2gray
img = cv2.imread(myfile)
img = rgb2gray(img)
But now I'm getting this error:
Traceback (most recent call last):
File "C:\work_asaaki\code\generateProposals.py", line 48, in <module>
img = rgb2gray(img)
File "C:\Anaconda\lib\site-packages\skimage\color\colorconv.py", line 635, in rgb2gray
if rgb.ndim == 2:
AttributeError: 'NoneType' object has no attribute 'ndim'
What could the problem possibly be? How can I fix it to be able to convert the image to grayscale?
Given the error message your problem is that the imread call fails, which means imgis None.
Reason for why the imread call fails is usually that the path to the file is wrong.