C++ Dlib: Face Detection














































C++ Dlib: Face Detection



Using this software, you can find frontal human faces in a photo and figure out their pose. There are 68 different landmarks in the posture. The corners of the lips, the space between the brows, the eyes, and other facial features are examples of these areas.

The face detector that we employ combines the conventional Histogram of Oriented Gradients (HOG) feature with a linear classifier, an image pyramid, and a sliding window detection technique.

#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>

#include <iostream>

using namespace dlib;

using namespace std;

int main(int argc, char** argv)

    try

    {

        if (argc == 1)



        {



            cout
<< "Call this program like this:" << endl;



            cout
<< "./face_landmark_detection_ex
shape_predictor_68_face_landmarks.dat faces/*.jpg" << endl;



            cout
<< "\nYou can get the shape_predictor_68_face_landmarks.dat file
from:\n";



            cout
<<
"http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2"
<< endl;



            return 0;



        }



       
frontal_face_detector detector = get_frontal_face_detector();



       
shape_predictor sp;



       
deserialize(argv[1]) >> sp;



        image_window win, win_faces;



 for (int i =0; i < argc; i++)  {

 cout<< "processing image " << argv[i] << endl;

          array2d<rgb_pixel> img;

          load_image(img, argv[i]);   

          pyramid_up(img);

          std::vector<rectangle> dets = detector(img);

          cout<< "Number of faces detected: " << dets.size() <<endl;

          std::vector<full_object_detection> shapes;

          for(unsigned long j = 0; j < dets.size(); ++j){

          full_object_detection shape = sp(img,dets[j]);

          cout<< "number of parts: "<< shape.num_parts() << endl;

          cout<< "pixel position of first part: " << shape.part(0) << endl;

          cout<< "pixel position of second part: " << shape.part(1)<< endl;                

          shapes.push_back(shape);

           }

           win.clear_overlay();    

           win.set_image(img);           

          win.add_overlay(render_face_detections(shapes));

          dlib::array<array2d<rgb_pixel> >face_chips;

          extract_image_chips(img, get_face_chip_details(shapes), face_chips);

          win_faces.set_image(tile_images(face_chips));

          cout<< "Hit enter to process the next image..." << endl

          cin.get();

          }

       }



    catch
(exception& e)



    {



        cout <<
"\nexception thrown!" << endl;



        cout <<
e.what() << endl;



    }



}


Comments