opencv读取视频并控制播放

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38877910/article/details/80289420


#include <iostream>
#include<highgui.h>
#include "cv.h"
using namespace std;
using namespace cv;


int g_slide_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("Example2", CV_WINDOW_AUTOSIZE);
   g_capture = cvCreateFileCapture("local .avi");//这个是视频文件的名称
int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
if (frames!=0)
{
cvCreateTrackbar("position","Example2",&g_slide_position,frames,ontrackbarSlide);//position是滑块的当前位置
}
    IplImage* frame;
 while(1)
 {
     frame = cvQueryFrame(g_capture);
     if(!frame)
     break;
  cvShowImage("Example2",frame);
  char c = cvWaitKey(33); 
/*    if(c == 27)
     break;*/
  }
  cvReleaseCapture(&g_capture);
  cvDestroyWindow("Example2");
}

猜你喜欢

转载自blog.csdn.net/weixin_38877910/article/details/80289420
今日推荐