2016-03-29 46 views
1

我正在嘗試製作離線視頻臉部檢測程序。我已經使用示例代碼進行人臉檢測,並且工作良好。但由於dlib庫不能直接在視頻上工作(或者我不知道它是否會),所以我正在爲圖像人臉檢測程序提供幀。對於像20-30幀視頻這樣的小視頻來說,它工作正常,但是如果給出更大的視頻,則會出現緩衝區溢出錯誤。我是否必須刪除數據或明確清除一些動態內存?或者它只處理少量圖像進行人臉檢測?使用dlib進行視頻臉部檢測

下面是代碼片段

// 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(); 
    } 

回答

3

DLIB有,一個OpenCV的集成。可以讀取視頻文件,OpenCV的功能和使用DLIB人臉檢測

這裏是此類整合的樣本

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

您應該只改變

cv::VideoCapture cap(0); 

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

如果你的相框是大的話檢測會很慢。所以最好調整幀大小,然後執行跟蹤/檢測過程。