#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
int g_slider_position =0;
CvCapture* g_capture=NULL;
void onTrackbarSlide(int pos)
{
cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);
}
int main(int argc,char** argv)
{
cvNamedWindow("example",CV_WINDOW_AUTOSIZE);
g_capture =cvCreateFileCapture(argv[1]); //指向视频文件
int frames =(int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);// 获取视频总帧数
if(frames!=0)
{
cvCreateTrackbar("position","example",&g_slider_position,frames,onTrackbarSlide); //创建滚动条
}
IplImage* frame;
while(1){
frame =cvQueryFrame(g_capture);
if(!frame)
break;
cvShowImage("example",frame);
char c=cvWaitKey(33);
if(c==27)
break;
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("example");
return 0;
}