#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; }