赞
踩
- #include "opencv2/core/core.hpp"
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
-
- using namespace cv;
-
- int main(int argc, char **argv)
- {
- Mat img_left = imread("church01.jpg");
- Mat img_right = imread("church02.jpg");
-
- Size size(img_left.cols + img_right.cols, MAX(img_left.rows, img_right.rows));
-
- Mat img_merge;
- Mat outImg_left, outImg_right;
-
- img_merge.create(size, CV_MAKETYPE(img_left.depth(), 3));
- img_merge = Scalar::all(0);
- outImg_left = img_merge(Rect(0, 0, img_left.cols, img_left.rows));
- outImg_right = img_merge(Rect(img_left.cols, 0, img_right.cols, img_right.rows));
-
- if(img_left.type() == CV_8U)
- {
- cvtColor(img_left, outImg_left, CV_GRAY2BGR);
- }
- else
- {
- img_left.copyTo(outImg_left);
- }
-
- if(img_right.type() == CV_8U)
- {
- cvtColor(img_right, outImg_right, CV_GRAY2BGR);
- }
- else
- {
- img_right.copyTo(outImg_right);
- }
-
- imshow("merge", img_merge);
- imwrite("merge.jpg", img_merge);
-
- waitKey(0);
- return 0;
- }

练习用的图像分别为
church01.jpg:
church02.jpg:
运行得到的结果为:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。