用opencv'打开avi视频并设置滚动条随之移动

来源:互联网 发布:java finally 抛异常 编辑:程序博客网 时间:2024/05/22 11:54
#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);}int main(int argc,char**argv){cvNamedWindow("example3",CV_WINDOW_AUTOSIZE);g_capture=cvCreateFileCapture(argv[1]);int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);if(frames!=0){cvCreateTrackbar("position","example3",&g_slider_position,frames,onTrackbarSlide);}IplImage*frame;int curpos=0;while(1){frame=cvQueryFrame(g_capture);curpos=cvGetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES);cvSetTrackbarPos("position","example3", curpos);if(!frame) break;cvShowImage("example3",frame);char c=cvWaitKey(33);if(c==27) break;}cvReleaseCapture(&g_capture);cvDestroyWindow("example3");return 0;}