形状预测器不是人脸检测器。您必须首先调用面部检测器,然后调用形状预测器。
请参阅此示例程序:http ://dlib.net/face_landmark_detection_ex.cpp.html
您正确初始化了面部检测器..然后您必须初始化跟踪器。像这样的东西:
shape_predictor sp;
deserialize("shape_predictor_68_face_landmarks.dat") >> sp;
该模型可以在这里找到:http: //sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
剩下的部分,您可以按照我上面链接的示例程序进行操作。这是运行跟踪器的部分。您必须将检测器返回的输出(边界框)传递给跟踪器才能使其工作。下面的代码遍历检测器返回的所有框。
// Now tell the face detector to give us a list of bounding boxes
// around all the faces in the image.
std::vector<rectangle> dets = detector(img);
cout << "Number of faces detected: " << dets.size() << endl;
// Now we will go ask the shape_predictor to tell us the pose of
// each face we detected.
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;
// 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);
}