#include <iostream>
#include <opencv2/opencv.hpp>
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("C:/Users/csh/Desktop/1.jpg");
g_dstImage = Mat::zeros(g_srcImage.size(), g_srcImage.type());
g_nContrastValue = 80;
g_nBrightValue = 80;//设置对比度和亮度的初值
namedWindow("效果图", 1);
createTrackbar("对比度", "效果图", &g_nContrastValue,300,on_ContrastAndBright);
createTrackbar("亮度", "效果图", &g_nBrightValue,200,on_ContrastAndBright);//创建轨迹条
on_ContrastAndBright(g_nContrastValue, 0);
on_ContrastAndBright(g_nBrightValue, 0);//进行回调函数初始化
while(char(waitKey(1))!='q'){}//按下q键程序退出
return 0;
}
static void on_ContrastAndBright(int, void*)
{
for (int x = 0; x < g_srcImage.rows; x++)
{
for (int y = 0; y < g_srcImage.cols; y++)
{
for (int c = 0; c < 3; c++)
{
g_dstImage.at<Vec3b>(x, y)[c] = saturate_cast<uchar>((g_nContrastValue*0.01)*(g_srcImage.at<Vec3b>(x, y)[c]) + g_nBrightValue);
}
}
}
imshow("效果图", g_dstImage);
}
opencv-图像对比度,亮度值调整
最新推荐文章于 2024-06-17 10:13:17 发布