opencv笔记6-滚动条操作

滚动条操作

#include
#include

using namespace std;
using namespace cv;

//Mat temp, m, dst;
//int lightness = 50;

static void on_track(int lightness, void*userdata)
{
	/*m = Scalar(lightness, lightness, lightness);
	add(temp, m, dst);
	subtract(temp, m, dst);*/
	Mat image = *((Mat*)userdata);
	Mat dst = Mat::zeros(image.size(), image.type());
	Mat m = Mat::zeros(image.size(), image.type());
	m = Scalar(lightness, lightness, lightness);
	add(image, m, dst);
	subtract(image, m, dst);
	imshow("亮度调整", dst);
}

//滚动条操作
void tracking_bar_demo(Mat& image)
{
	namedWindow("亮度调整",WINDOW_FREERATIO);
	/*dst = Mat::zeros(image.size(), image.type());
    m = Mat::zeros(image.size(), image.type());
	temp = image;*/
	int max_value = 100;//亮度最大值
	int lightness = 50;//亮度初始值
	//调整亮度滚动条的创建
	createTrackbar("亮度值:", "亮度调整", &lightness, max_value, on_track,(void*)&image);
	on_track(lightness,&image);
}

int main()
{
	string path = "C:\\Users\\四明\\Pictures\\QQ图片20200608155343.jpg";
	Mat img = imread(path);
	if (img.empty())
	{
		cout << "加载图片失败!" << endl;
		return -1;
	}
	namedWindow("image", WINDOW_FREERATIO);
	imshow("image", img);
	tracking_bar_demo(img);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

效果图
opencv笔记6-滚动条操作_第1张图片

你可能感兴趣的:(opencv笔记,笔记,c++,opencv)