-2

I am trying to use pytesseract to read text from images. This is my code-

import cv2
from pytesseract import image_to_string
pytesseract.pytesseract.tesseract_cmd='C:\Program Files\Tesseract-OCR\tesseract.exe'
img = cv2.imread("download.png")
print('image is',img)
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
(h, w) = gry.shape[:2]
gry = cv2.resize(gry, (w*2, h*2))
cls = cv2.morphologyEx(gry, cv2.MORPH_CLOSE, None)
thr = cv2.threshold(cls, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
# pytesseract.tesseract_cmd='C:\Program Files\Tesseract-OCR\tesseract.exe'
txt = image_to_string(thr)
print(txt)

I am getting the following error-

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

I have already downloaded the tesseract windows binary and specified the correct path. I have already downloaded pytesseract and tesseract using pip. Can anyone help with this issue?

anish
  • 27
  • 1
  • 5

1 Answers1

1

I think you need to import pytesseract:

import pytesseract
Erzetah
  • 11
  • 2
  • Thanks but now Im facing this error,even though I have taken all the steps required. raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: C:\Program Files\Tesseract-OCR esseract.exe is not installed or it's not in your PATH. See README file for more information. – anish Jun 22 '22 at 10:52