首页 > 其他 > 详细

OpenCV--VideoCapture类

时间:2019-05-06 15:30:29      阅读:341      评论:0      收藏:0      [点我收藏+]

读取本地视频&打开摄像头
***
OpenCV中VideoCapture中有三个构造函数

class CV_EXPORTS_W VideoCapture
{
public:
        CV_WRAP VideoCapture();
        CV_WRAP VideoCapture(const String& filename, int apiPreference = CAP_ANY);
        CV_WRAP VideoCapture(int index, int apiPreference = CAP_ANY);
        virtual ~VideoCapture();
    
    CV_WRAP virtual bool open(const String& filename, int apiPreference = CAP_ANY);

    CV_WRAP virtual bool open(int index, int apiPreference = CAP_ANY);
    
    CV_WRAP virtual bool isOpened() const;
    
    CV_WRAP virtual void release();
    
    CV_WRAP virtual bool grab();
    
    CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0);
    
    virtual VideoCapture& operator >> (CV_OUT Mat& image);

    virtual VideoCapture& operator >> (CV_OUT UMat& image);

    CV_WRAP virtual bool read(OutputArray image);

    CV_WRAP virtual bool set(int propId, double value);

    CV_WRAP virtual double get(int propId) const;

    CV_WRAP String getBackendName() const;

protected:
    Ptr<CvCapture> cap;
    Ptr<IVideoCapture> icap;
}

读取本地视频

void VideoRead()
{
    VideoCapture capture("1.mp4");
    /*
    VideoCapture capture;
    captrue.open("1.mp4");
    */
        while (1)
    {
        //frame存储每一帧图像
        Mat frame;
        //读取当前帧
        capture >> frame;
        //播放完退出
        if (frame.empty()) {
            printf("播放完成\n");
            break;
        }
        imshow("读取视频",frame);
        //延时30ms
        waitKey(30);
    }
}

OpenCV--VideoCapture类

原文:https://www.cnblogs.com/elong1995/p/10819739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!