#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
//a控制对比度,b控制亮度
void bright(Mat &srcImage, double a, double b);
int main()
{
Mat srcImage = imread("group.jpg");
imshow("【原图】", srcImage);
bright(srcImage, 0.5, 10);
imshow("【处理后的图像】", srcImage);
waitKey(0);
return 0;
}
void bright(Mat &srcImage, double a, double b)
{
const int imageRows = srcImage.rows;
const int imageCols = srcImage.cols * srcImage.channels();
for (int i = 0; i < imageRows; i++)
{
uchar *data = srcImage.ptr<uchar>(i);
for (int j = 0; j < imageCols; j++)
{
data[j] = saturate_cast<uchar>(a * data[j] + b);
}
}
}