OpenCV图像拼接混合(多波段混合)

biswetbf  于 2023-04-21  发布在  其他
关注(0)|答案(2)|浏览(179)

我试图融合出的接缝,我刚刚拼接在一起使用搅拌机从OpenCV 3.2在cv::detail::MultiBandBlender#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和单应性都是正确的)

  1. //Mask of iamge to be combined so you can get resulting mask
  2. Mat mask1(image1.size(), CV_8UC1, Scalar::all(255));
  3. Mat mask2(image2.size(), CV_8UC1, Scalar::all(255));
  4. Mat image1Updated, image2Updated;
  5. //Warp the masks and the images to their new posistions so their are of all the same size to be overlayed and blended
  6. warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
  7. warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT, (0));
  8. warpPerspective(mask1, mask1, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
  9. warpPerspective(mask2, mask2, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT, (0));
  10. //create blender
  11. detail::MultiBandBlender blender(false, 5);
  12. //feed images and the mask areas to blend
  13. blender.feed(image1Updated, mask1, Point2f (0,0));
  14. blender.feed(image2Updated, mask2, Point2f (0,0));
  15. //prepare resulting size of image
  16. blender.prepare(Rect(0, 0, result.size().width, result.size().height));
  17. Mat result_s, result_mask;
  18. //blend
  19. blender.blend(result_s, result_mask);

当我尝试执行blender.feed时发生错误
顺便说一句当为搅拌机制作遮罩时,遮罩应该是整个图像,还是只是在缝合期间彼此重叠的图像区域?
提前感谢任何帮助

编辑

我有它的工作,但现在得到这个结果混合成像。

这里是缝合图像没有混合参考。

任何想法如何改善?

7uhlpewt

7uhlpewt1#

1.使用搅拌机.搅拌机前准备.饲料
1.重新设计你的面具(一半255和一半0)

  1. //Mask of the image to be combined so you can get resulting mask
  2. Mat mask1, mask2;
  3. mask1 = optimalSeamMask(energy, path);
  4. mask2 = ones(mask1.rows, mask1.cols)*255-mask1
  5. Mat image1Updated, image2Updated;
  6. //Warp the masks and the images to their new posistions so their are of all the same size to be overlayed and blended
  7. warpPerspective(image1, image1Updated, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
  8. warpPerspective(image2, image2Updated, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT, (0));
  9. warpPerspective(mask1, mask1, (translation*homography), result.size(), INTER_LINEAR, BORDER_CONSTANT,(0));
  10. warpPerspective(mask2, mask2, translation, result.size(), INTER_LINEAR, BORDER_TRANSPARENT, (0));
  11. //create blender
  12. detail::MultiBandBlender blender(false, 5);
  13. //feed images and the mask areas to blend
  14. blender.prepare(Rect(0, 0, result.size().width, result.size().height));
  15. blender.feed(image1Updated, mask1, Point2f (0,0));
  16. blender.feed(image2Updated, mask2, Point2f (0,0));
  17. //prepare resulting size of image
  18. Mat result_s, result_mask;
  19. //blend
  20. blender.blend(result_s, result_mask);
展开查看全部
0yycz8jy

0yycz8jy2#

这是旧的,但我发现了问题的原因,并会分享它的情况下,任何人都面临着同样的问题,问题是在warpPerspective方法,将有一点黑色像素接壤的扭曲图像,所以你必须转换

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

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

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

相关问题