使用dlib进行视频人脸检测

时间:2016-03-29 11:46:11

标签: c++ video face-detection dlib

我正在尝试制作离线视频人脸检测程序。我已经使用了示例代码进行人脸检测,它运行良好。但由于dlib库不能直接在视频上工作(或者我不知道是否这样),我正在为图像人脸检测程序提供帧。对于像20-30帧视频这样的小视频,它工作正常,但如果给出更大的视频则会出现缓冲区溢出错误。我是否必须明确删除数据或清除某些动态内存?或者只处理少量图像进行人脸检测?

以下是代码段

// Loop over all the images provided on the command line.
    for (int i = 1; i <= 629; ++i)
    {
        //cout << "processing image " << endl;
        array2d<unsigned char> img;
        //load_image(img, argv[i]);
    sprintf(image, "./frame/frame%d.jpg",i);
    load_image(img, image);

        pyramid_up(img);

        // Now tell the face detector to give us a list of bounding boxes
        // around all the faces it can find in the image.
        std::vector<rectangle> dets = detector(img);

        //cout << "Number of faces detected: " << dets.size() << endl;
    //cout<<i<<"\t"<<dets.size()<<endl;
        // Now we show the image on the screen and the face detections as
        // red overlay boxes.
        win.clear_overlay();
        win.set_image(img);
        win.add_overlay(dets, rgb_pixel(255,0,0));

        //cout << "Hit enter to process the next image..." << endl;
        //cin.get();
    }

1 个答案:

答案 0 :(得分:4)

Dlib有一个OpenCV集成。您可以使用OpenCV函数读取视频文件,并使用Dlib进行面部检测

以下是此类整合的示例

http://dlib.net/webcam_face_pose_ex.cpp.html

你应该只改变

cv::VideoCapture cap(0);

cv::VideoCapture videoCapture;
videoCapture.open(fileName);
相关问题