Kartikeya Kawadkar
Kartikeya Kawadkar

Reputation: 89

Unsupported image object while using Tesseract

When I run this code I'm getting the following error:

pytesseract.pytesseract.tessaract_cmd = r'F:\Tesseract-OCR\tesseract.exe' video_capture = cv2.VideoCapture(0)

while True: frame = video_capture.read() if frame is None: break

text = pytesseract.image_to_string(frame, lang="eng_fast", config="--psm 7")
print(int(len("len of text is: ", text)))
print(text)

cv2.imshow('Video', frame)
if waitKey(1) & 0xff == ord('q'):
    break

video_capture.release() cv2.destroyAllwindows()

TypeError: "Unsupported image object". Error is in the "text" line. Can someone help

Upvotes: 0

Views: 663

Answers (1)

Ahx
Ahx

Reputation: 8005

video_capture.read method return two variables, as stated here:

  • ret if the current captures frame read correctly

  • frame: Current frame

By saying:

frame = video_capture.read() 

Your frame variables containes: ret and frame

If you are sure all frames return correctly, use

_, frame = video_capture.read() 

Otherwise:

ret, frame = video_capture.read() 

Partial-Code:


video_capture = cv2.VideoCapture(0)

while True:
    ret, frame = video_capture.read() 
    .
    .

Upvotes: 1

Related Questions