Heap error; failed to free cv :: Mat opencv

This code works fine to the last line. It saves the correct image on disk, but when the function exits, a "memory leak" occurs - damage to the heap. I read that Mat should not be explicitly released. In my case, it is reset both with release and without release. Please, help.

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();
}
+5
source share
2 answers

With this little information, I can only give you some support, but there is no real solution:

1.) , Win7. , , Dr. Memory ( ). : drmemory.exe -no_follow_children C:\\the_path\\YourExecutable.exe argv[1] ... argv[n]. -no_follow_children . . Dr. Memory C:\Users\NAMEHERE\AppData\Roaming\Dr. Memory\. , , . → . =)

2.) OpenCV , . , int-parameters imwrite:

vector<int> crparam;
crparam.push_back(CV_IMWRITE_PNG_COMPRESSION);
cv::imwrite("D:\\testAfterCannyEdgeDetetionFilter.png", mixedBandsMat, crparam);
+1

vector [i].release member STL ++. [i].erase

-2
source

All Articles