opencv——播放视频

#include "stdafx.h"

#include <opencv2opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;

CvCapture* capture=NULL;
int g_slider_position=0;
void onTrackbarSlide(int pos)
{
 cvSetCaptureProperty(capture,CV_CAP_PROP_POS_FRAMES,pos);
}


int _tmain(int argc, _TCHAR* argv[])
{
    cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
    //CvCapture* capture = cvCaptureFromAVI( argv[1] ); // either one will work
     capture= cvCreateFileCapture( "test.avi");
     IplImage* frame;
     int frames=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
     if(frames!=0)
     {
       cvCreateTrackbar("Position","Example2",&g_slider_position,frames,onTrackbarSlide);
     }
     
    while(1) 
    {
        frame = cvQueryFrame( capture );
        if( !frame ) break;
        cvShowImage( "Example2", frame );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Example2" );
}

原文地址:https://www.cnblogs.com/nanyangzp/p/3496449.html