#include"highgui.h"
#include"cv.h"
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos){
cvSetCaptureProperty(g_capture,
CV_CAP_PROP_POS_FRAMES, pos);//CV_CAP_PROP_POS_FRAMES - 将被下一步解压/获取的帧索引,以0为起点
}
int main()
{
g_capture = cvCreateFileCapture("D:\\Opencv\\testData\\video.avi");
cvNamedWindow("Video", CV_WINDOW_AUTOSIZE);
IplImage* frame;
int frames = (int)cvGetCaptureProperty(g_capture,
CV_CAP_PROP_FRAME_COUNT);//CV_CAP_PROP_FRAME_COUNT - 视频文件中帧的总数
if (frames != 0){
cvCreateTrackbar("Position", "Video", &g_slider_position, frames, onTrackbarSlide);
}
while (1){
frame = cvQueryFrame(g_capture);
if (!frame) break;
cvShowImage("Video", frame);
cvWaitKey(33);
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("Video");
return 0;
}