OpenCV--VideoCapture类

读取本地视频&打开摄像头
***
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);
    }
}

猜你喜欢

转载自www.cnblogs.com/elong1995/p/10819739.html