如何保存结果的面标志图像在dlib? [英] How to save resulted face landmark image in dlib?
问题描述
我使用dlib的face_landmark_detection_ex.cpp,它显示检测到的脸部图像和原始图像上的所有脸部界标。我要保存原始图像与所有68面孔地标到我的电脑。我知道它可以通过 save_png 和 draw_rectangle 的功能dlib,但draw_rectangle只给出检测到的面部矩形位置,连同它,我也想绘制地标点原始图像并保存为:
I am using dlib's face_landmark_detection_ex.cpp which display the detected face image and all face landmarks on the original image. I want to save the original image with all 68 face face landmarks to my computer. I know it can be done by save_png and draw_rectangle function of dlib but draw_rectangle only give detected face rectangle position, along with it, I also want to draw the landmark points on the original image and save them like this :
推荐答案
参数 pixel_type
用于指定要用于绘制矩形的像素种类。在函数的头声明中,定义了默认使用的像素类型是 rgb_pixel
( rgb_pixel(0, 0,0)
)
The parameter pixel_type
is used to specify the kind of pixels to be used to draw the rectangle. In the header declaration of the function it is defined that by default the kind of pixels to be used are black pixels of 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
保存此图像。
Hence, to save the image first use the function draw_rectangle
to draw the rectangle on the image and then save this image with save_png
.
绘制它们的简单方法是绘制每个地标( shape.part )
face_landmark_detection_ex.cpp $>中的函数
sp(img,dets [j])
c $ c>与函数 draw_pixel
。
A simple way of plotting them is to draw each landmark (shape.part(i)
) returned by the function sp(img, dets[j])
on the the face_landmark_detection_ex.cpp
with the function draw_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.
!*/
一旦绘制了所有地标, $ c> save_png 。
And once all landmarks have been drawn save the image with save_png
.
但是,我建议画这样的线条,而不是只是标记
However I would recommend to draw lines like that instead of just the landmarks
为此,请使用以下函数:
To do so, use the function:
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)
!*/
这篇关于如何保存结果的面标志图像在dlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!