openCV图像合成
2024-09-06 10:59:47
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/cvaux.hpp>
#include <fstream>
using namespace std;
using namespace cv; int main()
{
Mat image1=imread("/Users/war/Desktop/2.jpeg");
Mat image2=imread("/Users/war/Desktop/1.jpeg");
if (image1.empty() || image2.empty())
{
printf("open error");
return ;
}
//1.新建一个要合并的图像
Mat img_merge;
Size size(image1.cols + image2.cols, MAX(image1.rows, image1.rows));
img_merge.create(size, CV_MAKETYPE(image1.depth(), ));
img_merge = Scalar::all();
Mat outImg_left, outImg_right;
//2.在新建合并图像中设置感兴趣区域
outImg_left = img_merge(Rect(, , image1.cols, image1.rows));
outImg_right = img_merge(Rect(image1.cols, , image1.cols, image1.rows));
//3.将待拷贝图像拷贝到感性趣区域中
image1.copyTo(outImg_left);
image2.copyTo(outImg_right);
namedWindow("image1", );
imshow("image1", img_merge);
waitKey();
return ;
}
openCV图像合成
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/cvaux.hpp>
#include <fstream>
using namespace std;
using namespace cv; int main()
{
Mat image1=imread("/Users/war/Desktop/1.jpeg");
Mat image2=imread("/Users/war/Desktop/2.jpeg");
if (image1.empty() || image2.empty())
{
printf("open error");
return ;
}
//push_back 方法将图像2拷贝到图像1的最后一行
Mat img_merge;
img_merge.push_back(image1);
img_merge.push_back(image2); namedWindow("img_merge", );
imshow("img_merge", img_merge); waitKey();
return ;
}
//#include <cv.h>
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
//#include <highgui.h>
#include <iostream> using namespace cv;
using namespace std;
int main()
{
double alpha = 0.5; double beta; double input; Mat src1, src2, dst; cout << " Simple Linear Blender " <<endl;
cout << "-----------------------" << endl;
cout << "* Enter alpha [0-1]: ";
cin >> input;
if (input >= 0.0 && input <= 1.0)
{
alpha = input;
} /// Read image ( same size, same type ),注意,这里一定要相同大小,相同类型,否则出错
src1 = imread("/Users/war/Desktop/1.png");
src2 = imread("/Users/war/Desktop/2.png"); if (!src1.data) { printf("Error loading src1 \n"); return -; }
if (!src2.data) { printf("Error loading src2 \n"); return -; } /// Create Windows
namedWindow("Linear Blend", ); beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst); imshow("Linear Blend",dst); waitKey();
return ;
}
//#include <cv.h>
#include <opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
//#include <highgui.h>
#include <iostream> using namespace cv;
using namespace std;
int main()
{
double alpha = 0.5; double beta; double input; Mat src1, src2, dst; cout << " Simple Linear Blender " <<endl;
cout << "-----------------------" << endl;
cout << "* Enter alpha [0-1]: ";
cin >> input;
if (input >= 0.0 && input <= 1.0)
{
alpha = input;
} /// Read image ( same size, same type ),注意,这里一定要相同大小,相同类型,否则出错
src1 = imread("/Users/war/Desktop/1.png");
src2 = imread("/Users/war/Desktop/2.png"); if (!src1.data) { printf("Error loading src1 \n"); return -; }
if (!src2.data) { printf("Error loading src2 \n"); return -; } /// Create Windows
namedWindow("Linear Blend", ); beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst); imshow("Linear Blend",dst); waitKey();
return ;
}
最新文章
- oracle行转列与列转行
- git pull错误
- UpdateSourceTrigger Property in WPF Binding
- [AngularJS] jQuery时代
- MFC 修改 单文档 SDI 窗体 标题
- MyBatis 入门
- centos7 安装中文编码
- 【Unity3D】Unity3D之 Resources.Load 动态加载资源
- [转] error LNK2026: 模块对于 SAFESEH 映像是不安全的
- bzoj 1051: [HAOI2006]受欢迎的牛 tarjan缩点
- 【每周一译】愚蠢的指标:Java中使用最多的关键字
- Mac&;iOS Socket
- css和css3学习
- webpack 基本打包方法
- Python基础——字符串
- Vue结合slot插槽分发父组件内容实现高度复用、更加灵活的dialog组件
- Design Principles and Design Patterns
- TP5 生成二维码
- 自行实现高性能MVC
- UIKit&#160;框架之UIResponder
热门文章
- wpf 定时器应用,在界面动态刷新时间
- 历经小半宿吧。哎,终于搭建好了Linux-C的环境
- input光标使用caret-color改变颜色
- [记录]学习树莓派3B接DHT11和LCD1602和修改树莓派时区
- Atcoder arc085
- 从微服务治理的角度看RSocket、. Envoy和. Istio
- 18多校8th
- 19-10-27-S
- mysql插入数据显示:Incorrect datetime value: &#39;0000-00-00 00:00:00&#39;
- 大O法时间复杂度计算