dlib's face_landmark_detection

问 题

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 :

image show in window

解决方案

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 enter image description here

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

本文地址:IT屋 » How to save resulted face landmark image in dlib?

问 题

我使用dlib的face_landmark_detection_ex.cpp,它显示检测到的脸部图像和原始图像上的所有脸部界标。我要保存原始图像与所有68面孔地标到我的电脑。我知道它可以通过 save_png  draw_rectangle 的功能dlib,但draw_rectangle只给出检测到的面部矩形位置,连同它,我也想绘制地标点原始图像并保存为:


 

解决方案

参数 pixel_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 =矩形(-infinity,-infinity,infinity,infinity)
); 
  


 

因此,要保存图像,首先使用函数 draw_rectangle 在图像上绘制矩形,然后使用 save_png 保存此图像。


 



 

编辑新问题:


 

绘制它们的简单方法是绘制每个地标( shape.part ) face_landmark_detection_ex.cpp 中的函数 sp(img,dets [j]) c $ c>与函数 draw_pixel 。


 

  pixel_type> 
 void draw_pixel(
 const canvas& c,
 const point& p,
 const pixel_type& pixel 
); 
 / *! 
 requires 
  -  pixel_traits< pixel_type>被定义
确保
  -  if(c.contains(p))then 
  - 设置c中的像素,表示点p到给定像素颜色的
。 
!* / 
  


 

一旦绘制了所有地标, $ c> 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 
); 
 / *! 
需要
  -  image_type ==实现
中定义的接口的图像对象dlib / image_processing / generic_image.h 
确保
  - #img.nr()= = img.nr()&& #img.nc()== img.nc()
(即输入图像的尺寸不变)
  - 对于点p1和p2之间的线上的所有有效r和c :
  - 执行assign_pixel(img [r] [c],val)
(即绘制从p1到p2到图像上的线)
!* / 
  

本文地址:IT屋 » 如何保存结果的面标志图像在dlib?

猜你喜欢

转载自blog.csdn.net/CVAIDL/article/details/85061137