图像拼接的opencv、c++代码
这里提供一个简单的图像拼接的OpenCV和C++代码示例。
首先,我们需要包含OpenCV库的头文件和命名空间:
#include <opencv2/opencv.hpp>
using namespace cv;
接下来,我们定义一个函数,将两个输入图像水平拼接为一个输出图像:
Mat joinImages(Mat image1, Mat image2) {
int rows = max(image1.rows, image2.rows);
int cols = image1.cols + image2.cols;
Mat result(rows, cols, image1.type());
// Copy image1 to the left side of the result
Mat left(result, Rect(0, 0, image1.cols, image1.rows));
image1.copyTo(left);
// Copy image2 to the right side of the result
Mat right(result, Rect(image1.cols, 0, image2.cols, image2.rows));
image2.copyTo(right);
return result;
}
接下来,我们可以读取两个输入图像,然后调用我们的函数来生成拼接图像:
int main() {
// Read input images
Mat image1 = imread("image1.jpg");
Mat image2 = imread("image2.jpg");
// Join the images horizontally
Mat result = joinImages(image1, image2);
// Display the result
imshow("Result", result);
waitKey(0);
return 0;
}
这个简单的示例演示了如何使用OpenCV和C++对图像进行拼接。当然,这只是一个简单的示例,您可以根据需要进行更改和扩展。
原文地址: https://www.cveoy.top/t/topic/bCmn 著作权归作者所有。请勿转载和采集!