这里主函数要使用ROI函数和addWeigth函数来实现
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img1 = imread("1.jpg");
if (!img1.data)
{
cout << "oh,no.open failure" << endl;
}
//namedWindow("picture1", WINDOW_AUTOSIZE);
//namedWindow("picture2", WINDOW_AUTOSIZE);
//imshow("picture1", img1);
Mat img2 = imread("2.jpg");
//cvtColor(img1, img2, CV_RGB2GRAY);
//imshow("picture2", img2);
//新建一个名为expanded的Mat容器。高度和img1相同,宽度为两倍
Mat expanded(Size(img1.cols+img2.cols,img1.rows),CV_8UC3);//图像色彩一致
cout << "expanded.cols" << expanded.cols << endl;
cout << "expanded.rows" << expanded.rows << endl;
Mat ROI = expanded(Rect(0, 0, img1.cols, img1.rows));//从坐标原点开始输入第一幅图
cout << "ROI.cols" << ROI.cols << endl;
cout << "ROI.rows" << ROI.rows << endl;
Mat ROI1 = expanded(Rect(img1.cols, 0, img2.cols, img2.rows));//接第幅图之后显示第二幅图
cout << "ROI1.cols" << ROI1.cols << endl;
cout << "ROI1.rows" << ROI1.rows << endl;
addWeighted(ROI, 0, img1, 1, 0., ROI);
addWeighted(ROI1, 0, img2, 1, 0., ROI1);
namedWindow("muldisplay", WINDOW_NORMAL);//正常显示才能完整显示
imshow("muldisplay", expanded);
waitKey(0);
return 0;
}
opencv中不同与matlab可以直接调用subplot实现多幅图像在同一窗口的显示。