-1

I am using the

    haarcascade_frontalface_alt2.xml

file for face detection in OpenCV 2.4.3 under the Visual Studio 10 framework. I am using

    Mat frame;
    cv::VideoCapture capture("C:\\Users\\Xavier\\Desktop\\AVI\\Video 6_xvid.avi");
capture.set(CV_CAP_PROP_FPS,30);
    for(;;)
{

    capture >> frame;
     //face detection code
    }

The problem i'm facing is that as Haar face detection is computationally heavy, OpenCV is missing a few frames in the

    capture >> frame;

instruction. To check it I wrote to a txt file a counter and found only 728 frames out of 900 for a 30 sec 30fps video. Plz someone tell me how to fix it.

  • Did you check your frame rate?. See this link .. [http://stackoverflow.com/questions/9246564/getting-frames-from-avi-video-using-opencv][1] [1]: http://stackoverflow.com/questions/9246564/getting-frames-from-avi-video-using-opencv – Fadwa Dec 02 '13 at 10:51
  • Yes I did by writing to a txt file an integer counter. – Xavier Gonsalves Dec 04 '13 at 05:43

1 Answers1

0

I am not an experienced openCV user, but you could try flushing the outputstream of capture to disk. Unfortunately, I think the VideoCapture class does not seem to support such an operation. Note that flushing to disk will have an impact on your performance, since it will first flush everything and only then continue executing. Therefore it might not be the best solution, but it is the easiest one if possible.

Another approach that requires more work but that should fix it is to make a separate low priority thread that writes each frame to disk. Your current thread then only needs to call this low priority thread each time it wants its data to be captured. Depending on whether the higher priority thread might change the data while the low priority thread still has to write it to disk, you might want to copy the data to a separate buffer first.

bverhagen
  • 99
  • 4
  • I tried to first capture all frames in a vector of matrices and also tried an array of matrices to use as a buffer and then use the matrix frames in this buffer for face detection. But I was getting errors in their syntax. Can someone tell me how to make a vector or array of matrices for this problem. These matrices are used to hold the captured frame image in them. – Xavier Gonsalves Dec 04 '13 at 05:39
  • Instead of the 'capture >> frame' line, make a new function and call this one instead. The new function allocates a new memory chunk and copies the content of 'capture' to that memory chunk. Next it will write the copied memory chunk to your file using the >> operator. This is not the most optimal solution, but it is the easiest way to check whether this approach works. In a later stage you can create a low priority thread that writes the memory to the file while your original function writes to some kind of ringbuffer. – bverhagen Dec 05 '13 at 11:15