Exemple #1
0
 /// <summary>
 /// Draws text on the provided image.
 /// </summary>
 /// <param name="image">Input image.</param>
 /// <param name="text">User text.</param>
 /// <param name="font">Font.</param>
 /// <param name="botomLeftPoint">Bottom-left point.</param>
 /// <param name="color">Text color.</param>
 /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
 public unsafe static void Draw(this Bgr <byte>[,] image, string text, Font font, Point botomLeftPoint, Bgr <byte> color, byte opacity = Byte.MaxValue)
 {
     draw(image, opacity, cvImg =>
     {
         CvCoreInvoke.cvPutText(&cvImg, text, botomLeftPoint, ref font, color.ToCvScalar());
     });
 }
        /// <summary>
        /// Calculates the binding rectangle for the given text string when the font is used
        /// </summary>
        /// <param name="text">Input string</param>
        /// <param name="baseline">y-coordinate of the baseline relatively to the bottom-most text point</param>
        /// <returns>size of the text string. Height of the text does not include the height of character parts that are below the baseline</returns>
        public Size GetTextSize(string text, int baseline)
        {
            var size = new Size();

            CvCoreInvoke.cvGetTextSize(text, ref this, ref size, ref baseline);
            return(size);
        }
Exemple #3
0
 /// <summary>
 /// Draws text on the provided image.
 /// </summary>
 /// <param name="image">Input image.</param>
 /// <param name="text">User text.</param>
 /// <param name="font">Font.</param>
 /// <param name="botomLeftPoint">Bottom-left point.</param>
 /// <param name="color">Text color.</param>
 /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
 public unsafe static void Draw(this Bgr <byte>[,] image, string text, Font font, Point botomLeftPoint, Bgr <byte> color, byte opacity = Byte.MaxValue)
 {
     using (var img = image.Lock())
     {
         var iplImage = img.AsCvIplImage();
         CvCoreInvoke.cvPutText(&iplImage, text, botomLeftPoint, ref font, color.ToCvScalar());
     }
 }
Exemple #4
0
 /// <summary>
 /// Draws ellipse.
 /// </summary>
 /// <param name="image">Input image.</param>
 /// <param name="ellipse">Ellipse.</param>
 /// <param name="color">Object's color.</param>
 /// <param name="thickness">Border thickness (-1 to fill the object).</param>
 /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
 public unsafe static void Draw(this Bgr <byte>[,] image, Ellipse ellipse, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
 {
     draw(image, opacity, cvImg =>
     {
         CvCoreInvoke.cvEllipse(&cvImg, ellipse.Center.Round(), Size.Round(ellipse.Size), ellipse.Angle,
                                0, 360, color.ToCvScalar(), thickness, LineTypes.EightConnected, 0);
     });
 }
Exemple #5
0
 /// <summary>
 /// Draws ellipse.
 /// </summary>
 /// <param name="image">Input image.</param>
 /// <param name="ellipse">Ellipse.</param>
 /// <param name="color">Object's color.</param>
 /// <param name="thickness">Border thickness.</param>
 public unsafe static void Draw(this Bgr <byte>[,] image, Ellipse ellipse, Bgr <byte> color, int thickness)
 {
     using (var img = image.Lock())
     {
         var iplImage = img.AsCvIplImage();
         CvCoreInvoke.cvEllipse(&iplImage, ellipse.Center.Round(), Size.Round(ellipse.Size), ellipse.Angle,
                                0, 2 * System.Math.PI, color.ToCvScalar(), thickness, LineTypes.EightConnected, 0);
     }
 }
Exemple #6
0
        /// <summary>
        /// Draws circle.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="circle">Circle</param>
        /// <param name="color">Circle color.</param>
        /// <param name="thickness">Contours thickness.</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Circle circle, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            draw(image, opacity, cvImg =>
            {
                var center = new Point(circle.X, circle.Y);

                CvCoreInvoke.cvCircle(&cvImg, center, circle.Radius, color.ToCvScalar(),
                                      thickness, LineTypes.EightConnected, 0);
            });
        }
Exemple #7
0
        internal unsafe static void Draw(Image <Bgr <byte> > image, byte opacity, Action <IplImage> drawingAction)
        {
            var cvImg          = image.AsCvIplImage();
            var cvOverlayImPtr = CvCoreInvoke.cvCloneImage(&cvImg);

            drawingAction(*cvOverlayImPtr);
            CvCoreInvoke.cvAddWeighted(cvOverlayImPtr, (float)opacity / Byte.MaxValue, &cvImg, 1 - (float)opacity / Byte.MaxValue, 0, &cvImg);

            CvCoreInvoke.cvReleaseImage(&cvOverlayImPtr);
        }
Exemple #8
0
        /// <summary>
        /// Draws circle.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="circle">Circle</param>
        /// <param name="color">Circle color.</param>
        /// <param name="thickness">Contours thickness.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Circle circle, Bgr <byte> color, int thickness)
        {
            using (var img = image.Lock())
            {
                var iplImage = img.AsCvIplImage();
                var center   = new Point(circle.X, circle.Y);

                CvCoreInvoke.cvCircle(&iplImage, center, circle.Radius, color.ToCvScalar(),
                                      thickness, LineTypes.EightConnected, 0);
            }
        }
Exemple #9
0
        /// <summary>
        /// Draws rectangle.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="rect">Rectangle.</param>
        /// <param name="color">Object's color.</param>
        /// <param name="thickness">Border thickness (-1 to fill the object).</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Rectangle rect, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            if (float.IsNaN(rect.X) || float.IsNaN(rect.Y))
            {
                return;
            }

            draw(image, opacity, cvImg =>
            {
                CvCoreInvoke.cvRectangleR(&cvImg, rect, color.ToCvScalar(), thickness, LineTypes.EightConnected, 0);
            });
        }
Exemple #10
0
        /// <summary>
        /// Draws rectangle.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="rect">Rectangle.</param>
        /// <param name="color">Object's color.</param>
        /// <param name="thickness">Border thickness. If less than zero structure will be filled.</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Rectangle rect, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            if (float.IsNaN(rect.X) || float.IsNaN(rect.Y))
            {
                return;
            }

            using (var img = image.Lock())
            {
                var iplImage = img.AsCvIplImage();
                CvCoreInvoke.cvRectangleR(&iplImage, rect, color.ToCvScalar(opacity), thickness, LineTypes.EightConnected, 0);
            }
        }
Exemple #11
0
        private unsafe static void draw(Bgr <byte>[,] image, byte opacity, Action <IplImage> drawingAction)
        {
            using (var uImg = image.Lock())
            {
                var cvImg          = uImg.AsCvIplImage();
                var cvOverlayImPtr = CvCoreInvoke.cvCloneImage(&cvImg);

                drawingAction(*cvOverlayImPtr);
                CvCoreInvoke.cvAddWeighted(cvOverlayImPtr, (float)opacity / Byte.MaxValue, &cvImg, 1 - (float)opacity / Byte.MaxValue, 0, &cvImg);

                CvCoreInvoke.cvReleaseImage(&cvOverlayImPtr);
            }
        }
Exemple #12
0
        /// <summary>
        /// Draws contour.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="contour">Contour points.</param>
        /// <param name="color">Contour color.</param>
        /// <param name="thickness">Contours thickness (it does not support values smaller than 1).</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Point[] contour, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            var contourHandle = GCHandle.Alloc(contour, GCHandleType.Pinned);

            draw(image, opacity, cvImg =>
            {
                //TODO - noncritical: implement with cvContour
                CvCoreInvoke.cvPolyLine(&cvImg, new IntPtr[] { contourHandle.AddrOfPinnedObject() }, new int[] { contour.Length }, 1,
                                        true, color.ToCvScalar(), thickness, LineTypes.EightConnected, 0);
            });

            contourHandle.Free();
        }
Exemple #13
0
        /// <summary>
        /// Draws circles.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="circles">Circles</param>
        /// <param name="color">Circle color.</param>
        /// <param name="thickness">Contours thickness.</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void DrawCircles(this Bgr <byte>[,] image, IEnumerable <Circle> circles, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            Draw(image, opacity, cvImg =>
            {
                foreach (var circle in circles)
                {
                    var center = new Point(circle.X, circle.Y);

                    CvCoreInvoke.cvCircle(&cvImg, center, circle.Radius, color.ToCvScalar(),
                                          thickness, LineTypes.EightConnected, 0);
                }
            });
        }
Exemple #14
0
        /// <summary>
        /// Draws Box2D.
        /// </summary>
        /// <param name="image">Input image.</param>
        /// <param name="box">Box 2D.</param>
        /// <param name="color">Object's color.</param>
        /// <param name="thickness">Border thickness (-1 to fill the object).</param>
        /// <param name="opacity">Sets alpha channel where 0 is transparent and 255 is full opaque.</param>
        public unsafe static void Draw(this Bgr <byte>[,] image, Box2D box, Bgr <byte> color, int thickness, byte opacity = Byte.MaxValue)
        {
            if (thickness < 1)
            {
                throw new NotSupportedException("Only positive values are valid!");
            }

            var vertices = box.GetVertices();

            draw(image, opacity, cvImg =>
            {
                for (int i = 0; i < vertices.Length; i++)
                {
                    int idx2 = (i + 1) % vertices.Length;

                    CvCoreInvoke.cvLine(&cvImg, vertices[i].Round(), vertices[idx2].Round(),
                                        color.ToCvScalar(), thickness,
                                        LineTypes.EightConnected, 0);
                }
            });
        }
 /// <summary>
 /// Create a Font of the specific type, horizontal scale and vertical scale
 /// </summary>
 /// <param name="type">The type of the font.</param>
 /// <param name="hscale">The horizontal scale of the font.</param>
 /// <param name="vscale">The vertical scale of the font.</param>
 /// <param name="thickness">Font thickness.</param>
 public Font(FontTypes type, double hscale, double vscale, int thickness = 1)
     : this()
 {
     CvCoreInvoke.cvInitFont(ref this, type, hscale, vscale, 0, thickness, LineTypes.EightConnected);
 }