get
原型: CV_WRAP virtual double get(int propId) const
说明:
参数: propId, 用一个枚举值来表示,标识想要获取的属性的类型。
返回值:返回你想要的结果。
几个经常获取的属性:
CAP_PROP_FRAME_WIDTH:视频帧的宽度
CAP_PROP_FRAME_HEIGHT :视频帧的高度
CAP_PROP_FPS:视频帧率(fps)
CAP_PROP_FRAME_COUNT : 一个视频中帧的总数
CAP_PROP_BRIGHTNESS :图像亮度(针对支持这一特性的相机)
CAP_PROP_CONTRAST: 对比度(针对相机)
CAP_PROP_SATURATION: 饱和度 (针对相机)
。。。。。
代码演示
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
VideoCapture cam(0);
if (!cam.isOpened()) {
cout << " cam open failed " << endl;
getchar();
return -1;
}
cout << " cam open success. " << endl;
int fps = cam.get(CAP_PROP_FPS);
int width = cam.get(CAP_PROP_FRAME_WIDTH);
int height = cam.get(CAP_PROP_FRAME_HEIGHT);
int brightness = cam.get(CAP_PROP_BRIGHTNESS);
int contrast = cam.get(CAP_PROP_CONTRAST);
int saturation = cam.get(CAP_PROP_SATURATION);
cout << "fps: " << fps << endl;
cout << "width: " << width << endl;
cout << "height" << height << endl;
cout << "brightness" << brightness << endl;
cout << "contrast" << contrast << endl;
cout << "saturation" << saturation << endl;
return 0;
}
说明
(1)演示代码中代开的视频设备是摄像头;
(2)摄像头打开后获取的fps为0,如果打开的是视频文件,就能获取视频的fps;、
(3)获取了摄像头的亮度,对比度和饱和度,如果打开的是视频文件,则不会有这些信息哦。