这段代码工作正常,直到最后一行。它将正确的图像保存在磁盘上,但在退出功能后显示“内存泄漏” - 堆损坏。我读过 Mat 不需要明确释放。就我而言,它在释放和不释放时都会崩溃。请帮忙。
void CannyEdgeDetectionFilter::applyFilter(Mat& mat, Mat& mixedBandsMat)
{
//Mat mixedBandsMat;
vector<Mat> bandWiseImages;
split(mat, bandWiseImages);
//! Evaluate numChannels to be filtered in the input image
int numChannels = mat.channels();
int type = mat.type();
//! Multiplied by 8 to get bits from Bytes
int singleChannelDepth = 8*mat.elemSize1();
for (int i = 0; i < numChannels; i++)
{
Canny(bandWiseImages[i], bandWiseImages[i], m_LowerThreshold,
m_UpperThreshold, m_Kernel.rows);
}
//! Creating filteredImgMat in order to set DataValues
mixedBandsMat.create(mat.rows, mat.cols, mat.type());
//! Unifying the channels back to the output image
merge(bandWiseImages, mixedBandsMat);
#if 1
//Release bandWiseImages Mat memory
int bandWiseVecSize = bandWiseImages.size();
for(int i = 0; i < bandWiseVecSize; i++)
bandWiseImages[i].release();
bandWiseImages.clear();
//fromTo.clear();
#endif
imwrite("D:\\testAfterCannyEdgeDetetionFilter.jpg", mixedBandsMat);
mixedBandsMat.release();
}