如何使用Dlib保存带Overlay的视频?

时间:2016-11-11 07:07:39

标签: dlib opencv3.1

我正在使用Dlib 19.2和VS2015。我正在执行以下程序,如此链接中所述' http://dlib.net/webcam_face_pose_ex.cpp'

我想在每个帧上保存带有所有地标的视频。我该怎么做? 我正在运行以下代码。

int main(){

 try{

    cv::VideoCapture cap("out.avi");

    int count =cap.get(CV_CAP_PROP_FRAME_COUNT);
    if (!cap.isOpened())
    {
        cout << "Unable to connect to camera" << endl;
        return 1;
    }

    image_window win;

    // Load face detection and pose estimation models.
    frontal_face_detector detector = get_frontal_face_detector();
    shape_predictor pose_model;
    deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;

    // Grab and process frames until the main window is closed by the user.
    while (!win.is_closed())
    {
        // Grab a frame
        cv::Mat temp;
        cap >> temp;

        // Turn OpenCV's Mat into something dlib can deal with.  Note that this just
        // wraps the Mat object, it doesn't copy anything.  So cimg is only valid as
        // long as temp is valid.  Also don't do anything to temp that would cause it
        // to reallocate the memory which stores the image as that will make cimg
        // contain dangling pointers.  This basically means you shouldn't modify temp
        // while using cimg.
        cv_image<bgr_pixel> cimg(temp);

        // Detect faces 
        std::vector<rectangle> faces = detector(cimg);
        // Find the pose of each face.
        std::vector<full_object_detection> shapes;
        for (unsigned long i = 0; i < faces.size(); ++i)
            shapes.push_back(pose_model(cimg, faces[i]));

        // Display it all on the screen
        win.clear_overlay();
        win.set_image(cimg);
        win.add_overlay(render_face_detections(shapes));
        waitKey(20);
    }
}
catch (serialization_error& e)
{
    cout << "You need dlib's default face landmarking model file to run this example." << endl;
    cout << "You can get it from the following URL: " << endl;
    cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
    cout << endl << e.what() << endl;
}
catch (exception& e)
{
    cout << e.what() << endl;
}


getch();

}

所以请指导我。

0 个答案:

没有答案