added number of bands cropping in multi-bands blending
This commit is contained in:
parent
c65a39be82
commit
052bf4df73
@ -158,8 +158,15 @@ void FeatherBlender::blend(Mat &dst, Mat &dst_mask)
|
||||
void MultiBandBlender::prepare(Rect dst_roi)
|
||||
{
|
||||
dst_roi_final_ = dst_roi;
|
||||
|
||||
// Crop unnecessary bands
|
||||
double max_len = static_cast<double>(max(dst_roi.width, dst_roi.height));
|
||||
num_bands_ = min(actual_num_bands_, static_cast<int>(ceil(log(max_len) / log(2.0))));
|
||||
|
||||
// Add border to the final image, to ensure sizes are divided by (1 << num_bands_)
|
||||
dst_roi.width += ((1 << num_bands_) - dst_roi.width % (1 << num_bands_)) % (1 << num_bands_);
|
||||
dst_roi.height += ((1 << num_bands_) - dst_roi.height % (1 << num_bands_)) % (1 << num_bands_);
|
||||
|
||||
Blender::prepare(dst_roi);
|
||||
|
||||
dst_pyr_laplace_.resize(num_bands_ + 1);
|
||||
@ -186,12 +193,14 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
|
||||
CV_Assert(img.type() == CV_16SC3);
|
||||
CV_Assert(mask.type() == CV_8U);
|
||||
|
||||
// Keep source image in memory with small border
|
||||
int gap = 3 * (1 << num_bands_);
|
||||
Point tl_new(max(dst_roi_.x, tl.x - gap),
|
||||
max(dst_roi_.y, tl.y - gap));
|
||||
Point br_new(min(dst_roi_.br().x, tl.x + img.cols + gap),
|
||||
min(dst_roi_.br().y, tl.y + img.rows + gap));
|
||||
|
||||
// Ensure coordinates of top-left, bootom-right corners are divided by (1 << num_bands_)
|
||||
tl_new.x = dst_roi_.x + (((tl_new.x - dst_roi_.x) >> num_bands_) << num_bands_);
|
||||
tl_new.y = dst_roi_.y + (((tl_new.y - dst_roi_.y) >> num_bands_) << num_bands_);
|
||||
int width = br_new.x - tl_new.x;
|
||||
|
@ -84,15 +84,15 @@ class MultiBandBlender : public Blender
|
||||
{
|
||||
public:
|
||||
MultiBandBlender(int num_bands = 5) { setNumBands(num_bands); }
|
||||
int numBands() const { return num_bands_; }
|
||||
void setNumBands(int val) { num_bands_ = val; }
|
||||
int numBands() const { return actual_num_bands_; }
|
||||
void setNumBands(int val) { actual_num_bands_ = val; }
|
||||
|
||||
void prepare(cv::Rect dst_roi);
|
||||
void feed(const cv::Mat &img, const cv::Mat &mask, cv::Point tl);
|
||||
void blend(cv::Mat &dst, cv::Mat &dst_mask);
|
||||
|
||||
private:
|
||||
int num_bands_;
|
||||
int actual_num_bands_, num_bands_;
|
||||
std::vector<cv::Mat> dst_pyr_laplace_;
|
||||
std::vector<cv::Mat> dst_band_weights_;
|
||||
cv::Rect dst_roi_final_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user