opencv图像亮度调整

先上代码:

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int contrast = 300;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Mat srcImg = imread("../imgs/a.jpeg");
    namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
    imshow("Display Image", srcImg);

    Mat destImg = Mat::zeros(srcImg.size(), srcImg.type());

    for(int i =0; i < srcImg.rows; i++)
    {
        for(int j = 0; j < srcImg.cols; j++)
        {
            for(int c = 0 ; c < 3; c++)
            {
                destImg.at(i,j)[c] = srcImg.at(i,j)[c];
                destImg.at(i,j)[c] = \
                        saturate_cast(srcImg.at(i,j)[c] * contrast * 0.001);
            }
        }
    }

    namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
    imshow("Display Image", destImg);

    return a.exec();
}

他的本质上就是在修改图片上每个点的GBR值

你可能感兴趣的:(opencv,opencv学习)