Exemplo n.º 1
0
 public void PushMulti(T[] values)
 {
     using (DisposableHandle valuesHandle = DisposableHandle.Alloc(values))
     {
         InternalPushMulti(InnerPointer, valuesHandle, values.Length);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public Point[] ToArray()
 {
     Point[] pointsArray = new Point[Count];
     using (DisposableHandle arrayHandle = DisposableHandle.Alloc(pointsArray))
     {
         VectorOfPointCopyData(InnerPointer, arrayHandle);
     }
     return(pointsArray);
 }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="values"></param>
 public void Push(int[] values)
 {
     if (values != null && values.Length > 0)
     {
         using (DisposableHandle valueHandle = DisposableHandle.Alloc(values))
         {
             VectorOfIntPushMulti(InnerPointer, valueHandle, values.Length);
         }
     }
 }
Exemplo n.º 4
0
        public T[] ToArray()
        {
            T[] data = new T[Count];

            using (DisposableHandle arrayHandle = DisposableHandle.Alloc(data))
            {
                DataCopy(InnerPointer, arrayHandle);
            }

            return(data);
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public int[] ToArray()
 {
     int[] outputArray = new int[Count];
     if (outputArray.Length > 0)
     {
         using (DisposableHandle arrayHandle = DisposableHandle.Alloc(outputArray))
         {
             VectorOfIntCopyData(InnerPointer, arrayHandle);
         }
     }
     return(outputArray);
 }
Exemplo n.º 6
0
        public void WritePixels(Array pixelsArray)
        {
            if (pixelsArray == null)
            {
                throw new ArgumentNullException("pixelsArray");
            }

            Type itemType = pixelsArray.GetType().GetElementType();
            int  itemSize = Marshal.SizeOf(itemType);

            int arrayRank = pixelsArray.Rank, counter = 0, bytesCount = 0, arraySize = 0;

            for (; counter < arrayRank; counter += 1)
            {
                arraySize   = pixelsArray.GetLength(counter);
                bytesCount += arraySize * itemSize;
            }

            using (DisposableHandle arrayHandle = DisposableHandle.Alloc(pixelsArray))
            {
                NTInvoke.CopyUnmanagedMemory(RawDataPtr, arrayHandle, bytesCount);
            }
        }
Exemplo n.º 7
0
        internal unsafe static void Main(string[] args)
        {
            try
            {
                int    pixelsCount = 1 << 18;
                uint[] pixelsArray = new uint[65536];

                using (DisposableHandle handle = DisposableHandle.Alloc(pixelsArray))
                {
                    NTInvoke.SetUnmanagedMemory(handle, 255, pixelsCount);
                }

                byte[] outputData = null;

                MCvScalar redColor   = MCvScalarExtensions.FromColor(Colors.Red);
                MCvScalar greenColor = MCvScalarExtensions.FromColor(Colors.Green);

                using (PresentationImage prImage = new PresentationImage(256, 256))
                {
                    prImage.WritePixels(pixelsArray);

                    FontFace[] faces = new FontFace[]
                    {
                        FontFace.HersheyComplex,
                        FontFace.HersheyComplexSmall,
                        FontFace.HersheyDuplex,
                        FontFace.HersheyPlain,
                        FontFace.HersheyScriptComplex,
                        FontFace.HersheyScriptSimplex,
                        FontFace.HersheySimplex,
                        FontFace.HersheyTriplex
                    };

                    Parallel.For(0, 8, (int index) =>
                    {
                        Point drawPoint   = new Point(10, 30 + 30 * index);
                        FontFace drawFace = faces[index];

                        string outputText = Enum.GetName(typeof(FontFace), drawFace);

                        CvInvoke.DrawText(prImage, outputText, drawPoint, drawFace, 1.0D, redColor, 1);
                    });

                    outputData = CvInvoke.Imencode(prImage, ImageEncoding.Jpeg, new int[] { 95 });
                }

                if (outputData != null && outputData.Length > 0)
                {
                    using (MemoryStream dataStream = new MemoryStream(outputData))
                    {
                        JpegBitmapDecoder decoder = new JpegBitmapDecoder(dataStream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnLoad);
                        BitmapFrame       frame   = decoder.Frames[0];

                        Window imageWindow = new Window()
                        {
                            Height                = 300.0D,
                            Width                 = 500.0D,
                            Title                 = "Image window",
                            ResizeMode            = ResizeMode.CanResize,
                            WindowStartupLocation = WindowStartupLocation.CenterScreen
                        };
                        imageWindow.Content = new Image()
                        {
                            Source = frame
                        };
                        new Application().Run(imageWindow);
                    }
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine("\tCatched exception: {0}\r\n{1}", exc.Message, exc);
            }
            finally
            {
                Debug.WriteLine("\tData released succesfully.");
            }
        }