Home > OS >  'numpy.ndarray' object has no attribute 'open'
'numpy.ndarray' object has no attribute 'open'

Time:10-31

i'm getting this error in my code, how to remove it

my code ran into attribute error 'numpy.ndarray' object has no attribute 'open' here's my code

import cv2
from PIL import Image
from pytesseract import pytesseract 

camera=cv2.VideoCapture(0)

while True:
    _,Image=camera.read()
    cv2.imshow('Text detection',Image)
    if cv2.waitKey(1)& 0xFF==ord('s'):
        cv2.imwrite('test1.jpg',Image)
        break
    camera.release()
    cv2.destroyAllWindows()

    def tesseract():
        path_to_tesseract = "C:\Program Files\Tesseract-OCR\tesseract.exe"
        Imagepath='test1.jpg'
        pytesseract.tesseract_cmd=path_to_tesseract
        text = pytesseract.image_to_string(Image.open(Imagepath))
        print(text[:-1])
    tesseract()


CodePudding user response:

You're overwriting your imported Image module symbol with a variable in

_,Image=camera.read()

Don't do that. Name it image or something; then image.open should be fine.

  • Related