Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
 public static extern void cvShowImage(string name, ref CvMat image);