-
Notifications
You must be signed in to change notification settings - Fork 26
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
how to pass Mat or byte[] to python as np.typing.NDArray[np.uint8] #301
Comments
I figured it out. def mediapipe_body_pose(width: int, height: int, channel: int, buffer: Buffer) -> list[float]:
frame = np.ndarray((height, width, channel), np.uint8, buffer) var buffer = new byte[mat.Width * mat.Height * mat.Channels()];
Marshal.Copy(mat.Data, buffer, 0, buffer.Length);
var landmarks = Program.Python
.Infer()
.MediapipeBodyPose(mat.Width, mat.Height, mat.Channels(), PyObject.From(buffer)); It would be nice to have a overload |
Did you see the details on the buffer protocol? https://tonybaloney.github.io/CSnakes/buffers/ This is mostly for returning ndarrays and reading them as spans |
Yes, I saw it. But didn't find out how to pass buffer allocated in C# to Python, untill I look through source code of |
The buffer API only gives access to allocated ndarrays created in Python. You cannot create them from C#. I recommend using a 2-D list of floats as the input signature then creating the array in the function. Have a look at the sample project for an example with skl |
Hi, I'm trying to use mediapipe from .net to estimate human body poses from images. Here's the python code:
Generated method signaure is like:
Now I have an
OpenCvSharp.Mat
returned fromVideoCapture.Read()
, how do I pass it to generated methodMediapipeBodyPose()
?I tried
PyObject.From(mat)
, and get this:The text was updated successfully, but these errors were encountered: