"眼睛成長記"(四)—看我所想
- 2020 年 4 月 10 日
- 筆記
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)獲取了攝影機的亮度,對比度和飽和度,如果打開的是影片文件,則不會有這些資訊哦。