#include
"stdafx.h" #include "cv.h" #include
"highgui.h" using
namespace std;
int g_slider_position = 0;
CvCapture* g_capture = NULL;
int cur_frame = 0; //增加全局变量,指示g_capture的当前帧
void onTrackbarSlide(int pos)
{
if (pos!=cur_frame) //如果回调函数onTrackbarSlide(int pos)中当前的函数参数pos与全局变量相等,
//说明是滚动条自动移动造成的调用,不必重新设置g_capture的当前帧。。
{
cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
}
}
int main( int argc, char** argv )
{
cvNamedWindow( "Example2_3", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( "1.avi" );
int frames = (int) cvGetCaptureProperty( g_capture, CV_CAP_PROP_FRAME_COUNT);
if(frames!=0)
{
cvCreateTrackbar(
"Position",
"Example2_3",
&g_slider_position,
frames,
onTrackbarSlide
);
};
IplImage* frame;
while(1)
{
frame = cvQueryFrame( g_capture );
if( !frame ) break;
cvShowImage( "Example2_3", frame );
cur_frame = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES);//提取当前帧
cvSetTrackbarPos("Position","Example2_3",cur_frame);
char c = (char)cvWaitKey(50);
if(c == 27) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example2_3" );
return(0);
}
|
|