【问题标题】:How to save resulted face landmark image in dlib?如何在 dlib 中保存结果人脸地标图像?
【发布时间】:2016-08-08 08:32:47
【问题描述】:

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

【问题讨论】:

  • 没用过dlib,但是对成像的东西有了解。所以我猜,在 draw_rectangle 中,pixel_type 要求一个颜色值,它将用它来绘制矩形。尝试传递 struct rgb_pixel oValue(255, 0, 0) 的对象 (oValue);如果在调用 draw_rectangle 的适当位置传递 oValue,则将绘制一个红色矩形。

标签: c++ face-detection feature-extraction dlib


【解决方案1】:

参数pixel_type 用于指定用于绘制矩形的像素类型。在函数的头声明中定义了默认情况下要使用的像素类型是rgb_pixelrgb_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))。

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

【讨论】:

  • 你是如何得到眉毛轮廓的?谢谢。
猜你喜欢
  • 2017-10-28
  • 2017-02-21
  • 2020-09-27
  • 2021-03-22
  • 2017-05-22
  • 2017-10-18
  • 2018-01-20
  • 2017-02-09
  • 2019-02-20
相关资源
最近更新 更多