我是靠谱客的博主 快乐往事,最近开发中收集的这篇文章主要介绍基于dlib的68个特征点检测,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

dlib有个很炫的功能,就是可以检测人脸的68个特征点。本博客目的是教怎么调用dlib的API去实现这一功能,还是老规矩,代码会提供。下载地址在这儿。之所以提供下载地址,是因为文件要下载,从官网上下载速度贼慢贼慢,我特么都下了个把小时了,最后还是csdn上一哥们儿给下载到了。另外一个方面,我很讨厌从那种控制台或者是terminal输入参数,因为我是程序员呀,直接从代码改个路径不久好了,至于那么麻烦么。。。
最后,我用的是范冰冰女士的照片,如果要侵权的话,我可以删掉。。。

/**
This example program shows how to find frontal human faces in an image and estimate their pose.
The pose takes the form of 68 landmarks. These are points on the face such as the corners of the mouth, 
along the eyebrows, on the eyes, and so forth.

The face detector we use is made using the classic Histogram of Oriented Gradient(HOG) feature
combined with a linear classifier, an image pyramid, and sliding window detection scheme. The pose estimator was created by 
using dlib's implemention of the paper:
*/
#include <string>
#include <iostream>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>

void face_landmark_detection_ex()
{
    try
    {
        std::string face_landmarks_path = "../Resources/dlib_info_files/shape_predictor_68_face_landmarks.dat";
        std::string face_img_path = "../Resources/dlib_info_files/timg.jpg";        // 此为图片路径,可根据自己图片来更改路径

        dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();
        dlib::shape_predictor sp;
        dlib::deserialize(face_landmarks_path) >> sp;
        dlib::image_window win;
        dlib::image_window win_faces;
        dlib::array2d<dlib::rgb_pixel> img;
        dlib::load_image(img, face_img_path);
        dlib::pyramid_up(img);

        // Now tell the face detector to give us a list of bounding boxes
        // around all the faces in the image.
        std::vector<dlib::rectangle> dets = detector(img);
        std::cout << "Number of faces detected: " << dets.size() << std::endl;

        // Now we will go ask the shape_predictor to tell us the pose of
        // each face we detected.
        std::vector<dlib::full_object_detection> shapes;
        for (unsigned long j = 0; j < dets.size(); ++j)
        {
            dlib::full_object_detection shape = sp(img, dets[j]);
            std::cout << "number of parts: " << shape.num_parts() << std::endl;
            std::cout << "pixel position of first part:  " << shape.part(0) << std::endl;
            std::cout << "pixel position of second part: " << shape.part(1) << std::endl;
            // You get the idea, you can get all the face part locations if
            // you want them.  Here we just store them in shapes so we can
            // put them on the screen.
            shapes.push_back(shape);
        }

        // Now let's view our face poses on the screen.
        win.clear_overlay();
        win.set_image(img);
        win.add_overlay(render_face_detections(shapes));

        // We can also extract copies of each face that are cropped, rotated upright,
        // and scaled to a standard size as shown here:
        dlib::array<dlib::array2d<dlib::rgb_pixel> > face_chips;
        extract_image_chips(img, get_face_chip_details(shapes), face_chips);
        win_faces.set_image(tile_images(face_chips));

        std::cout << "Hit enter to process the next image..." << std::endl;
        std::cin.get();
    }
    catch (std::exception& e)
    {
        std::cout << "n exception thrown!" << std::endl;
        std::cout << e.what() << std::endl;
    }
}

这里写图片描述

最后

以上就是快乐往事为你收集整理的基于dlib的68个特征点检测的全部内容,希望文章能够帮你解决基于dlib的68个特征点检测所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部