如何在opencv中使用多频段混合器 [英] How to use Multi-band Blender in opencv

查看:417
本文介绍了如何在opencv中使用多频段混合器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用混合两张图片多频段混合,但我不清楚此函数的输入参数:

I want to blend two images using multiband blending but I am not clear to the input parameter of this function:

void detail::Blender::prepare(const std::vector<Point>& corners, const std::vector<Size>& sizes)

在我的例子中,我只是输入两个扭曲的图像与黑色的间隙,并用面具全部白色(原谅我不能添加图片...)

In my case ,I just input two warped images with black gap, and with masks all white.(forgive me can not add pictures...)

我设置了两个角(0.0,0.0),因为变形的图像已经被注册。

And I set the two corners (0.0,0.0),because the warped images has been registered.

但我的结果不够好。

有人可以告诉我为什么?我如何解决这个问题?

can someone tell me why?How can I solve this problem?

推荐答案

我不知道你说我的结果不够好是什么意思。最好看看这个结果,但我会试着猜测。我的代码的主要部分,这使得全景,看起来像这样:

I'm not sure what do you mean when you say "my result is not good enough". It's better to watch that result, but I'll try to guess. My main part of code, which makes panorama, looks like this:

void makePanorama(Rect bounding_box, vector<Mat> images, vector<Mat> homographies, vector<vector<Point>> corners) {
  detail::MultiBandBlender blender;
  blender.prepare(bounding_box);

  Mat mask, bigImage, curImage;
  for (int i = 0; i < (int)images.size(); ++i) {
    warpPerspective(images[i], curImage, homographies[i],
                bounding_box.size(), INTER_LINEAR, ORDER_TRANSPARENT);

    mask = makeMask(curImage.size(), corners[i], homographies[i]);
    blender.feed(curImage.clone(), mask, Point(0, 0));
  }

  blender.blend(bigImage, mask);
  bigImage.convertTo(bigImage, (bigImage.type() / 8) * 8);
  imshow("Result", bigImage);
  waitKey();
}

因此,准备 blender 然后循环:warp图像,在变形图像和feed进料混合器后制作mask。最后,打开这个搅拌机,这就是所有。我遇到了两个问题,这对我的结果影响很大。可能是你有其中一个或两者都有。

So, prepare blender and then loop: warp image, make the mask after warped image and feed blender. At the end, turn this blender on and that's all. I met two problems, which influence on my result badly. May be you have one of them or both.

第一个是类型。我的图像有CV_16SC3,混合后,你需要将混合图像类型转换为 unsigned 一个。像这样

The first is type. My images had CV_16SC3, and after blending you need to convert blended image type into unsigned one. Like this

  bigImage.convertTo(bigImage, (bigImage.type() / 8) * 8);

如果没有,结果图片将是灰色的。

If you not, the result image would be gray.

第二个是边框。在开始,我的函数makeMask计算非黑色区域的翘曲图像。结果,人们可以在混合图像上看到扭曲图像的边界。解决方案是使掩模小于非黑色翘曲图像区域。所以,我的函数 makeMask 看起来像这样:

The second is borders. In the beginning, my function makeMask was calculating non-black area of warped images. As a result, the one could see borders of the warped images on the blended image. The solution is to make mask smaller than non-black warped image area. So, my function makeMask is looks like this:

Mat makeMask(Size sz, vector<Point2f> imageCorners, Mat homorgaphy) {
  Scalar white(255, 255, 255);
  Mat mask = Mat::zeros(sz, CV_8U);
  Point2f innerPoint;
  vector<Point2f> transformedCorners(4);

  perspectiveTransform(imageCorners, transformedCorners, homorgaphy);
  // Calculate inner point
  for (auto& point : transformedCorners)
      innerPoint += point;
  innerPoint.x /= 4;
  innerPoint.y /= 4;

  // Make indent for each corner
  vector<Point> corners;
  for (int ind = 0; ind < 4; ++ind) {
    Point2f direction = innerPoint - transformedCorners[ind];
    double normOfDirection = norm(direction);
    corners[ind].x += settings.indent * direction.x / normOfDirection;
    corners[ind].y += settings.indent * direction.y / normOfDirection;
  }

  // Draw borders
  Point prevPoint = corners[3];
  for (auto& point : corners) {
    line(mask, prevPoint, point, white);
    prevPoint = point;
  }

  // Fill with white
  floodFill(mask, innerPoint, white);
  return mask;
}

我从我的实际代码中取出这些代码,指定的东西。但我希望,如何使用 MultiBandBlender 的想法很清楚。

I took this pieces of code from my real code, so I could possibly forget to specify something. But I hope, the idea of how to work with MultiBandBlender is clear.

这篇关于如何在opencv中使用多频段混合器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆