Reputation:
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
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:
Upvotes: 1