How to save the received face landmark image in dlib?

I am using dlib face_landmark_detection_ex.cpp, which displays the detected face image and all the face landmarks in the original image. I want to keep the original image with all 68 face landmarks facing the computer. I know that this can be done using the save_png and draw_rectangle functions of the dlib, but draw_rectangle only gives the detected position of the face rectangle with it, I also want to draw landmarks on the original image and save them as follows:

show image in window

+5
c ++ face-detection feature-extraction dlib
source share
1 answer

The pixel_type parameter pixel_type used to specify the type of pixels that will be used to draw the rectangle. The function header declaration defines that by default the type 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) ); 

Therefore, to save the image, first use the draw_rectangle function to draw a rectangle on the image, and then save this image with save_png .


Edit for new question:

An easy way to build them is to draw each landmark ( shape.part(i) ) returned by the sp(img, dets[j]) function in face_landmark_detection_ex.cpp using the draw_pixel function.

 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 the landmarks have been drawn, save the image using save_png .

However, I would recommend drawing such lines, not just landmarks enter image description here

To do this, 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() (ie 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) (ie it draws the line from p1 to p2 onto the image) !*/ 
+3
source share

All Articles