如何在 dlib 中保存结果人脸特征图像?

How to save resulted face landmark image in dlib?

我正在使用 dlib 的 face_landmark_detection_ex.cpp,它显示检测到的面部图像和原始图像上的所有面部特征。我想将包含所有 68 个面部特征的原始图像保存到我的计算机中。我知道可以通过 dlib 的 save_pngdraw_rectangle 函数来完成,但是 draw_rectangle 只检测到人脸矩形位置,连同它,我也想在原图上画出地标点,这样保存:

参数pixel_type用于指定用于绘制矩形的像素种类。在函数的 header 声明中定义了默认使用的像素类型是 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_pixelface_landmark_detection_ex.cpp 上绘制函数 sp(img, dets[j]) 返回的每个地标 (shape.part(i))。 =24=]

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)
    !*/