Sunday, 18 August 2013

Program crashes on using grabCut in OpenCV 2.3.1

Program crashes on using grabCut in OpenCV 2.3.1

I am using the following code :
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
const string ipImgName= argv[1];
Mat ipImg;
ipImg = imread( ipImgName, 1 );
cv::Mat gcImg;
cv::Mat bgdModel;
cv::Mat fgdModel;
cv::Rect rect(0, 0, ipImg.cols-1, ipImg.rows-1);
cv::grabCut( ipImg, gcImg, rect, bgdModel, fgdModel, 1,
cv::GC_INIT_WITH_RECT );
return 0;
}
But when exiting the main loop, when the debugger goes into the ~Mat()
destructor, the code crashes on release() ( saying "this maybe due to a
corruption of the heap" ) for gcImg or bgdModel or fgdModel.
However, if I allocate the cv::Mats on heap using new and then don't
delete them after, the code runs just fine. I am using Visual Studio 2010
with OpenCV 2.3.1.

No comments:

Post a Comment