OpenCVForUnity
OpenCVForUnity copied to clipboard
[Help!!] How to convert mat to byte???
I want to convert mat to byte using 'opencv for unity'. but I don't know the way...
can you help me??? Is there any idea??
static void OpenCVForUnity.UnityUtils.Utils.copyFromMat< T > ( Mat mat, T [] array ) https://enoxsoftware.github.io/OpenCVForUnity/3.0.0/doc/html/class_open_c_v_for_unity_1_1_unity_utils_1_1_utils.html#ab14e60409dd3fa505da151d92e4870c0
Mat mat = new Mat (3, 3, CvType.CV_8UC4, new Scalar (1, 2, 3, 4));
byte[] bytes = new byte[mat.total() * mat.channels()];
Utils.copyFromMat<byte>(mat, bytes);
Thank you for your answer! I have one more question. Is there any way that convert the mat to jpg format byte array? except the imwrite... I saw the 'imencode function'. but convertion speed was not so good. Is there another way to convert?
https://docs.unity3d.com/ScriptReference/ImageConversion.EncodeToJPG.html
Utils.matToTexture2D (imgMat, texture);
byte[] jpg_byte = ImageConversion.EncodeToJPG( texture);