ANU*_*NGH 6 c++ feature-extraction face-detection dlib
我正在使用dlib的face_landmark_detection_ex.cpp,它在原始图像上显示检测到的面部图像和所有面部标记.我想将原始图像与所有68个面部地标保存到我的计算机上.我知道它可以通过dlib的save_png和draw_rectangle函数来完成,但draw_rectangle只给出检测到的面部矩形位置,同时我也想在原始图像上绘制标志点并保存它们如下:
该参数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。
绘制它们的一个简单方法是在函数上绘制函数返回的每个地标( shape.part(i)) 。sp(img, dets[j])face_landmark_detection_ex.cppdraw_pixel
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)
    !*/