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 :
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)
);
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
.
Edit for new question:
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.
!*/
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)
!*/
© 2022 - 2024 — McMap. All rights reserved.