#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
Mat srcImage1, srcImage2, dstImage;
int g_nAlphaValueSlider = 0;
const int g_nMaxAlphaValue = 100;
Mat imageROI;
Mat logo;
Mat Roi;
void on_Trackbar(int, void *)
{
double alphaValue = g_nAlphaValueSlider / 100.0;
double betaValue;
betaValue = 1 - alphaValue;
//addWeighted的两幅输入图像一定不能变
addWeighted(Roi, alphaValue, logo, betaValue, 0.0, imageROI);
imshow("【加权后的值】", srcImage2);
}
int main()
{
srcImage1 = imread("【原图】.jpg");
srcImage2 = imread("yemu.jpg");
logo = imread("sun.jpg");
dstImage.create(srcImage1.size(), srcImage1.type());
imageROI = srcImage2(Rect(0, 0, logo.cols, logo.rows));
imageROI.copyTo(Roi);
namedWindow("窗口");
moveWindow("窗口", 0, 0);
namedWindow("【加权后的值】");
moveWindow("【加权后的值】", 325, 0);
g_nAlphaValueSlider = 50;
createTrackbar("比例", "窗口", &g_nAlphaValueSlider, g_nMaxAlphaValue, on_Trackbar);
on_Trackbar(g_nAlphaValueSlider, 0);
waitKey(0);
return 0;
}
Opencv初级图像混合
最新推荐文章于 2024-08-22 22:46:32 发布