#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<vector>
#include <iostream>
using namespace cv;
using namespace std;
Mat img1;
Mat img2;
int a;
int b;
void ContrastAndBright(int,void*)
{
namedWindow("原始图像",1);
for(int i=0;i<img1.rows;i++)
for(int j=0;j<img1.cols;j++)
for(int c=0;c<3;c++)
{
img2.at<Vec3b>(i,j)[c]=saturate_cast<uchar>(a*0.01*(img1.at<Vec3b>(i,j)[c])+b);
}
imshow("原始图像",img1);
imshow("效果图",img2);
imwrite("C://Users//huashuo111//Desktop//对比度.jpg",img2);
}
int main()
{
//system("color 5F");
const char* filename="C://Users//huashuo111//Desktop//星空.jpg";
img1=imread(filename,1);
img2=Mat::zeros(img1.size(),img1.type());
a=60;
b=80;
namedWindow("效果图",1);
createTrackbar("对比度","效果图",&a,300,ContrastAndBright);
createTrackbar("亮度","效果图",&b,200,ContrastAndBright);
ContrastAndBright(a,0);
ContrastAndBright(b,0);
waitKey();
return 0;
}
效果图: