参数pixel_type 用于指定用于绘制矩形的像素类型。在函数的头声明中定义了默认情况下要使用的像素类型是rgb_pixel(rgb_pixel(0,0,0))类型的黑色像素
template <typename pixel_type>
void draw_rectangle (
const canvas& c,
rectangle rect,
const pixel_type& pixel = rgb_pixel(0,0,0),
const rectangle& area = rectangle(-infinity,-infinity,infinity,infinity)
);
因此,要保存图像,首先使用函数draw_rectangle在图像上绘制矩形,然后用save_png保存该图像。
编辑新问题:
绘制它们的一种简单方法是使用函数draw_pixel 在face_landmark_detection_ex.cpp 上绘制函数sp(img, dets[j]) 返回的每个地标(shape.part(i))。
template <typename pixel_type>
void draw_pixel (
const canvas& c,
const point& p,
const pixel_type& pixel
);
/*!
requires
- pixel_traits<pixel_type> is defined
ensures
- if (c.contains(p)) then
- sets the pixel in c that represents the point p to the
given pixel color.
!*/
绘制完所有地标后,将图像保存为save_png。
但是我建议画这样的线,而不仅仅是地标
为此,请使用以下函数:
template <typename image_type, typename pixel_type >
void draw_line (
image_type& img,
const point& p1,
const point& p2,
const pixel_type& val
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
ensures
- #img.nr() == img.nr() && #img.nc() == img.nc()
(i.e. the dimensions of the input image are not changed)
- for all valid r and c that are on the line between point p1 and p2:
- performs assign_pixel(img[r][c], val)
(i.e. it draws the line from p1 to p2 onto the image)
!*/