-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Open
Labels
Milestone
Description
System Information
c++11, user OpenCV version: 4.10.0, windows10, msvc2019 compiler
Detailed description
After blend the images successfully, and release the blender by manual or auto. The program will still occupy the memory. When we want to blend a huge size image, it will occupy a lots of memory and nerver release.
Steps to reproduce
//Sample code
void CComposer::RunBlend(cv::Mat& blendResult, const std::vector<int32_t>& indexList,
const std::vector<cv::Point2i>& cornerInputList) {
Ptr<Blender> blender;
switch (mBlendType) {
case BLEND_FEATHER: {
blender = Blender::createDefault(Blender::FEATHER);
FeatherBlender* featherBlend = dynamic_cast<FeatherBlender*>(blender.get());
featherBlend->setSharpness(FEATHER_SHARPNESS);
break;
}
case BLEND_MULTI: {
blender = Blender::createDefault(Blender::MULTI_BAND);
MultiBandBlender* multiBandBlender = dynamic_cast<MultiBandBlender*>(blender.get());
multiBandBlender->setNumBands(mDegree);
break;
}
default: blender = Blender::createDefault(Blender::NO);
}
cv::Size srcSize = Size(mSingleWidth, mSingleHeight);
std::vector<Size> sizes = std::vector<Size>(indexList.size(), srcSize);
blender->prepare(cornerInputList, sizes);
LOGDEBUG("feeding blend start");
cv::Mat mask = cv::Mat(mSingleHeight, mSingleWidth, CV_8UC1, cv::Scalar(255));
LOGDEBUG("feeding blend start");
for (uint32_t i = 0; i < indexList.size(); i++) {
cv::Mat img, img_s, dilateMask;
int32_t currentIndex = indexList[i];
img = cv::imread(mVecSrcImagePath[currentIndex], cv::IMREAD_COLOR);
img.convertTo(img_s, CV_16S);
if (img_s.size() != srcSize) {
LOGERROR("feeding failed: size matched failed");
return;
}
blender->feed(img_s, mask, cornerInputList[i]);
}
Mat blendResultMask;
blender->blend(blendResult, blendResultMask);
blender.release();
LOGDEBUG("blending over");
}
int main() {
std::vector<std::string> imgPathList;
for (int32_t i = 0; i < 14; i++) {
std::string path = "./manual_images/" + std::to_string(i)+ ".tiff";
imgPathList.push_back(path);
}
std::vector<cv::Point2i> cornerList = {
cv::Point2i(0, 0),
cv::Point2i(683, 5),
cv::Point2i(1354, 10),
cv::Point2i(2224, 14),
cv::Point2i(3253, 62),
cv::Point2i(3251, 616),
cv::Point2i(2336, 552),
cv::Point2i(1642, 547),
cv::Point2i(883, 547),
cv::Point2i(255, 547),
cv::Point2i(258, 1010),
cv::Point2i(1275, 1008),
cv::Point2i(2074, 1004),
cv::Point2i(3341, 991),
};
CComposer composer;
composer.SetInput(imgPathList, cornerList);
composer.SetSingleSize(1920, 1080);
composer.SetBlendType(BLEND_MULTI);
cv::Mat blendResult;
std::vector<int32_t> indexList;
for (int32_t i = 0; i < 14; i++) {
indexList.push_back(i);
}
composer.RunBlend(blendResult, indexList, cornerList, false, 0, false);
blendResult.release();
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
After run to the final, it will still occupy about 200MB memory. If I blend a big size image, the occcupied maybe several GB.
However, If i use the featherblender, it only occupies about 30mb, whatever the size of the image.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)