diff --git a/dlib/image_transforms/draw.h b/dlib/image_transforms/draw.h index d177dd2bf5336b6880d74ccc61f6b82b0d9bbf1e..7e661eab9db735a84ff460fc2bc67553f606f727 100644 --- a/dlib/image_transforms/draw.h +++ b/dlib/image_transforms/draw.h @@ -166,6 +166,46 @@ namespace dlib draw_line(p1.x(),p1.y(),p2.x(),p2.y(),c,val); } +// ---------------------------------------------------------------------------------------- + + template < + typename image_type, + typename pixel_type + > + void draw_rectangle ( + image_type& c, + const rectangle& rect, + const pixel_type& val + ) + { + draw_line(c, rect.tl_corner(), rect.tr_corner(), val); + draw_line(c, rect.bl_corner(), rect.br_corner(), val); + draw_line(c, rect.tl_corner(), rect.bl_corner(), val); + draw_line(c, rect.tr_corner(), rect.br_corner(), val); + } + +// ---------------------------------------------------------------------------------------- + + template < + typename image_type, + typename pixel_type + > + void draw_rectangle ( + image_type& c, + const rectangle& rect, + const pixel_type& val, + unsigned int thickness + ) + { + for (int i = 0; i < thickness; ++i) + { + if ((i%2)==0) + draw_rectangle(c,shrink_rect(rect,(i+1)/2),val); + else + draw_rectangle(c,grow_rect(rect,(i+1)/2),val); + } + } + // ---------------------------------------------------------------------------------------- template < diff --git a/dlib/image_transforms/draw_abstract.h b/dlib/image_transforms/draw_abstract.h index 2aad371714257e9856e88855b1ef455e537c9dee..5ef633c6c18741e28b861d50c4134917a2e09a64 100644 --- a/dlib/image_transforms/draw_abstract.h +++ b/dlib/image_transforms/draw_abstract.h @@ -55,6 +55,29 @@ namespace dlib // ---------------------------------------------------------------------------------------- + template < + typename image_type, + typename pixel_type + > + void draw_rectangle ( + image_type& img, + const rectangle& rect, + const pixel_type& val, + unsigned int thickness = 1 + ); + /*! + requires + - image_type == is an implementation of array2d/array2d_kernel_abstract.h + - pixel_traits<pixel_type> is defined + ensures + - Draws the given rectangle onto the image img. It does this by calling + draw_line() four times to draw the four sides of the rectangle. + - The rectancle is drawn with the color given by val. + - The drawn rectangle will have edges that are thickness pixels wide. + !*/ + +// ---------------------------------------------------------------------------------------- + template < typename image_type, typename pixel_type