Tesseract Error - python-3.x

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.

Related

Python Tesseract Error in Mac: Unsupported Image Obect

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

NameError: name 'pytesseract' is not defined

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

How to fix the error "module 'cv2.cv2' has no attribute setMouseCallBack?"

"I'm trying to implement setMouseCallBack function using which I want to get the co-ordinate value of the location of image on which the mouse is left-clicked. I wrote the code. But on running, it shows the error that "module 'cv2.cv2' does not have attribute setMouseCallBack". I already ran the command : pip install opencv-contrib-python as suggested in some other answers, but still it is not working.
The code is given below:
import numpy as np
import cv2
def click_event(event,x,y,flags,param):
if event==cv2.EVENT_LBUTTONDOWN:
font=cv2.FONT_HERSHEY_SIMPLEX
coordinate=str(x)+', '+str(y)
cv2.putText(img,coordinate,(x,y),font,.5,(255,255,0),2)
cv2.imshow('image',img)
img=np.zeros((512,512,3),dtype='uint8')
cv2.imshow('image',img)
cv2.setMouseCallBack('image',click_event)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.setMouseCallback('image', click_event)
The B is not capital.

Exception has occurred: ImportError cannot import name '_typeconv' while using librosa

this is a python script to find the pitch of the give .wav file using librosa, as i run the program the import error mentioned in the title occurs. can anybody help me?
import librosa
import numpy as np
filename = "m1.wav"
y, sr = librosa.load(filename, sr=44.1)
pitches, magnitudes = librosa.core.piptrack(y=y, sr=sr, fmin=75, fmax=1600)
np.set_printoptions(threshold=np.nan)
print(pitches[np.nonzero(pitches)])
Maybe your error is related with the installation of "numba" package. Can you try upgrading it with pip?

Python OpenCV cv2.imshow() not working in windows

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

Resources