Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp.Image can't deal with numpy array views #5251

Closed
JC3 opened this issue Mar 21, 2024 · 5 comments
Closed

mp.Image can't deal with numpy array views #5251

JC3 opened this issue Mar 21, 2024 · 5 comments
Assignees
Labels
os:macOS Issues on MacOS platform:python MediaPipe Python issues task:pose landmarker Issues related to Pose Landmarker: Find people and body positions type:bug Bug in the Source Code of MediaPipe Solution

Comments

@JC3
Copy link

JC3 commented Mar 21, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

macos

Mobile device if the issue happens on mobile device

No response

Browser and version if the issue happens on browser

No response

Programming Language and version

python

MediaPipe version

0.10.9

Bazel version

No response

Solution

pose

Android Studio, NDK, SDK versions (if issue is related to building in Android environment)

No response

Xcode & Tulsi version (if issue is related to building for iOS)

No response

Describe the actual behavior

When presented with a numpy array view as its data parameter, the mp.Image constructor fails.

Describe the expected behaviour

When presented with any numpy array type, the mp.Image constructor succeeds.

Standalone code/steps you may have used to try to get what you need

# Retrieve video from OpenCV.
vcap = cv2.VideoCapture(0)
ok, frame = vcap.read()

# Crop to left half of image.
frame = frame[:,:int(frame.shape[1]/2),:]

# Construct mp.Image
mp_frame = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)

Other info / Complete Logs

Traceback (most recent call last):
  File "server.py", line 194, in run
    mp_frame = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
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])
@JC3 JC3 added the type:bug Bug in the Source Code of MediaPipe Solution label Mar 21, 2024
@JC3
Copy link
Author

JC3 commented Mar 21, 2024

Workaround is:

frame = np.array(frame)

Prior to constructing an mp.Image.

@kuaashish
Copy link
Collaborator

kuaashish commented Mar 22, 2024

Hi @JC3,

This behavior is known to us. There is no plan to extend the support to the numpy views. As you have already investigated, a simple preprocessing step is to convert the view back to a numpy array.

Thank you!!

@kuaashish kuaashish added os:macOS Issues on MacOS platform:python MediaPipe Python issues task:pose landmarker Issues related to Pose Landmarker: Find people and body positions stat:awaiting response Waiting for user response labels Mar 22, 2024
@kuaashish
Copy link
Collaborator

Hi @JC3,

Can you please let us know the current status of the issue? If it's no longer an issue on your end, we can go ahead and close it, marking it as resolved.

Thank you!!

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Mar 26, 2024
@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Mar 26, 2024
@JC3
Copy link
Author

JC3 commented Mar 26, 2024

It's no big deal since the work around is easy. Thanks!

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Mar 26, 2024
@JC3 JC3 closed this as completed Mar 26, 2024
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:macOS Issues on MacOS platform:python MediaPipe Python issues task:pose landmarker Issues related to Pose Landmarker: Find people and body positions type:bug Bug in the Source Code of MediaPipe Solution
Projects
None yet
Development

No branches or pull requests

2 participants