话不多说,直接上代码
#include <math.h>
#include "opencv2/highgui.hpp"
#include <opencv2/highgui/highgui_c.h>
using namespace std;
using namespace cv;
int main()
{
Mat img1 = imread("图片1.jpg");
Mat img2 = imread("图片2.jpg");
Mat combine, result;
int addWeight = abs(img1.cols - img2.cols);
int addHeight = abs(img1.rows - img2.rows);
Mat addImg;
if (img1.rows >= img2.rows)
{
addImg = Mat::zeros(addHeight, img2.cols, CV_8UC3);
vconcat(img2, addImg, combine);
hconcat(img1, combine, result);
}
else
{
addImg = Mat::zeros(addHeight, img1.cols, CV_8UC3);
vconcat(img1, addImg, combine);
hconcat(combine, img2, result);
}
imshow("结果", result);
waitKey();
system("pause");
return 0;
}