原文写于2013年3月22日
#include "stdafx.h"
#include "highgui.h"
int slide_position = 0;
CvCapture * g_capture = 0;
int n=0; //定义一个全局变量,控制滚动条的位置
void onTrackbarSlide (int pos){ //滚动条移动的调用函数
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
n=pos;
}
int main( int argc, char ** argv[]) {
cvNamedWindow("example3",CV_WINDOW_AUTOSIZE);
g_capture = cvCreateFileCapture ("tree.avi");
int frames = cvGetCaptureProperty( //获取视频的帧数
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
if(frames != 0){
cvCreateTrackbar( //定义滚动条属性
"position",
"example3",
&slide_position,
frames,
onTrackbarSlide
);
}
IplImage * frame;
while(1){
frame = cvQueryFrame( g_capture );
if(!frame)break;
cvShowImage("example3",frame);
cvSetTrackbarPos(
"position",
"example3",
n++);
char c = cvWaitKey(33);
if(c == 27 )break;
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("example3");
return(0);
}
心得:滚动条可以控制,但是播放是比正常速度慢