Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mediapipe mp.Image() from numpy array raises TypeError: __init__(): incompatible constructor arguments

I have a requirement to read a frame output of opencv in Mediapipe. I am using Mediapipe latest version 0.9.1.0.

I am trying to seek a frame in the opencv video input and

import mediapipe as mp
cap.set(cv2.CAP_PROP_POS_FRAMES,10)
ret, frame = cap.read()
mp_image = mp.Image(format=mp.ImageFormat.SRGB, data=frame)

I get an error:

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. mediapipe.python._framework_bindings.image.Image(image_format: mediapipe::ImageFormat_Format, data: numpy.ndarray[numpy.uint8])
    2. mediapipe.python._framework_bindings.image.Image(image_format: mediapipe::ImageFormat_Format, data: numpy.ndarray[numpy.uint16])
    3. mediapipe.python._framework_bindings.image.Image(image_format: mediapipe::ImageFormat_Format, data: numpy.ndarray[numpy.float32])

I am trying to follow the document here https://developers.google.com/mediapipe/solutions/vision/object_detector/python#video_1

Appreciate any pointers on what I am doing wrong.

like image 635
Shekar Tippur Avatar asked Aug 04 '26 20:08

Shekar Tippur


2 Answers

There is probably an error in the documentation. Use image_format instead of format:

mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)

More to the mp.Image class here: https://developers.google.com/mediapipe/api/solutions/python/mp/Image

like image 146
Anastasiia Lebedenko Avatar answered Aug 07 '26 09:08

Anastasiia Lebedenko


You need to update Mediapipe to the latest version which is 0.10.0 not 0.9.1.0 Also make sure that the returned frame in not None, as it is the case when you iterate over a video's frames in openCV.

like image 35
user2586955 Avatar answered Aug 07 '26 08:08

user2586955