cv::VideoCapture::set failed on image sequence

asked 2015-09-28 08:19:39 -0500

I am trying to use a cursor to seek a specific frame in stream.

main.cpp code follows:

#include <iostream>
#include <opencv2/opencv.hpp>

int main()
{
  cv::VideoCapture cap;

  if (!cap.open("8%d.jpg"))
    return 1;

  double index = cap.get(CV_CAP_PROP_POS_FRAMES);

  index += 10.0;    
  std::cout << "Seek to index: " << std::endl;

  if ( !(index < cap.get(CV_CAP_PROP_FRAME_COUNT)) )
    return 1;

  bool retval = cap.set(CV_CAP_PROP_POS_FRAMES, index);
  assert(retval);

  std::cout << cap.get(CV_CAP_PROP_POS_FRAMES) << std::endl;

  cap.release();
  return 0;
}

Command line on Ubuntu 14.4.3 LTS with OpenCV 2.4.11:

g++ main.cpp `pkg-config --cflags --libs opencv`

Command to check returning value:

echo "$#"

Output:

Seek to index: 10
-9.223377e+18

cv::VideoCapture::set function on an image sequence seems to break the stream, can you tell me why ?

Note: It works for a video as input but not an image sequence!

PS: I prefer asking before looking inside OpenCV-FFmpeg source code (it could take a while). Same question as http://stackoverflow.com/questions/32818053/cvvideocaptureset-failed-on-image-sequence

edit retag flag offensive close merge delete

Comments

You are opening a .jpg file that I assume is a still image. VideoCapture opens this file but then, there is no way for it to go to a specified frame position because there is none.

unxnut gravatar imageunxnut ( 2015-09-28 12:01:02 -0500 )edit

VideoCapture is able to open an image sequence, that is to say, a sequence of consecutive images (00000001.jpg to 00000196.jpg in my example). Normally, if I want to go to frame number 10, it should give me the image 00000011.jpg.

double_g gravatar imagedouble_g ( 2015-09-29 02:08:57 -0500 )edit