gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:04 27 4
gpt4 key购买 nike

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

image show in window

最佳答案

参数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 保存此图像。


编辑新问题:

绘制它们的一种简单方法是绘制函数 sp(img, dets[j])具有函数 draw_pixelface_landmark_detection_ex.cpp

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 保存图像。

但是我会建议画这样的线而不是仅仅画地标 enter image description here

为此,请使用函数:

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

关于c++ - 如何在 dlib 中保存结果人脸特征图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36662894/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com