0

我正在尝试将相机中的每一帧写入视频。到这里为止还好。但是,我希望我的视频在每一帧也包含 shape_predictor,因此当它被复制时,它也会出现在图像上。到目前为止,我已经得到了这个......有什么想法吗?谢谢

cap >> frame;
cv::VideoWriter oVideoWriter;
// . . .
cv_image<bgr_pixel> cimg(frame);               //Mat to something dlib can deal with
frontal_face_detector detector = get_frontal_face_detector();
std::vector<rectangle> faces = detector(cimg);
pose_model(cimg, faces[0]);
oVideoWriter.write(dlib::toMat(cimg));          //Turn it into an Opencv Mat
4

1 回答 1

3

形状预测器不是人脸检测器。您必须首先调用面部检测器,然后调用形状预测器。

请参阅此示例程序: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);
        }
于 2015-04-17T18:04:55.770 回答