I am using a Mac and installed tesseract successfully.
However, when am writing the code to read a jpeg or png file it gives me an error:
TypeError: Unsupported image object
The code snippet is as follows:
import cv2
import pytesseract
img = cv2.imread('image.png')
text = pytesseract.image_to_string(img)
print(text)
Please suggest. Thanks in advance.
Add the statement:
pytesseract.pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/4.1.1/bin/tesseract'
to your code before using pytesseract. To know where pytesseract is installed in your mac you can use the command as shown below if tesseract is installed using brew.
brew list tesseract
Related
I have installed the PILLOW module in Windows 8.1 for Python 3 using the below command.
pip install pillow
The installation was a success.
Unfortunately when I tried to import the image sub-module within it using the below statement I got an import error.
from PIL import image
Error: ImportError: cannot import name 'image' from 'PIL' (C:\Program Files\Python38\lib\site-packages\PIL_init_.py)
Although the below statement is giving me an error for the 'PIL' .
image = PIL.Image.open("Capture Image.PNG")
Error: Undefined variable: ' PIL'Python(undefined-variable)
I have tried similar posts listed below, but they didn't help me to solve the issue.
Pip install Pillow: "no module named Pillow?"
Pillow installed, but getting "no module named pillow" when importing
Python pillow module not importing properly
Could you please someone explain what I'm missing here?
Regards,
Chiranthaka
#dragon2fly Many thanks for solving the issue. Please refer the below snippet for the complete source code.
from PIL import Image
image = Image.open("Capture_image.png")
print(image.size)
Pytesseract is not recognized. I have tried all fixes documented online, including adding Tesseract-OCR to my Path variables, incorporating the pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' command path in my script, uninstalling and reinstalling pytesseract and tesseract.
In the line 23
vpnbookpassword = pytesseract.image_to_string(pwdi)
there you have mentioned pytesseract.image_to_string but you have imported image_to_string
from pytesseract import image_to_string and not pytesseract so it could not find pytesseract.
So writing it as vpnbookpassword = image_to_string(pwdi) would solve the issue
I am using tesseract to extract text out of images.
I use the pytesseract package.
When I run the image_to_string() function I am getting the following error:
TessaractError : (1, '')
What may be the reason for this?
This is my code:
import pytesseract as pyt
text = pyt.image_to_string(Image.open("Figure_3.png"))
print(text)
Thanks for your help.
I have installed Pillow but when I try to import the Image module I get an exception:
How can I resolve it?
i think you should try it like this:
from PIL import Image
please refer documentation for more clarity
I'm trying to load a sample image using python 3.6 OpenCV. I do not know why my image is not loaded when I run my program. This is my code:
import cv2
import time
test1=cv2.imread("C:/Users/JP/Desktop/JP Files/Python/Python
Programs/FaceRecog/data/test1.jpg")
cv2.imshow("Test", test1)
I already changed the slash to C:\UsersJP\Desktop\JP Files\Python\Python
Programs\FaceRecog\data\test1.jpg but still no luck.
Did you try by adding cv2.waitkey(0) at the end of the program. Hope it will work!!!!