zoukankan      html  css  js  c++  java
  • 图像对比度、亮度值调整

     1 #include<opencv2/opencv.hpp>
     2 #include<iostream>
     3 
     4 using namespace std;
     5 using namespace cv;
     6 
     7 static void on_ContrastAndBright(int, void *);
     8 static void ShowHelpText();
     9 
    10 int g_nContrastValue;   //对比度值
    11 int g_nBrightValue;    //亮度值
    12 Mat g_srcImage, g_dstImage;
    13 
    14 int main() {
    15     //读取输入图像
    16     g_srcImage = imread("C:\Users\Nelsoner\Desktop\Camera Roll\05.jpg");
    17     g_dstImage = Mat::zeros(g_srcImage.size(), g_srcImage.type());
    18 
    19     //设定对比度和亮的初值
    20     g_nContrastValue = 80;
    21     g_nBrightValue = 80;
    22 
    23 
    24 
    25     //窗口
    26     namedWindow("【效果图】", 1);
    27 
    28     //创建滑块
    29     createTrackbar("对比度:", "【效果图】", &g_nContrastValue, 300, on_ContrastAndBright);
    30     createTrackbar("亮  度:", "【效果图】", &g_nBrightValue, 200, on_ContrastAndBright);
    31 
    32     //进行回调函数的初始化
    33     on_ContrastAndBright(g_nContrastValue, 0);
    34     on_ContrastAndBright(g_nBrightValue, 0);
    35 
    36     waitKey();
    37     return  0;
    38 }
    39 
    40 static void on_ContrastAndBright(int, void *) {
    41     //创建窗口
    42     namedWindow("【原始图窗口】", 1);
    43     //三个for循环,执行运算g_dstImage(i,j) = a*g_srcImage(i,j) +b
    44     for (int y = 0; y < g_srcImage.rows; y++) {
    45         for (int x = 0; x < g_srcImage.cols; x++) {
    46             for (int c = 0; c < 3; c++) {
    47                 g_dstImage.at<Vec3b>(y, x)[c] = saturate_cast<uchar>((g_nContrastValue*0.01)*(g_srcImage.at<Vec3b>(y, x)[c]) + g_nBrightValue);
    48             }
    49         }
    50     }
    51 
    52     //显示图像
    53     imshow("【原始图窗口】", g_srcImage);
    54     imshow("【效果图】", g_dstImage);
    55 }

  • 相关阅读:
    关于java.lang.OutOfMemoryError: Java heap space的错误分析
    对TCP/IP网络协议的深入浅出归纳
    leetcode面试准备:Contains Duplicate I && II
    leetcode面试准备:Count Complete Tree Nodes
    leetcode面试准备: Jump Game II
    leetcode面试准备: Jump Game
    LeetCode解题报告:Linked List Cycle && Linked List Cycle II
    最小栈的实现与优化
    面试:归并排序
    leetcode面试准备:Decode Ways
  • 原文地址:https://www.cnblogs.com/Nelsoner/p/6769999.html
Copyright © 2011-2022 走看看