我正在尝试使用ExposureCompensator
类。我试图将一个小图像粘贴到一个更大的图像,但在粘贴它之前,我想平衡两个图像的亮度。但是,当我运行代码时,smallImage
将返回黑色图像。
PS:另外,如果我使用ExposureCompensator::GAIN_BLOCK
,它会给出一个错误,整数除以零。
int num_images = 2;
int img_idx = 1;
//left and top corner position of small image
int left = 300;
int top = 400;
vector<Point> corners(num_images);
vector<Mat> images_warped(num_images);
vector<Mat> masks_warped(num_images);
images_warped.push_back(bigImage);
images_warped.push_back(smallImage);
corners.push_back(Point(0, 0));
corners.push_back(Point(left, top));
//created two white Mats as masks
Mat bigMask, smallMask;
bigMask.create(bigImage.size(), CV_8U);
bigMask.setTo(Scalar::all(255));
smallMask.create(smallImage.size(), CV_8U);
smallMask.setTo(Scalar::all(255));
masks_warped.push_back(bigMask);
masks_warped.push_back(smallMask);
int expos_comp_type = detail::ExposureCompensator::GAIN;
Ptr<detail::ExposureCompensator> compensator = detail::ExposureCompensator::createDefault(expos_comp_type);
compensator->feed(corners, images_warped, masks_warped);
compensator->apply(img_idx, corners[img_idx], smallImage, smallMask);
答案 0 :(得分:0)
如果在代码中创建矢量对象:
vector<Point> corners(num_images);
vector<Mat> images_warped(num_images);
vector<Mat> masks_warped(num_images);
对象的大小为2。 在push_back()方法之后,大小将为4.
尝试将上面的代码替换为:
vector<Point> corners(0);
vector<Mat> images_warped(0);
vector<Mat> masks_warped(0);