/// <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); } }); }