本文主要是介绍opencv c++ 调整亮度与对比度,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include<opencv2\opencv.hpp>
#include
#include<math.h>
using namespace cv;
int main()
{
Mat dst,m1;
Mat src = imread(“C:/Users/asus/Desktop/tupian/1.jpg”);
if (!src.data)
{
printf(“could not load image…\n”);
return -1;
}
char input_image[] = “input_image”;
namedWindow(input_image, 1);
imshow(input_image, src);
int height = src.rows;
int width = src.cols;
dst = Mat::zeros(src.size(), src.type());
float alpha = 1.2;
float beta = 30;src.convertTo(m1, CV_32F);
for (int row = 0; row<height; row++)
{for (int col = 0; col<width; col++){if (src.channels() == 1){float v = src.at<uchar>(row, col);dst.at<uchar>(row, col) = saturate_cast<uchar>(v*alpha + beta);}if (src.channels() == 3){float b= m1.at<Vec3f>(row, col)[0];float g = m1.at<Vec3f>(row, col)[1];float r = m1.at<Vec3f>(row, col)[2];dst.at<Vec3b>(row, col)[0] = saturate_cast<uchar>(b*alpha + beta);dst.at<Vec3b>(row, col)[1] = saturate_cast<uchar>(g*alpha + beta);dst.at<Vec3b>(row, col)[2] = saturate_cast<uchar>(r*alpha + beta);}}
}
imshow("out _image", dst);
waitKey(0);
return 0;
}
这篇关于opencv c++ 调整亮度与对比度的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!