opencv 图像对比度及亮度调整

#include
#include
#include
#include
using namespace cv;
using namespace std;
static void on_ContrastAndBright(int ,void*);
int g_nContrastValue;
int g_nBrightValue;
Mat  g_srcImage,g_dstImage;
int main()
{
g_srcImage = imread("1.jpg");
if(!g_srcImage.data)
{
printf("reas jpg error\n");
return -1;
}
g_dstImage = Mat::zeros(g_srcImage.size(),g_srcImage.type());
g_nBrightValue =80;
g_nContrastValue = 80;
namedWindow("yunxingtu",WINDOW_AUTOSIZE);
createTrackbar("Contrast","yunxingtu",&g_nContrastValue,300,on_ContrastAndBright);
createTrackbar("Bright","yunxingtu",&g_nBrightValue,200,on_ContrastAndBright);
on_ContrastAndBright(g_nContrastValue ,0);
on_ContrastAndBright(g_nBrightValue,0);
while(char(waitKey(1)) != 'g')
{
}
return 0;

waitKey(0);
}
static void on_ContrastAndBright(int ,void*)
{
namedWindow("yuantu",WINDOW_AUTOSIZE);
for(int y =0 ; y < g_srcImage.rows; y++)

for(int x = 0; x < g_srcImage.cols ; x++)
{
for(int c = 0; c < 3; c++)
{
g_dstImage.at(y,x)[c] = saturate_cast < uchar >((g_nContrastValue *0.01)*(g_srcImage.at(y,x)[c])+g_nBrightValue);
}
}
}
imshow("yuantu",g_srcImage);
imshow("yunxingtu",g_dstImage);

}

运行效果如下

opencv 图像对比度及亮度调整_第1张图片

你可能感兴趣的