white balance 白平衡调整

28 篇文章 0 订阅

white balance

 

#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>
#include <iomanip>

using namespace cv;
using namespace std;

int main() {
	VideoCapture v(0);
	Mat imageSource = imread("02.jpg");
	while (1) {

		v >> imageSource;
		imshow("原始图像", imageSource);
		vector<Mat> imageRGB;

		//RGB三通道分离
		split(imageSource, imageRGB);

		//求原始图像的RGB分量的均值
		double R, G, B;
		B = mean(imageRGB[0])[0];
		G = mean(imageRGB[1])[0];
		R = mean(imageRGB[2])[0];

		//需要调整的RGB分量的增益
		double KR, KG, KB;
		KB = (R + G + B) / (3 * B);
		KG = (R + G + B) / (3 * G);
		KR = (R + G + B) / (3 * R);

		//调整RGB三个通道各自的值
		imageRGB[0] = imageRGB[0] * KB;
		imageRGB[1] = imageRGB[1] * KG;
		imageRGB[2] = imageRGB[2] * KR;

		//RGB三通道图像合并
		merge(imageRGB, imageSource);
		imshow("白平衡调整后", imageSource);
		waitKey(10);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值