VideoCapture类可以从文件或者摄像设备中读取视频。VideoCapture提供了常用的三种构造函数:
VideoCapture::VideoCapture()
VideoCapture::VideoCapture(int device)
VideoCapture::VideoCapture(const string& filename);
说明:
第一个是默认无参构造函数
第二个中参数device指定要打开的摄像头设备
第三个构造函数中filename 是指要打开的视频文件路径以及名称;
VideoCapture类还提供了read方法并且使用了重载运算符>> 获取视频的每一帧。其函数原型如下:
VideoCapture& VideoCapture::operator>>(UMat& frame);
VideoCapture& VideoCapture::operator>>(Mat& frame);
bool VideoCapture::read(OutputArray frame);
VideoCapture常用的一些函数如下:
函数 | 功能 |
---|---|
VideoCapture::isOpened() | Returns true if video capturing has been initialized already |
VideoCapture::getBackednName() | Returns used backend API name |
VideoCapture::grab() | Grabs the next frame from video file or capturing device |
VideoCapture::open(int index)VideoCapture::open(const string& filename)VideoCapture::open(int index,int apiPreference);VideoCapture::open(const string& filename,int apiPreference); | Open video file or a capturing device or a IP video stream for video capturing with API Preference |
VideoCapture::release() | Closes video file or capturing device |
VideoCapture::retrieve(OutputArray image,int flags= 0); | Decodes and returns the grabbed video frame. |
VideoCapture::get(int propId) | Returns the specified VideoCapture property |
VideoCapture::set(int propId,double value); | Sets a property in the VideoCapture |
示例代码如下:
1 |
|