添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
想出家的萝卜  ·  Vlog装备 ...·  9 月前    · 
憨厚的水煮肉  ·  汽车频道·  1 年前    · 
正直的桔子  ·  领袖水准 - 知乎·  1 年前    · 
1 capture.set(CV_CAP_PROP_FRAME_WIDTH, 1080);//宽度 
2 capture.set(CV_CAP_PROP_FRAME_HEIGHT, 960);//高度
3 capture.set(CV_CAP_PROP_FPS, 30);//帧率 帧/秒
4 capture.set(CV_CAP_PROP_BRIGHTNESS, 1);//亮度 1
5 capture.set(CV_CAP_PROP_CONTRAST,40);//对比度 40
6 capture.set(CV_CAP_PROP_SATURATION, 50);//饱和度 50
7 capture.set(CV_CAP_PROP_HUE, 50);//色调 50
8 capture.set(CV_CAP_PROP_EXPOSURE, 50);//曝光 50

获取摄像头参数

1 capture.get(CV_CAP_PROP_FRAME_WIDTH);
2 capture.get(CV_CAP_PROP_FRAME_HEIGHT);
3 capture.get(CV_CAP_PROP_FPS);
4 capture.get(CV_CAP_PROP_BRIGHTNESS);
5 capture.get(CV_CAP_PROP_CONTRAST);
6 capture.get(CV_CAP_PROP_SATURATION);
7 capture.get(CV_CAP_PROP_HUE);
8 capture.get(CV_CAP_PROP_EXPOSURE);
  1 /**
  2 @brief       OpenCV摄像头和视频属性操作
  3 @author      
  4 @copyright    -
  5 @version     1.0
  6 @data        
  7 @note        -
  8 */
  9 #include <iostream>
 10 #include "opencv2/opencv.hpp"
 12 using namespace std;
 13 using namespace cv;
 15 const string window_name = "用户界面";
 17 #define USE_CAMERA
 18 //#define USE_VIDEO
 20 int main()
 21 {
 22     Mat frame;
 24     double brightness = 0;        //亮度
 25     double contrast = 0;        //对比度
 26     double saturation = 0;        //饱和度
 27     double hue = 0;                //色调
 28     double gain = 0;            //增益
 29     double exposure = 0;        //曝光
 30     double white_balance = 0;    //白平衡
 32     double pos_msec = 0;        //当前视频位置(ms)
 33     double pos_frame = 0;        //从0开始下一帧的索引
 34     double pos_avi_ratio = 0;    //视频中的相对位置(范围为0.0到1.0)
 35     double frame_width = 0;        //视频帧的像素宽度
 36     double frame_height = 0;    //视频帧的像素高度
 37     double fps = 0;                //帧速率
 38     double frame_count = 0;        //视频总帧数
 39     double video_duration = 0.00;    //视频时长
 40     double format = 0;            //格式
 42 #ifdef USE_VIDEO
 43     const string file_name = "201910915314.avi";
 44     VideoCapture capture(file_name);
 46     frame_width = capture.get(cv::CAP_PROP_FRAME_WIDTH);
 47     frame_height = capture.get(cv::CAP_PROP_FRAME_HEIGHT);
 48     fps = capture.get(cv::CAP_PROP_FPS);
 49     frame_count = capture.get(cv::CAP_PROP_FRAME_COUNT);
 50     format = capture.get(cv::CAP_PROP_FORMAT);
 51     pos_avi_ratio = capture.get(cv::CAP_PROP_POS_AVI_RATIO);
 52     video_duration = frame_count / fps;
 54     cout << "---------------------------------------------" << endl;
 55     cout << "视频中的相对位置(范围为0.0到1.0):" << pos_avi_ratio << endl;
 56     cout << "视频帧的像素宽度:" << frame_width << endl;
 57     cout << "视频帧的像素高度:" << frame_height << endl;
 58     cout << "录制视频的帧速率(帧/秒):" << fps << endl;
 59     cout << "视频文件总帧数:" << frame_count << endl;
 60     cout << "图像的格式:" << format << endl;
 61     cout << "视频时长:" << video_duration << endl;
 62     cout << "---------------------------------------------" << endl;
 63 #endif // USE_VIDEO
 65 #ifdef USE_CAMERA
 66     VideoCapture capture(0);
 67     brightness = capture.get(cv::CAP_PROP_BRIGHTNESS);
 68     contrast= capture.get(cv::CAP_PROP_CONTRAST);
 69     saturation = capture.get(cv::CAP_PROP_SATURATION);
 70     hue = capture.get(cv::CAP_PROP_HUE);
 71     gain = capture.get(cv::CAP_PROP_GAIN);
 72     exposure = capture.get(cv::CAP_PROP_EXPOSURE);
 73     white_balance = capture.get(cv::CAP_PROP_WHITE_BALANCE_BLUE_U);
 75     std::cout << "---------------------------------------------" << endl;
 76     std::cout << "摄像头亮度:" << brightness << endl;
 77     std::cout << "摄像头对比度:" << contrast << endl;
 78     std::cout << "摄像头饱和度:" << saturation << endl;
 79     std::cout << "摄像头色调:" << hue << endl;
 80     std::cout << "摄像头增益:" << gain << endl;
 81     std::cout << "摄像头曝光度:" << exposure << endl;
 82     std::cout << "摄像头白平衡:" << white_balance << endl;
 83     std::cout << "---------------------------------------------" << endl;
 84 #endif // USE_CAMERA
 86     namedWindow(window_name,WINDOW_AUTOSIZE);
 87     while (capture.isOpened())
 88     {
 89         capture >> frame;
 91 #ifdef USE_VIDEO
 92         pos_msec = capture.get(cv::CAP_PROP_POS_MSEC);
 93         pos_frame = capture.get(cv::CAP_PROP_POS_FRAMES);
 94         pos_avi_ratio = capture.get(cv::CAP_PROP_POS_AVI_RATIO);
 95         cout << "---------------------------------------------" << endl;
 96         cout << "视频文件中当前位置(ms):" << pos_msec << endl;
 97         cout << "从0开始下一帧的索引:" << pos_frame << endl;
 98         cout << "视频中的相对位置(范围为0.0到1.0):" << pos_avi_ratio << endl;
 99         cout << "---------------------------------------------" << endl;
100 #endif // USE_VIDEO
102         imshow(window_name, frame);
103         if (waitKey(60)==27)
104         {
105             break;
106         }
107     }
108     capture.release();
109     destroyAllWindows();
110     return 0;
111 }

打印结果: