Код: Выделить всё
#include
#include
#include
#include
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#include "opencv2/xfeatures2d/cuda.hpp"
#include "opencv2/cudafeatures2d.hpp"
#include "opencv2/cudaarithm.hpp"
cv::Mat border(cv::Mat mask)
{
cv::Mat gx;
cv::Mat gy;
cv::Sobel(mask, gx, CV_32F, 1, 0, 3);
cv::Sobel(mask, gy, CV_32F, 0, 1, 3);
cv::Mat border;
cv::magnitude(gx, gy, border);
return border > 100;
}
cv::Mat linearBlend2(cv::Mat image1, cv::Mat mask1, cv::Mat image2, cv::Mat mask2)
{
cv::TickMeter tm;
// === Init variable ===
cv::Mat distResult, distMask1, distMask2, diskMaskSum, borderMask;
cv::Mat imBlendedB, imBlendedG, imBlendedR, imgResult;
double min, max;
cv::Point minLoc, maxLoc;
cv::Mat im1Float, im2Float;
std::vector channels1, channels2, channelsBlended;
// edited: find regions where no mask is set
// compute the region where no mask is set at all, to use those color values unblended
tm.start();
cv::Mat bothMasks = mask1 | mask2;
cv::Mat noMask = 255 - bothMasks;
// create an image with equal alpha values:
cv::Mat rawAlpha = cv::Mat(noMask.rows, noMask.cols, CV_32FC1);
rawAlpha = 1.0f;
tm.stop();
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79414543/how-to-remove-ghosting-on-linear-blend[/url]