毛星云opencv之5.2.4初级图像混合
Posted 爱雨天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了毛星云opencv之5.2.4初级图像混合相关的知识,希望对你有一定的参考价值。
#include <opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include"opencv2/highgui/highgui.hpp"
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
bool ROI_AddImage();
bool LinearBlending();
bool ROI_LinearBlending();
int main()
{
system("color 5E");
if (ROI_AddImage() && LinearBlending() && ROI_LinearBlending())
{
cout << endl << "运行成功,得出图像:)";
}
waitKey(0);
return 0;
}
bool ROI_AddImage()
{
Mat srcImage1 = imread("C:/Users/离子键/source/repos/Project8/1.jpg");
Mat logoImage = imread("C:/Users/离子键/source/repos/Project8/3.jpg");
if (!srcImage1.data) { printf("读取srcImage1错误!\\n"); return false; }
if (!logoImage.data) { printf("读取logoImage错误!\\n"); return false; }
Mat imageROI = srcImage1(Rect(0, 0, logoImage.cols, logoImage.rows));
Mat mask = imread("C:/Users/离子键/source/repos/Project8/3.jpg", 0);
logoImage.copyTo(imageROI,mask);
namedWindow("<1>利用ROI实现图像叠加示例窗口");
imshow("<1>利用ROI实现图像叠加示例窗口", srcImage1);
return true;
}
bool LinearBlending()
{
double alphaValue = 0.5;
double betaValue;
Mat srcImage2, srcImage3, dstImage;
srcImage2 = imread("C:/Users/离子键/source/repos/Project8/1.jpg");
srcImage3 = imread("C:/Users/离子键/source/repos/Project8/3.jpg");
if (!srcImage2.data) { printf("读取srcImage2错误!\\n"); return false; }
if (!srcImage3.data) { printf("读取srcImage3错误!\\n"); return false; }
betaValue = (1.0-alphaValue);
addWeighted(srcImage2, alphaValue, srcImage3, betaValue, 0.0, dstImage);
namedWindow("<2>线性混合示例窗口[原图]", 1);
imshow("<2>线性混合示例窗口[原图]",srcImage2);
namedWindow("<3>线性混合示例窗口[效果图]", 1);
imshow("<3>线性混合示例窗口[效果图]", dstImage);
return true;
}
bool ROI_LinearBlending()
{
Mat srcImage4 = imread("C:/Users/离子键/source/repos/Project8/1.jpg");
Mat logoImage = imread("C:/Users/离子键/source/repos/Project8/3.jpg");
if (!srcImage4.data) { printf("读取srcImage4错误!\\n"); return false; }
if (!logoImage.data) { printf("读取logoImage错误!\\n"); return false; }
Mat imageROI;
imageROI = srcImage4(Rect(0, 0, logoImage.cols, logoImage.rows));
addWeighted(imageROI, 0.5, logoImage, 0.3,0., imageROI);
namedWindow("<4>区域线型图象混合示例窗口");
imshow("<4>区域线型图象混合示例窗口",srcImage4);
return true;
}
运行结果如下:
以上是关于毛星云opencv之5.2.4初级图像混合的主要内容,如果未能解决你的问题,请参考以下文章
图像识别——《OpenCV3编程入门-毛星云》第三部分 掌握imgproc组件
图像识别——《OpenCV3编程入门-毛星云》第一部分 快速上手OpenCV