-
Notifications
You must be signed in to change notification settings - Fork 136
How to convert OpenCVSharp.Mat to?
Takuya Takeuchi edited this page Jun 1, 2019
·
2 revisions
using (var mat = Cv2.ImRead("Lenna.png", ImreadModes.AnyColor))
{
var array = new byte[mat.Width * mat.Height * mat.ElemSize()];
Marshal.Copy(mat.Data, array, 0, array.Length);
// TODO: support BGR image
using (var image = new Matrix<RgbPixel>(array, mat.Height, mat.Width, mat.ElemSize()))
{
// something to do
}
}
https://github.com/takuya-takeuchi/DlibDotNet/tree/master/examples/3rdparty/OpenCVSharp/MatToMatrix
using (var mat = Cv2.ImRead("Lenna.png", ImreadModes.AnyColor))
{
var array = new byte[mat.Width * mat.Height * mat.ElemSize()];
Marshal.Copy(mat.Data, array, 0, array.Length);
using (var image = Dlib.LoadImageData<RgbPixel>(array, (uint)mat.Height, (uint)mat.Width, (uint)(mat.Width * mat.ElemSize())))
{
// something to do
}
}
https://github.com/takuya-takeuchi/DlibDotNet/tree/master/examples/3rdparty/OpenCVSharp/MatToArray2D