今天参照Opencv的官方文档写了一个将两幅图片进行线性混叠的程序,并且使用了滑动条来实现混叠的参数alpha,下面是代码:
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
const int slide_value_max=100;
Mat src1,src2,dst;
void on_trackbar(int slide_alpha,void *)
{
double alpha= (double)slide_alpha/slide_value_max;
double beta=1.0-alpha;
addWeighted(src1,alpha,src2,beta,0.0,dst);
imshow("Linear Blend",dst);
}
int main(int argc, char **argv)
{
src1=imread("LinuxLogo.jpg");
src2=imread("WindowsLogo.jpg");//src1 and src2 must be the same size
if(!src1.data || !src2.data)
{
cerr<<"error in loading picture"<<endl;
system("pause");
exit(-1);
}
namedWindow("Linear Blend",0);
int slide_alpha=0;
char TrackbarName[MAX_PATH];
sprintf(TrackbarName,"Trackbar:%d",slide_alpha);
createTrackbar(TrackbarName,"Linear Blend",&slide_alpha,slide_value_max,on_trackbar);
on_trackbar(slide_alpha,0);
waitKey(0);
return 0;
}
- 1
参考链接:http://docs.opencv.org/doc/tutorials/highgui/trackbar/trackbar.html#adding-trackbars`