opencv开发笔记(十):利用轨迹条调整图像对比度和亮度

// 利用轨迹条调整图像对比度和亮度.cpp : 定义控制台应用程序的入口点。

#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
void onconst(int, void*);
int g_nl;//对比度
int g_cl;//亮度值
Mat src, dst;
int main()
{
src = imread("E:\\Pictures\\1.jpg");
dst = Mat::zeros(src.size(),src.type());
//设置对比度
g_nl = 80;
g_cl = 80;
namedWindow("效果窗口",1);
//创建轨迹条
createTrackbar("对比度","效果窗口",&g_nl,300,onconst);
createTrackbar("亮度","效果窗口", &g_cl, 200, onconst);
//回调函数初始化
onconst(g_nl,0);
onconst(g_cl,0);
while(char(waitKey(1) )!= 'q'){}
    return 0;
}
void onconst(int,void*) {
namedWindow("原始窗口", 1);
// 三个for循环,执行运算 g_dstImage(i,j) = a*g_srcImage(i,j) + b 调整对比度和亮度的公式
for (int y = 0; y < src.rows; y++)
{
for (int x = 0; x < src.cols; x++)
{
for (int c = 0; c < 3; c++)
{
dst.at<Vec3b>(y, x)[c] = saturate_cast<uchar>((g_nl*0.01)*(src.at<Vec3b>(y, x)[c]) + g_cl);
}
}
}

// 显示图像
imshow("【原始图窗口】", src);
imshow("【效果图窗口】", dst);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值