openCV3 Track Bar

来源:互联网 发布:标识设计软件 编辑:程序博客网 时间:2024/06/05 00:55

opencv3

Add Progress Bar to your video

C++

/** main.cpp*Video Track Bar*  Created on: 2015.10.24*      Author: anonymous*/#include <opencv2/opencv.hpp>#include <opencv2/video/video.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/core/core.hpp>#include <iostream>#include <cstdio>using namespace std;using namespace cv;void onTrackbar(int, void*);VideoCapture cap;int main(){       Mat curFrame;    Mat dst;    int framePosition = 0;    uint curFrameCount = 0;    bool stop = false;#ifdef CAMERA    cap.open(0);    if (!cap.isOpened())        return -1;#else    cap.open("G:\\video.avi");    if (!cap.isOpened())    {        cout << "fail to open video" << endl;        return -1;    }    uint totalFrame = cap.get(CAP_PROP_FRAME_COUNT);    namedWindow("src");    createTrackbar("frameCurPosition", "src", &framePosition, totalFrame, onTrackbar);    onTrackbar(framePosition, 0);#endif    while (1)    {        if (!cap.read(curFrame))        {            cout << "fail to read video" << endl;            return -1;        }        if (stop)        {            cap.set(CAP_PROP_POS_FRAMES, framePosition);            curFrameCount = framePosition;        }            //get video position            int trapos = (int)cap.get(CAP_PROP_POS_FRAMES);            //set track bar to be consistent with video position            setTrackbarPos("frameCurPosition", "src", trapos);            //play the video        imshow("src", curFrame);        char button = waitKey(1);        if (button == 113 || cap.get(CAP_PROP_POS_FRAMES) == totalFrame) //press q then exit            break;        else if (button == 32)//press blank then pause        {            stop = 1 - stop;        }    }    return 0;}void onTrackbar(int pos, void*){    cap.set(CAP_PROP_POS_FRAMES, pos);}
0 0
原创粉丝点击