最全OpenCV设置和获取摄像头参数_opencv 设置摄像头 对比度,2024年最新C C++应用性能优化

avatar
作者
猴君
阅读量:4

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

capture.get(CV_CAP_PROP_EXPOSURE);

     ### 获取视频参数     ---    

capture.get(CV_CAP_PROP_FRAME_COUNT);//视频帧数

 ####    #### 源代码    

/**
@brief OpenCV摄像头和视频属性操作
@author xiaolei
@copyright -
@version 1.0
@data 2019/10/12
@note -
*/
#include
#include “opencv2/opencv.hpp”

using namespace std;
using namespace cv;

const string window_name = “用户界面”;

#define USE_CAMERA
//#define USE_VIDEO

int main()
{
Mat frame;

double brightness = 0;		//亮度 double contrast = 0;		//对比度 double saturation = 0;		//饱和度 double hue = 0;				//色调 double gain = 0;			//增益 double exposure = 0;		//曝光 double white_balance = 0;	//白平衡  double pos_msec = 0;		//当前视频位置(ms) double pos_frame = 0;		//从0开始下一帧的索引 double pos_avi_ratio = 0;	//视频中的相对位置(范围为0.0到1.0) double frame_width = 0;		//视频帧的像素宽度 double frame_height = 0;	//视频帧的像素高度 double fps = 0;				//帧速率 double frame_count = 0;		//视频总帧数 double video_duration = 0.00;	//视频时长 double format = 0;			//格式 

#ifdef USE_VIDEO
const string file_name = “201910915314.avi”;
VideoCapture capture(file_name);

frame_width = capture.get(cv::CAP_PROP_FRAME_WIDTH); frame_height = capture.get(cv::CAP_PROP_FRAME_HEIGHT); fps = capture.get(cv::CAP_PROP_FPS); frame_count = capture.get(cv::CAP_PROP_FRAME_COUNT); format = capture.get(cv::CAP_PROP_FORMAT); pos_avi_ratio = capture.get(cv::CAP_PROP_POS_AVI_RATIO); video_duration = frame_count / fps;  cout << "---------------------------------------------" << endl; cout << "视频中的相对位置(范围为0.0到1.0):" << pos_avi_ratio << endl; cout << "视频帧的像素宽度:" << frame_width << endl; cout << "视频帧的像素高度:" << frame_height << endl; cout << "录制视频的帧速率(帧/秒):" << fps << endl; cout << "视频文件总帧数:" << frame_count << endl; cout << "图像的格式:" << format << endl; cout << "视频时长:" << video_duration << endl; cout << "---------------------------------------------" << endl; 

#endif // USE_VIDEO

#ifdef USE_CAMERA
VideoCapture capture(0);
brightness = capture.get(cv::CAP_PROP_BRIGHTNESS);
contrast= capture.get(cv::CAP_PROP_CONTRAST);
saturation = capture.get(cv::CAP_PROP_SATURATION);
hue = capture.get(cv::CAP_PROP_HUE);
gain = capture.get(cv::CAP_PROP_GAIN);
exposure = capture.get(cv::CAP_PROP_EXPOSURE);
white_balance = capture.get(cv::CAP_PROP_WHITE_BALANCE_BLUE_U);

std::cout << "---------------------------------------------" << endl; std::cout << "摄像头亮度:" << brightness << endl; std::cout << "摄像头对比度:" << contrast << endl; std::cout << "摄像头饱和度:" << saturation << endl; std::cout << "摄像头色调:" << hue << endl; std::cout << "摄像头增益:" << gain << endl; std::cout << "摄像头曝光度:" << exposure << endl; std::cout << "摄像头白平衡:" << white_balance << endl; std::cout << "---------------------------------------------" << endl; 

#endif // USE_CAMERA

namedWindow(window_name,WINDOW_AUTOSIZE); while (capture.isOpened()) { 	capture >> frame; 

#ifdef USE_VIDEO
pos_msec = capture.get(cv::CAP_PROP_POS_MSEC);
pos_frame = capture.get(cv::CAP_PROP_POS_FRAMES);

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!