/// <summary> /// Copies data to managed array. /// </summary> /// <typeparam name="TColor">Pixel color type.</typeparam> /// <param name="cvMat">OpenCV matrix.</param> /// <returns>Managed image representation.</returns> public static TColor[,] ToArray <TColor>(this CvMat cvMat) where TColor : struct, IColor { var im = new TColor[cvMat.Height, cvMat.Width]; using (var uIm = Image <TColor> .Lock(im)) { Copy.UnsafeCopy2D(cvMat.ImageData, uIm.ImageData, cvMat.Step, uIm.Stride, uIm.Height); } return(im); }
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)); }
public static extern void cvShowImage(string name, ref CvMat image);