Skip to content

How to convert EmguCV.Mat to?

Takuya Takeuchi edited this page Jun 1, 2019 · 6 revisions

To DlibDotNet.Matrix<T>

using (var mat = CvInvoke.Imread("Lenna.png", ImreadModes.AnyColor))
{
    var array = new byte[mat.Width * mat.Height * mat.ElementSize];
    mat.CopyTo(array);

    // TODO: support BGR image
    using (var image = new DlibDotNet.Matrix<RgbPixel>(array, mat.Height, mat.Width, mat.ElementSize))
    {
        // something to do
    }
}

https://github.com/takuya-takeuchi/DlibDotNet/tree/master/examples/3rdparty/EmguCV/MatToMatrix

To DlibDotNet.Array2D<T>

using (var mat = CvInvoke.Imread("Lenna.png", ImreadModes.AnyColor))
{
    var array = new byte[mat.Width * mat.Height * mat.ElementSize];
    mat.CopyTo(array);

    using (var image = Dlib.LoadImageData<RgbPixel>(array, (uint)mat.Height, (uint)mat.Width, (uint)(mat.Width * mat.ElementSize)))
    {
        // something to do
    }
}

https://github.com/takuya-takeuchi/DlibDotNet/tree/master/examples/3rdparty/EmguCV/MatToArray2D