1

I try to blend my images into pano with MultiBandBlender, but it return black pano. But FeatherBlender works fine. What I doing wrong?

blendImages(const std::vector<cv::Point> &corners, std::vector<cv::Mat> images)
{
    std::vector<cv::Size> sizes;
    for(int i = 0; i < images.size(); i++)
        sizes.push_back(images[i].size());
    float blend_strength = 5;
    cv::Size dst_sz = cv::detail::resultRoi(corners, sizes).size();
    float blend_width = sqrt(static_cast<float>(dst_sz.area())) * blend_strength / 100.f;
    cv::Ptr<cv::detail::Blender> blender = cv::detail::Blender::createDefault(cv::detail::Blender::MULTI_BAND);
    //cv::detail::FeatherBlender* fb = dynamic_cast<cv::detail::FeatherBlender*>(blender.get());
    //fb->setSharpness(1.f/blend_width);
    cv::detail::MultiBandBlender* mb = dynamic_cast<cv::detail::MultiBandBlender*>(blender.get());
    mb->setNumBands(static_cast<int>(ceil(log(blend_width)/log(2.)) - 1.));
    blender->prepare(corners, sizes);
    for(int i = 0; i < images.size(); i++)
    {
        cv::Mat image_s;
        images[i].convertTo(image_s, CV_16SC3);
        blender->feed(image_s, cv::Mat::ones(image_s.size(), CV_8UC1), corners[i]);
    }
    cv::Mat pano;
    cv::Mat panoMask = cv::Mat::ones(dst_sz, CV_8UC1);
    blender->blend(pano, panoMask);
    return pano;
}
Pavel
  • 277
  • 2
  • 13

3 Answers3

2

Three possible causes:

  • Try keeping all image_s and masks in a vector, and feed with the following structure:

for (int i = 0; i < images_s.size(); ++i) blender->feed(images_s[i], masks[i], corners[i]);

  • Don't initialize panoMask to ones before blending.

  • Make sure corners are well defined

Finfa811
  • 618
  • 1
  • 8
  • 28
0

Actually, I can't compile your code with OpenCV 2.4, because of blender.get function. There is no such a function in my build of OpenCV 2.4.

Anyway, if you wish to make a panorama, you'd better not use resultRoi function. You need boundingRect. I suppose, it is really hard to get all horizontally aligned images for one panorama.

Also, look at my answer here. It demonstrates how to use MultiBandBlender.

Community
  • 1
  • 1
RomanS
  • 883
  • 8
  • 14
0

Hey I was getting the same black pano while using MultiBand blender in opencv. Actually the issue was resolved by changing

cv::Mat::ones(image_s.size(), CV_8UC1)

to

cv::Mat::ones(image_s.size(), CV_8UC1)*255

This is because Mat::ones initialize all the pixels to a value of numerical 1, Thus, we need to muliply it with 255 in order to get a pure black & white mask.

And, thanks, your issue solved my problem :)

Koopakiller
  • 2,838
  • 3
  • 32
  • 47