使用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();
    }
Dlib为此集成了OpenCV。您可以使用OpenCV功能读取视频文件,并使用Dlib进行人脸检测

以下是这种集成的示例

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

您应该只更改

cv::VideoCapture cap(0);

进入

cv::VideoCapture videoCapture;
videoCapture.open(fileName);

如果你的帧很大,那么检测就会很慢。因此,最好调整帧的大小,然后执行跟踪/检测过程。

最新更新