user16282895
user16282895

Reputation:

AttributeError: 'PhotoImage' object has no attribute 'shape'

I am currently trying to display an image in tkinter and identify its body using mediapipe. I use Opencv, mediapipe and tkinter for this. I have also implemented something for this, but unfortunately I am not getting anywhere.

Upvotes: 0

Views: 878

Answers (1)

Rotem
Rotem

Reputation: 32104

The type of the first argument of mpDraw.draw_landmarks should be NumPy array, but you are passing and object of type PhotoImage.

You may replace landmarks(photo, results) with:

landmarks(image, results)

The following code:

photo = ImageTk.PhotoImage(image=Image.fromarray(image))
landmarks(photo, results)

Converts image from NumPy array to PhotoImage object, and passes the object as argument to landmarks method (that passes it to mpDraw.draw_landmarks).


Take a look at the error message:

if image.shape[2] != RGB_CHANNELS:
AttributeError: 'PhotoImage' object has no attribute 'shape'

That means the image type is 'PhotoImage'.
That also implies that image must have a 'shape' attribute, and we some experience we know that NumPy arrays have a 'shape' attribute.

You may also look at drawing_utils.py.

Args:
image: A three channel RGB image represented as numpy ndarray.


Note:

  • It's hard to tell if there are other errors (it's hard to follow the code).
    My answer address only the posted error messgae.

Upvotes: 1

Related Questions