0

I am running a code to extract optical flow on a movie and I want to run it on all the frames of the movie. However, when i use

number_of_frames = (int) cvGetCaptureProperty( input_video, CV_CAP_PROP_POS_FRAMES );

the number_of_frames comes out to be 0; My code snippet is as follows:

CvCapture *input_video = cvCaptureFromFile("C:\\Movies\\WESTWARD_HO.avi");
long number_of_frames;
cvSetCaptureProperty( input_video, CV_CAP_PROP_POS_AVI_RATIO, 1. );
number_of_frames = (int) cvGetCaptureProperty( input_video, CV_CAP_PROP_POS_FRAMES );

I am using visual studio 2008 with OpenCv 2.1. I know its old but i have to use it for backward compatibility with some other part of project. Thanks in advance !!

Random
  • 157
  • 1
  • 3
  • 13

2 Answers2

1

There are a ton of bugs filed in OpenCV related to this parameter. Right now, OpenCV just doesn't have very good support for it, although in the latest versions it improved considerably. Due to the sheer number of video formats, codecs, backends and so on, it is really difficult to make it work everywere.

If you really really need it, try to convert your video in another format. Chances are you'll get better results with a different codec. Also, installing more codecs helps sometimes.

Here is a related question regarding CV_CAP_POS_FRAMES: Reverse video playback in OpenCV

And, most important of all, update you OpenCV to 2.4.2. Using 2.1 reminds me of the times George Washington signed the Declaration of Independence...

Community
  • 1
  • 1
Sam
  • 19,708
  • 4
  • 59
  • 82
  • thanks for the clarifications !!! I suppose best way would be to avoid using it. changing to 2.4 is not really in my hands but i would suggest it to my supervisor – Random Jul 11 '12 at 12:31
  • Maybe the best is to try 2.4 locally, and if it works, you have a good reason to propose an official update. – Sam Jul 11 '12 at 12:47
-1

You are converting double value from 0-1 to int - that's why are you getting 0... If You want total number of frames use CV_CAP_PROP_FRAME_COUNT...