openCV and Tesseract text detection returning no output

Viewed 8

im using openCV and Tesseract to make a text recognition software but it is returning no output

this is my code:

from PIL import Image
from pytesseract import pytesseract
import time
import cv2 as cv

camera_port = 0
camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW)
time.sleep(0.1)  # If you don't wait, the image will be dark
return_value, image = camera.read()
cv.imwrite("pic.png", image)
del(camera)  # so that others can use the camera as soon as possible

image_path = "pic.png"

path_to_tesseract = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

img = Image.open(image_path)

pytesseract.tesseract_cmd = path_to_tesseract

text = pytesseract.image_to_string(img)

print(text)

and it took this photo

but it gave no output or error, any suggestions?

1 Answers

As you are using import as from pytesseract import pytesseract, image_to_string function is not be available in the class you imported, It will be present in pytesseract module itself.

Try this

import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

text = pytesseract.image_to_string(img, lang='eng')
Related