Opencv图像拼接融合(多波段融合)

3

我正在尝试使用OpenCV 3.2中的blender cv::detail::MultiBandBlender(位于#include "opencv2/stitching/detail/blenders.hpp")混合刚拼接在一起的图像中的接缝。根据我所了解,文档并不多,而且能找到的编码示例更少,但我设法找到了一个很好的博客,在此处解释了步骤。

当我运行我现有的代码时,我遇到以下错误:error:/opencv/modules/core/src/copy.cpp:1176: error: (-215) top >= 0 && bottom >= 0 && left >= 0 && right >= 0 in function copyMakeBorder

以下是混合的代码(假设已正确找到stitching、warpPerspective和homographies)

//Mask of iamge to be combined so you can get resulting mask
Mat mask1(image1.size(), CV_8UC1, Scalar::all(255));
Mat mask2(image2.size(), CV_8UC1, Scalar::all(255));
Mat image1Updated, image2Updated;
//Warp the masks and the images to their new posistions so their are of all the same  size to be overlayed and blended
warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));
warpPerspective(mask1, mask1, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(mask2, mask2, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));

//create blender
detail::MultiBandBlender blender(false, 5);
//feed images and the mask areas to blend
blender.feed(image1Updated, mask1, Point2f (0,0));
blender.feed(image2Updated, mask2, Point2f (0,0));
//prepare resulting size of image
blender.prepare(Rect(0, 0, result.size().width, result.size().height));
Mat result_s, result_mask;
//blend
blender.blend(result_s, result_mask);

当我尝试执行blender.feed时发生错误。

另外一点;在为混合器制作掩模时,掩模应该是整个图像还是仅在拼接过程中重叠的图像区域?

提前感谢任何帮助。

编辑

我已经让它正常工作了,但现在得到了这个混合后的图像。 enter image description here 这是未进行混合的拼接图像供参考。 enter image description here 有什么好的建议吗?


1
我认为在执行blender.feed之前应该先执行blender.prepare - api55
@api55 这让它开始运行了,但是合成后的图像只是一张灰色的图像。有什么建议吗? - C.Radford
我看到你让它运行起来了。现在它们看起来相当不错 :) 我觉得你可以尝试一些直方图均衡化的方法,使颜色更加均匀?或者还有其他方法... - api55
请查看线性交叉混合,类似于 https://dev59.com/o2Eh5IYBdhLWcg3whTwR#22324790 - Micka
还要看一下 Stitcher 实现以及它如何使用混合器。 - Adi Shavit
2个回答

0

这篇文章可能有点旧,但是我找到了问题的原因,并且想要分享一下以便于其他人也遇到同样的问题时有一个解决的思路。问题出在warpPerspective方法上,它会在变换后的图像周围留下一些黑色像素,所以你需要转换一下

warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));
warpPerspective(mask1, mask1, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(mask2, mask2, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));

warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_REPLICATE);
warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_REPLICATE);
warpPerspective(mask1, mask1, (translation*homography), result.size());
warpPerspective(mask2, mask2, translation, result.size());

这将用最接近的像素替换扭曲图像周围的所有黑色区域。


0
  1. 在 blender.feed 之前使用 blender.prepare
  2. 重新设计你的掩码(一半为 255,另一半为 0)
//Mask of the image to be combined so you can get resulting mask
Mat mask1, mask2;
mask1 = optimalSeamMask(energy, path);
mask2 = ones(mask1.rows, mask1.cols)*255-mask1

Mat image1Updated, image2Updated;
//Warp the masks and the images to their new posistions so their are of all the same  size to be overlayed and blended
warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));
warpPerspective(mask1, mask1, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
warpPerspective(mask2, mask2, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT,   (0));

//create blender
detail::MultiBandBlender blender(false, 5);
//feed images and the mask areas to blend
blender.prepare(Rect(0, 0, result.size().width, result.size().height));
blender.feed(image1Updated, mask1, Point2f (0,0));
blender.feed(image2Updated, mask2, Point2f (0,0));
//prepare resulting size of image
Mat result_s, result_mask;
//blend
blender.blend(result_s, result_mask);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接