首先看类的申明:
class CV_EXPORTS_W VideoCapture { public: CV_WRAP VideoCapture(); CV_WRAP VideoCapture(const string& filename); CV_WRAP VideoCapture(int device); virtual ~VideoCapture(); CV_WRAP virtual bool open(const string& filename); CV_WRAP virtual bool open(int device); CV_WRAP virtual bool isOpened() const; CV_WRAP virtual void release(); CV_WRAP virtual bool grab(); CV_WRAP virtual bool retrieve(CV_OUT Mat& image, int channel=0); virtual VideoCapture& operator >> (CV_OUT Mat& image); CV_WRAP virtual bool read(CV_OUT Mat& image); CV_WRAP virtual bool set(int propId, double value); CV_WRAP virtual double get(int propId); protected: Ptr调用源码如下:cap; };
VideoCapture capture; capture.open(0);capture.open(0)即是打开设备的端口号。
或者调用如下:
std::string videoFile = "../test.avi"; cv::VideoCapture capture; capture.open(videoFile);检测是否打开摄像头或者视频文件的函数,打开了返还true,没打开返回false。
CV_WRAP virtual bool isOpened() const;介绍完了。。。。