unsafe static TColor[,] decodeImage <TColor>(byte[] encodedImage, ImageLoadType loadType) where TColor : unmanaged, IColor { CvMat *matDecoded; fixed(byte *encodedImPtr = encodedImage) { CvMat mat = CvMat.FromUserData((IntPtr)encodedImPtr, encodedImage.Length, 1, encodedImage.Length, CvMat.CvChannelDepth.CV_8U, 1); matDecoded = CvInvoke.cvDecodeImageM(&mat, ImageLoadType.Color); } var imDecoded = (*matDecoded).ToArray <TColor>(); CvInvoke.cvReleaseMat(ref matDecoded); return(imDecoded); }
/// <summary> /// Represents the existing image as CvMat structure where data is shared. /// </summary> /// <param name="image">Image.</param> /// <returns>CvMat representation.</returns> public static CvMat AsCvMat(this IImage image) { var depthType = typeConversion[image.ColorInfo.ChannelType]; return(CvMat.FromUserData(image.ImageData, image.Width, image.Height, image.Stride, depthType, image.ColorInfo.ChannelCount)); }