| 61 | // ---------------------------------------------------------------------------------------- |
| 62 | |
| 63 | int main(int argc, char** argv) |
| 64 | { |
| 65 | try |
| 66 | { |
| 67 | // This example takes in a shape model file and then a list of images to |
| 68 | // process. We will take these filenames in as command line arguments. |
| 69 | // Dlib comes with example images in the examples/faces folder so give |
| 70 | // those as arguments to this program. |
| 71 | if (argc == 1) |
| 72 | { |
| 73 | cout << "Call this program like this:" << endl; |
| 74 | cout << "./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces/*.jpg" << endl; |
| 75 | cout << "\nYou can get the shape_predictor_68_face_landmarks.dat file from:\n"; |
| 76 | cout << "http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl; |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | // We need a face detector. We will use this to get bounding boxes for |
| 81 | // each face in an image. |
| 82 | frontal_face_detector detector = get_frontal_face_detector(); |
| 83 | // And we also need a shape_predictor. This is the tool that will predict face |
| 84 | // landmark positions given an image and face bounding box. Here we are just |
| 85 | // loading the model from the shape_predictor_68_face_landmarks.dat file you gave |
| 86 | // as a command line argument. |
| 87 | shape_predictor sp; |
| 88 | deserialize(argv[1]) >> sp; |
| 89 | |
| 90 | |
| 91 | image_window win, win_faces; |
| 92 | // Loop over all the images provided on the command line. |
| 93 | for (int i = 2; i < argc; ++i) |
| 94 | { |
| 95 | cout << "processing image " << argv[i] << endl; |
| 96 | array2d<rgb_pixel> img; |
| 97 | load_image(img, argv[i]); |
| 98 | // Make the image larger so we can detect small faces. |
| 99 | pyramid_up(img); |
| 100 | |
| 101 | // Now tell the face detector to give us a list of bounding boxes |
| 102 | // around all the faces in the image. |
| 103 | std::vector<rectangle> dets = detector(img); |
| 104 | cout << "Number of faces detected: " << dets.size() << endl; |
| 105 | |
| 106 | // Now we will go ask the shape_predictor to tell us the pose of |
| 107 | // each face we detected. |
| 108 | std::vector<full_object_detection> shapes; |
| 109 | for (unsigned long j = 0; j < dets.size(); ++j) |
| 110 | { |
| 111 | full_object_detection shape = sp(img, dets[j]); |
| 112 | cout << "number of parts: "<< shape.num_parts() << endl; |
| 113 | cout << "pixel position of first part: " << shape.part(0) << endl; |
| 114 | cout << "pixel position of second part: " << shape.part(1) << endl; |
| 115 | // You get the idea, you can get all the face part locations if |
| 116 | // you want them. Here we just store them in shapes so we can |
| 117 | // put them on the screen. |
| 118 | shapes.push_back(shape); |
| 119 | } |
| 120 |
nothing calls this directly
no test coverage detected