c++ - Opencv 图像拼接混合(多波段混合)

标签 c++ opencv blending image-stitching

我正在尝试使用 cv::detail::MultiBandBlender 中的 OpenCV 3.2 中的混合器来混合刚刚缝合在一起的图像中的接缝。发现于#include "opencv2/stitching/detail/blenders.hpp" 。我能找到的文档并不多,编码示例甚至更少,但我设法找到了一个很好的博客来帮助解释这些步骤 here

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

这是混合的代码(假设拼接、warpPerspective 和单应性均正确)

//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 时发生错误

顺便说一句;为 blender 制作蒙版时,蒙版应该是整个图像还是只是缝合过程中彼此重叠的图像区域?

感谢您提前提供的帮助

编辑

我已经可以工作了,但现在正在得到这个混合图像。 enter image description here 这是未混合的拼接图像,以供引用。 enter image description here 关于如何改进有什么想法吗?

最佳答案

  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);

关于c++ - Opencv 图像拼接混合(多波段混合),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45983034/

相关文章:

c++ - 关于纯抽象类中的静态成员函数 - 设计模式?

c++ - std::move() 如何将值传输到 RValues 中?

python - 使用光流计算实际速度

c++ - OpenCV 仅围绕大轮廓绘制矩形?

OpenGL 渲染到纹理

c++ - 从不在 PIMPL 中提供析构函数(使用 boost scoped_ptr),g++(4.6.1) 不会生成编译错误,为什么?

C++ Exe加密?

c++ - CudaMemCpy 在复制 vector<cv::Point3f> 时返回 cudaErrorInvalidValue

ios - 具有深度测试的 OpenGL 点 Sprite - 混合问题?

c++ - 如何通过简单的乘法将纹理颜色混合到其下面的颜色?