OpenCV播放视频带滚动条(3)

 

演示 :一个带有滚动条的播放视频的代码。

 

#include
"stdafx.h"

#include
<opencv2/core/core.hpp>

#include
<opencv2/contrib/contrib.hpp>

#include
<opencv2/highgui/highgui.hpp>

#include
<opencv2/imgproc/imgproc.hpp>

#include
<opencv2/objdetect/objdetect.hpp>

 

using
namespace cv;

using
namespace std;

#pragma
comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")

 

int g_slider_position = 0;

int i = 0;

CvCapture* g_capture = NULL;

void onTrackingbarSlide(int
pos)

{

    i = pos;

    cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);

}

 

int main(int
argc, char** argv[])

{

    cvNamedWindow("Example3", CV_WINDOW_NORMAL);

    g_capture = cvCreateFileCapture("F:\\life\\opencv\\BuildingCordovaAppsWithVS_high.mp4");

 

    int frames = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);

    if (frames != 0)

    {

        cvCreateTrackbar("Position", "Example3", &g_slider_position, frames, onTrackingbarSlide);

    }

 

    IplImage* frame;

    while (1)

    {

        i++;

        frame = cvQueryFrame(g_capture);

        if (!frame) break;

        cvShowImage("Example3", frame);

        char c = cvWaitKey(33);

        if (c == 27) break;

 

        cvSetTrackbarPos("Position", "Example3", i);

    }

 

    cvReleaseCapture(&g_capture);

    cvDestroyWindow("Example3");

 

    return 0;

}

 

OpenCV播放视频带滚动条(3)

上一篇:前端框架layui


下一篇:ffmpeg和opencv 播放视频文件和显示器