Commit bc332150 authored by Davis King's avatar Davis King

Added a version of draw_rectangle() that can draw directly onto an array2d.

parent f6c42f7d
...@@ -166,6 +166,46 @@ namespace dlib ...@@ -166,6 +166,46 @@ namespace dlib
draw_line(p1.x(),p1.y(),p2.x(),p2.y(),c,val); 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 < template <
......
...@@ -55,6 +55,29 @@ namespace dlib ...@@ -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 < template <
typename image_type, typename image_type,
typename pixel_type typename pixel_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment