对比度调节,亮度调节。

 1 #include <iostream>
 2 #include <opencv2/opencv.hpp>
 3 using namespace std;
 4 using namespace cv;
 5 //--------------------声明全局函数---------------------------------
 6 static void on_ContrastAndBright(intvoid*);
 7 //static void helphelp();
 8 //--------------------声明全局变量---------------------------------
 9 Mat srcImg;
10 Mat dstImg;
11 int g_Bright;
12 int g_Contrast;
13 //--------------------主函数入口-----------------------------------
14 int main()
15 {    
16     srcImg = imread("1.jpg");
17     if (!srcImg.data)
18         {
19             cout<<"0000"<<endl;
20         }
21     dstImg = Mat::zeros(srcImg.size(),srcImg.type());
22     namedWindow("stage2",1);
23     int g_Bright = 80;
24     int g_Contrst = 80;
25     namedWindow("stage",1);
26     //creat the Trackbar
27     createTrackbar("Contrast""stage2", &g_Contrast, 300, on_ContrastAndBright);
28     createTrackbar("Bright""stage2", &g_Bright, 250, on_ContrastAndBright);
29     on_ContrastAndBright(g_Contrst,0);
30     on_ContrastAndBright(g_Bright,0);
31     while (char(waitKey(1)) != 's'
32     {}
33     return 0;
34 }
35 static void on_ContrastAndBright(int,void*)
36 {
37     for(int i=0; i<srcImg.rows; i++)
38         {
39             for(int j=0; j<srcImg.cols; j++)
40             {
41                 for(int c=0; c<3; c++)
42                 {
43                     dstImg.at<Vec3b>(i,j)[c] = saturate_cast<uchar>( (g_Contrast * 0.01) * ( srcImg.at<Vec3b>(i,j)[c]) + g_Bright );
44                 }
45             }
46         }
47     imshow("stage",srcImg);
48     imshow("stage2",dstImg);
49 }

 

转载于:https://www.cnblogs.com/gyearth/p/4867202.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值