white balance 白平衡调整

版权声明:https://blog.csdn.net/CAIYUNFREEDOM https://blog.csdn.net/CAIYUNFREEDOM/article/details/90439713

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;
}

猜你喜欢

转载自blog.csdn.net/CAIYUNFREEDOM/article/details/90439713