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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With