#include "cv.h" #include "highgui.h" CvCapture* g_capture; int g_position; void onTrackbarSlide(int pos){ cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos); } int main(int argc, char** argv){ g_capture = cvCaptureFromFile("***.avi"); cvNamedWindow("window",CV_WINDOW_AUTOSIZE); int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT); if(frames!=0){ cvCreateTrackbar("track","window",&g_position,frames,onTrackbarSlide); } IplImage* frame; while(TRUE){ frame=cvQueryFrame(g_capture); if(!frame){break;} cvShowImage("window",frame); char c = cvWaitKey(100); if(c==27){ break; } } cvReleaseImage(&frame); cvReleaseCapture(&g_capture); cvDestroyWindow("window"); return 0; } capture里应该有一个int型变量指向capture当前帧