首先看类的申明:
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<CvCapture> 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;
介绍完了。。。。
本文详细介绍了OpenCV中VideoCapture类的使用方法,包括如何通过类构造函数及open方法打开摄像头或视频文件,如何检查设备或文件是否成功打开,并提供了基本的代码示例。

2698

被折叠的 条评论
为什么被折叠?



