As is the function to control video with trackbar

asked 2012-09-09 12:55:00 -0500

mauricioav gravatar image

updated 2012-09-09 15:49:49 -0500

AlexanderShishkov gravatar image

Hello everyone. I'm new in using OpenCV. I have a slider to move forward or backward a video. I have relied on the example2-3 and it does not work. I guess I am missing something.

#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"

using namespace cv;
VideoCapture capture;
int slider_position=0;
Mat frame;
void on_trackbar( int , void* )
{
 int position=(double)slider_position;
 capture.set(CV_CAP_PROP_POS_FRAMES, position);
 //imshow("",);
}
int main( int argc, char** argv ) 
{
 namedWindow( "Ejemplo_TrackBar", CV_WINDOW_AUTOSIZE );
 VideoCapture capture = VideoCapture( argv[1] );
 int frames= (int)capture.get(CV_CAP_PROP_FRAME_COUNT);
 if(frames!=0)
 {
     createTrackbar("Position","Ejemplo_TrackBar",&slider_position,frames,on_trackbar);
 }
 while(1) 
 {  
  if( !capture.read(frame) ) 
      break;
  imshow( "Ejemplo_TrackBar", frame );
  char c = waitKey(33);
  if( c == 27 ) break;
 }
  capture.release();
}
edit retag flag offensive close merge delete