對比調節,亮度調節。

來源:互聯網
上載者:User

標籤:

 1 #include <iostream>
 2 #include <opencv2/opencv.hpp>
 3 using namespace std;
 4 using namespace cv;
 5 //--------------------聲明全域函數---------------------------------
 6 static void on_ContrastAndBright(int, void*);
 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 }

 

對比調節,亮度調節。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.