01 - 添加进度条传递参数

 /***************************************************************
* @file		: main.cpp
* @brief	: main function
* @author	: YangL0322
* @version	: V.0.0.1
* @cnblogs	: httpswww.cnblogs.comkongqiweiliang
* @History	: modification - Date - Author - Information
*
**************************************************************/
#include 
#include
#include"opencv2/imgproc/imgproc.hpp"
#include 
  
using namespace std;
using namespace cv;
 
static void ContrastAndBright(int, void *);
 
int g_nContrastValue; //对比度值
int g_nBrightValue;	  //亮度值
Mat g_srcImage, g_dstImage;
 
int main()
{  
	//读入用户提供的图像
	g_srcImage = imread("1.jpg");
	g_dstImage = Mat::zeros(g_srcImage.size(), g_srcImage.type());

	//设定对比度和亮度的初值
	g_nContrastValue = 80;
	g_nBrightValue = 80;

	//创建窗口
	namedWindow("【效果图窗口】", 1);

	//创建轨迹条
	createTrackbar("对比度 :", "【效果图窗口】", &g_nContrastValue, 300, ContrastAndBright);
	createTrackbar("亮度:", "【效果图窗口】", &g_nBrightValue, 200, ContrastAndBright);

	//调用回调函数
	ContrastAndBright(g_nContrastValue, 0);
	ContrastAndBright(g_nBrightValue, 0);

	//按下“q”键时,程序退出
	while (char(waitKey(1)) != 'q') {}
	return 0;
}

static void ContrastAndBright(int, void *)
{
	namedWindow("【原始图窗口】", 1);

	//三个for循环,执行运算 g_dstImage(i,j) =a*g_srcImage(i,j) + b
	for (int y = 0; y < g_srcImage.rows; y++)
	{
		for (int x = 0; x < g_srcImage.cols; x++)
		{
			for (int c = 0; c < 3; c++)
			{
				g_dstImage.at<Vec3b>(y, x)[c] = saturate_cast<uchar>((g_nContrastValue*0.01)*(g_srcImage.at<Vec3b>(y, x)[c]) + g_nBrightValue);
			}
		}
	}
	//显示图像
	imshow("【原始图窗口】", g_srcImage);
	imshow("【效果图窗口】", g_dstImage);
}

你可能感兴趣的:(05,-,C图像算法实现)