Opencv学习之VideoCapture类

VideoCapture类可以对视频进行读取操作以及调用摄像头,下面是该类的API。

1、VideoCapture类的构造函数:


C++: VideoCapture::VideoCapture();
C++: VideoCapture::VideoCapture(const string& filename);
C++: VideoCapture::VideoCapture(int device);

功能:创建一个VideoCapture类的实例,传入相对应的参数可以打开视频文件或者调用摄像头。

参数:

filename:打开的视频文件名

device:打开的摄像头捕获设备id,如果只有一个摄像头可以填0,表示打开默认的摄像头。


2、VideoCapture::open

C++: bool VideoCapture::open(const string& filename);
C++: bool VideoCapture::open(int device);

功能、参数和VideoCapture类的构造函数一样

所以打开视频和摄像头有两种方法:

第一种:实例化的同时进行初始化

VideoCapture("opencv.avi");

第二种:先实例化再初始化

VideoCapture capture;

capture.open("opencv.avi");


3、VideoCapture::isOpened

C++: bool VideoCapture::isOpened();

功能:判断视频读取或者摄像头调用是否成功,成功则返回true。


4、VideoCapture::release

C++: void VideoCapture::release();

功能:关闭视频文件或者摄像头。


5、VideoCapture::grab

C++: bool VideoCapture::grab();

功能:从视频文件或捕获设备中抓取下一个帧,假如成功返回true。


6、VideoCapture::retrieve

C++: bool VideoCapture::retrieve(Mat& image, int channel=0);

功能:解码并且返回刚刚抓取的视频帧,假如没有视频帧被捕获(相机没有连接或者视频文件中没有更多的帧)将返回false


7、VideoCapture::set

bool VideoCapture::set(int propertyId, double value)

功能:设置VideoCapture类的属性,设置成功返回ture,失败返回false

参数:第一个属性ID,第二个该属性要设置的值


8、VideoCapture::get

double VideoCapture::get(int propID)

功能:一个视频有很多属性,比如:帧率、总帧数、尺寸和格式等,VideoCapture::get方法

可以获取这些属性


9、VideoCapture::read

    (1)VideoCapture& VideoCapture::operator>>(Mat& image)

    (2)bool VideoCapture::read(Mat& image);

功能:该函数结合VideoCapture::grab()和VideoCapture::retrieve()其中之一被调用,

用于捕获、解码和返回下一个视频帧这是一个最方便的函数对于读取视频文件或者

捕获数据从解码和返回刚刚铺货的帧,假如没有视频帧被捕获(相机没有连接或者视频文件中

没有更多帧)将返回false。



猜你喜欢

转载自blog.csdn.net/xueluowutong/article/details/80953047