/// <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); }
/// <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.AsOpenCvImage(); CvCoreInvoke.cvPutText(&iplImage, text, botomLeftPoint, ref font, color.ToCvScalar()); } }
/// <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.AsOpenCvImage(); CvCoreInvoke.cvEllipse(&iplImage, ellipse.Center.Round(), Size.Round(ellipse.Size), ellipse.Angle, 0, 2 * System.Math.PI, color.ToCvScalar(), thickness, LineTypes.EightConnected, 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.AsOpenCvImage(); var center = new Point(circle.X, circle.Y); CvCoreInvoke.cvCircle(&iplImage, center, circle.Radius, color.ToCvScalar(), thickness, LineTypes.EightConnected, 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.AsOpenCvImage(); CvCoreInvoke.cvRectangleR(&iplImage, rect, color.ToCvScalar(opacity), thickness, LineTypes.EightConnected, 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.</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); using (var img = image.Lock()) { var iplImage = img.AsOpenCvImage(); //TODO - noncritical: implement with cvContour CvCoreInvoke.cvPolyLine(&iplImage, new IntPtr[] { contourHandle.AddrOfPinnedObject() }, new int[] { contour.Length }, 1, true, color.ToCvScalar(), thickness, LineTypes.EightConnected, 0); } contourHandle.Free(); }
/// <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.</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(); using (var img = image.Lock()) { var iplImage = img.AsOpenCvImage(); for (int i = 0; i < vertices.Length; i++) { int idx2 = (i + 1) % vertices.Length; CvCoreInvoke.cvLine(&iplImage, vertices[i].Round(), vertices[idx2].Round(), color.ToCvScalar(opacity), 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 fonr</param> public Font(FontTypes type, double hscale, double vscale) : this() { CvCoreInvoke.cvInitFont(ref this, type, hscale, vscale, 0, 1, LineTypes.EightConnected); }