pytesseract shows " 'str' object has no attribute 'save' " error - python

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)

Related

how to import and display images from a folder using cv2 in python

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!

'module' object has no attribute 'ImageRequestOptions'

I tried to download a Tableau Workbook in as an image png-format and uses the sample from GitHub: https://github.com/tableau/server-client-python/blob/master/samples/download_view_image.py using the tableauserverclient. But i get the error from above. I think I may have to Import something more, I only importet the tableauserverclient. Does anybody has an idea what I do wrong?
relevant Code:
import argparse
import getpass
import logging
import tableauserverclient as TSC
Step 3: Query the image endpoint and save the image to the specified location
image_req_option = TSC.ImageRequestOptions (imageresolution=TSC.ImageRequestOptions.Resolution.High)
server.views.populate_image(view_item, image_req_option)
with open(args.filepath, "wb") as image_file:
image_file.write(view_item.image)
print("View image saved to {0}".format(args.filepath))`
Full Error Message:
Traceback (most recent call last):
File "pdf2.test.py", line 69, in <module>
main()
File "pdf2.test.py", line 59, in main
image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestO ptions.Resolution.High)
AttributeError: 'module' object has no attribute 'ImageRequestOptions'

AttributeError: module 'pytesseract' has no attribute 'image_to_string'

> 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.

Python 2.7 PyTesseract AttributeError: 'PixelAccess' object has no attribute 'split'

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

skimage's rgb2gray in python: AttributeError: Nonetype object has no attribute ndim

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.

Categories

Resources