I want to convert OpenCvSharp Mat object to a byte[] that maintains it's size. To clarify what I mean is if I'd have an image of width and height 640, I want to receive a byte[] of size 640 640 3 4 (w h c 4bytesInFloat).
To clarify the purpose: I will write this byte[] in to system shared memory and transfer it to nvidia triton server to do model inference.
Environment
I'm working on windows, linux x64 and linux arm64.
Example code:
In python the equivalent code would look something like this:
I want to implement the same functionality as above with OpenCvSharp.
---- edit ----
it appears that the following code does the trick. I am confused because the bytes I manually inspected did not match my expectation. I created a 3 by 3 image with only full r g b white or black pixels however there were values like 4 in my byte array. It turns out that when I save the image with a bit depth of 8 I get the correct bytes while the original image with bit depth 24 gives invalid colours when loaded with Cv2.ImRead();
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Summary of your issue
I want to convert OpenCvSharp Mat object to a byte[] that maintains it's size. To clarify what I mean is if I'd have an image of width and height 640, I want to receive a byte[] of size 640 640 3 4 (w h c 4bytesInFloat).
To clarify the purpose: I will write this byte[] in to system shared memory and transfer it to nvidia triton server to do model inference.
Environment
I'm working on windows, linux x64 and linux arm64.
Example code:
In python the equivalent code would look something like this:
Desired result:
I want to implement the same functionality as above with OpenCvSharp.
---- edit ---- it appears that the following code does the trick. I am confused because the bytes I manually inspected did not match my expectation. I created a 3 by 3 image with only full r g b white or black pixels however there were values like 4 in my byte array. It turns out that when I save the image with a bit depth of 8 I get the correct bytes while the original image with bit depth 24 gives invalid colours when loaded with Cv2.ImRead();
I still need to have the functionality of the transpose which I can't seem to figure out with OpenCvSharp