OpenCV函数cvAddWeighted调整alpha和gamma值

创建两个trackerbar,一个用来调整alpha,一个用来调整gamma值。代码如下:

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#pragma comment(lib, "cv.lib")
#pragma comment(lib, "cxcore.lib")
#pragma comment(lib, "highgui.lib")

IplImage *srcImg = 0, *dstImg = 0;
int gAlpha = 50;
int gGamma = 0;

void on_change(int arg)
{
	// dstImg = alpha*src1 + beta*src2 + gamma
	cvAddWeighted(srcImg, (gAlpha / 50.0), srcImg, 0, gGamma, dstImg);
	cvShowImage("dst", dstImg);
}

int main(int argc, char* argv[])
{
	srcImg = cvLoadImage("D:\\Testing_Images\\view.png");
	dstImg = cvCreateImage(cvGetSize(srcImg), 8, 3);

	cvNamedWindow("src");
	cvShowImage("src", srcImg);
	// 创建trackbar: gAlpha=[0, 100], gGamma=[0, 100]
	cvCreateTrackbar("alpha", "src", &gAlpha, 100, on_change);
	cvCreateTrackbar("gamma", "src", &gGamma, 100, on_change);
	on_change(0);

	cvNamedWindow("dst");
	cvWaitKey(0);

	return 0;
}
演示结果如下:

你可能感兴趣的:(OpenCV函数cvAddWeighted调整alpha和gamma值)