opencv - 如何拼接两个具有不同绝对坐标的图像?
问题描述
例如,缝合
first image
1 1 1
1 1 1
1 1 1
second image
2 2 2 2
2 2 2 2
2 2 2 2
and What I want
0 0 0 2 2 2 2
1 1 1 2 2 2 2
1 1 1 2 2 2 2
1 1 1 0 0 0 0
或者
1 1 1 0 0 0 0
1 1 1 2 2 2 2
1 1 1 2 2 2 2
0 0 0 2 2 2 2
在python中,这很容易像..
temp_panorama = np.zeros((1's height+abs(2's upper part length), 1's width+2's width))
temp_panorama[(2's upper part length) : 1's height, 0 : 1's width] = img1[:]
temp_panorama[0 : 2's height, 1's width +1 :] = img2[:, :]
但是如何在 C++ 的 opencv 中实现相同的功能呢?
解决方案
使用子图像:
// ROI where first image will be placed
cv::Rect firstROI = cv::Rect(x1,y2, first.cols, first.height);
cv::Rect secondROI = cv::Rect(x2,y2, second.cols, second.height);
// create an image big enought to hold the result
cv::Mat canvas = cv::Mat::zeros(cv::Size(std::max(x1+first.cols, x2+second.cols), std::max(y1+first.rows, y2+second.rows)), first.type());
// use subimages:
first.copyTo(canvas(firstROI));
second.copyTo(canvas(secondROI));
在你的例子中:
x1 = 0,
y1 = 1,
x2 = 3,
y2 = 0
first.cols == 3 first.rows == 3 second.cols == 4 second.rows == 3
推荐阅读
- android - 在我的应用中实现深色主题;不同活动的工具栏中显示不同的颜色
- python-3.x - 访问 DEAP 中的多个统计信息
- r - 如何为R中地图中的不同区域选择不同的主题
- django - 在 Django 中启动两个 http 服务器
- android - 更改下一个活动后应用程序崩溃问题?
- android - setTextAppearance - 尝试禁用单击时不适用于 MaterialButton
- mysql - 为什么 MariaDB 10.1.38 不创建表空间?
- python - 如果我想基于列来处理数据帧,我可以在函数 read_csv 中使用函数“排序依据”吗?
- java - 在我的登录函数中匹配数组列表第二个第三位的值时出错?
- reactjs - 如何在 Twilio Flex 网络聊天中保持聊天栏始终打开