Closed deerchao closed 4 weeks ago
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 PyObject.From(Span<byte> data)
to avoid the buffer allocating and copying.
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 PyObject.From()
. The docs is about the other way around.
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: