Ask Your Question

Revision history [back]

Iplimage to Mat memory acces violation

I´m having some problems with a code I'm writing, i'm trying to make the bwlabel operation in c++. And I'm having some memory deallocation problems, I don't know why, because I tried to follow the documentation in the OpenCV tutorials. It seems to be a problem with the variable refcount proper of the variable Mat.

Here is my code:

void VideoSeg::bwlabel(IplImage *srce, IplImage *out) {

namedWindow( "wndNameOut", CV_GUI_NORMAL );
cvConvertScale(srce,srce,255.);
Ptr<IplImage> srcx = srce; 

Mat src(srcx);

imshow( "wndNameOut", src);            //The image is succesfully plotted
SimpleBlobDetector blobDetector( params );
blobDetector.create("SimpleBlob");

blobDetector.detect(src, keyPoints );  // The problem appears in this line

for(int i=0; i<keyPoints.size(); i++ )
{
    cv::floodFill(src,keyPoints[i].pt, Scalar::all((i+1)*255/(keyPoints.size()+1)));
}

IplImage outx = src;
//http://docs.opencv.org/doc/tutorials/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.html
(*out) = outx;

cout << "Keypoints " << keyPoints.size() << endl;

}