openCV cv::mat release
openCV cv::mat release
使用openCV时,cv::Mat。http://docs.opencv.org/modules/core/doc/basic_structures.html我知道有人在使用某种智能指针。我的问题是,为了做一些内存优化。
我应该调用cv::Mat release()以释放未使用的矩阵吗?
或者我应该相信编译器来做?
为例,想想下面的代码:
cv::Mat filterContours = cv::Mat::zeros(bwImg.size(),CV_8UC3);
bwImg.release();
for (int i = 0; i < goodContours.size(); i++)
{
cv::RNG rng(12345);
cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
cv::drawContours(filterContours,goodContours,i,color,CV_FILLED);
}
/*% Fill any holes in the objects
bwImgLabeled = imfill(bwImgLabeled,'holes');*/
imageData = filterContours;
filterContours.release(); //should I call this line or not ?
cv::release()
函数释放内存,析构函数将在Mat实例的作用域结束时处理这些内存。因此,您不需要在发布的代码片段中显式调用它。需要它的一个例子是,如果矩阵的大小在同一循环中的不同迭代中可以变化,即
using namespace cv;
int i = 0;
Mat myMat;
while(i++ < relevantCounter )
{
myMat.create(sizeForThisIteration, CV_8UC1);
//Do some stuff where the size of Mat can vary in different iterations\
mymat.release();
}
在这里,使用cv::release()为编译器节省了在每个循环中创建指针的开销
相关文章:
- Difference in displaying cv2 Mat
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 将CHW格式的浮点向量转换为cv::Mat
- C++中的openCV Mat访问冲突
- ISearchJob->Release() 卡住
- 调用 Napi::ThreadSafeFunction::Release() 会导致 ELIFECYCLE 322122
- OpenCV 和从 OutputArrays 或 (Mat) 读取数据
- 使用 mat.at<uchar>(i,j) 的 opencv C++中的矩阵赋值错误
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- LLVM 编译:目标的配方 '../lib/IR/Release+Asserts/Intrinsics.gen.tmp' failed
- 将 cv::mat 转换为 QImage
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 将 cv::Mat 转换为 std::vector 的通用函数
- 如何通过引用传递OpenCV MAT
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- Read OpenCV Mat 16bit to QImage 8bit Greyscale
- cv::Mat 内存即使在调用 release() 后也没有释放?
- cv::Mat.release()
- openCV cv::mat release