1. 程式人生 > >openCV 播放視訊 帶進度條

openCV 播放視訊 帶進度條


#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"

#include <iostream>

using namespace std;
using namespace cv;

int g_slider_position = 0;
CvCapture* g_caputre = NULL;

void onTrackbarSlide(int pos)
{
    cvSetCaptureProperty(g_caputre, CV_CAP_PROP_POS_FRAMES, pos);
}

int main(int argc,  char **argv)
{
    
    cvNamedWindow("WIND0", CV_WINDOW_AUTOSIZE);
    g_caputre = cvCreateFileCapture(argv[1]);

    int frames = (int) cvGetCaptureProperty(g_caputre, CV_CAP_PROP_FRAME_COUNT);
    if (frames != 0)
    {
        cvCreateTrackbar("Position", "WIND0", &g_slider_position, frames, onTrackbarSlide);
    }

    IplImage* frame;

    while (1)
    {
        frame = cvQueryFrame(g_caputre);
        if (!frame) break;
        cvShowImage("WIND0", frame);
        char c = cvWaitKey(33);
        if (c == 'c') break;
    }

    cvReleaseCapture(&g_caputre);
    cvDestroyWindow("WIND0");


    return 0;
}


cmake_minimum_required(VERSION 2.8)

project(playvideo_control)

find_package(OpenCV REQUIRED)

add_executable(playvideo_control main.cpp)

target_link_libraries(playvideo_control ${OpenCV_LIBS})