learning opencv系列--实现视频播放滑块随视频播放自动移动

来源:互联网 发布:网络劫持判断 编辑:程序博客网 时间:2024/04/28 08:06
实现视频播放滑块随视频播放自动移动

但是有一个问题是在视频播放的帧数越大的时候,播放速度明显变慢,移到视频前面帧数较小部分速度又会恢复。

#include <opencv2\opencv.hpp>  #include <iostream>using namespace cv;int g_slider_position = 0;CvCapture* g_capture = NULL;void onTrackbarSlide(int pos){    cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);}void main(){    cvNamedWindow("example2",CV_WINDOW_AUTOSIZE);    g_capture = cvCreateFileCapture("example.mp4 ");    int frames = (int)cvGetCaptureProperty(        g_capture,        CV_CAP_PROP_FRAME_COUNT        );    if(frames != 0)    {        cvCreateTrackbar(            "Position",            "example2",            &g_slider_position,            frames,            onTrackbarSlide);    }    IplImage* frame;    while(1)    {        frame = cvQueryFrame(g_capture);        if(!frame)            break;        cvShowImage("example2",frame);        char c = cvWaitKey(33);        if(c == 27)            break;        int position = (int)cvGetCaptureProperty(        g_capture,        CV_CAP_PROP_POS_FRAMES        );        cvSetTrackbarPos(            "Position",            "example2",            position);    }    cvReleaseCapture(&g_capture);    cvDestroyWindow("example2");    } 


0 0
原创粉丝点击