Opencv Image stitching blending (Многополосное смешивание)

Я пытаюсь растушевать швы на изображениях, которые я только что сшил, используя блендер из OpenCV 3.2 в 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 и найденные гомографии верны)

//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

На небольшом примечании; При создании масок для блендера должна ли маска быть целым изображением или только областью изображений, которые перекрывают друг друга во время стежка?

Спасибо за любую помощь заранее

ИЗМЕНИТЬ

У меня это работает, но теперь я получаю это смешанное изображение. введите описание изображения здесь Вот сшитое изображение без смешивания для справки. введите здесь описание изображения Есть идеи, как улучшить?


person C.Radford    schedule 31.08.2017    source источник
comment
Я думаю, blender.prepare должно быть до blender.feed   -  person api55    schedule 31.08.2017
comment
@ api55 Вот и все, за исключением того, что полученное смешанное изображение представляет собой просто серое изображение. Какие-либо предложения?   -  person C.Radford    schedule 31.08.2017
comment
Я вижу, ты заставил это работать. Теперь они выглядят неплохо :) Думаю, можно немного уравновесить гистограмму, чтобы цвета были более ровными? или какой-то другой метод ....   -  person api55    schedule 31.08.2017
comment
взгляните на линейное перекрестное смешивание, подобное смешению stackoverflow.com/questions/22315904/   -  person Micka    schedule 31.08.2017
comment
Также взгляните на реализацию Stitcher и на то, как он использует блендеры.   -  person Adi Shavit    schedule 01.09.2017


Ответы (1)


  1. Используйте blender.prepare перед blender.feed
  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);
person I-Chan Lo    schedule 27.11.2019