Access violation error to vector<vector<Point>>,wich was created by function findContours [closed]
Hi! I need get access to Point in vector<vector<point> > which was created by function findContours. It work perfectly in Visual Studio 2010. But I get error when I use Visual Studio 2012 or Visual Studio 2013. I use x86 platform. This piece of code work perfectly in VS 2010:
Mat Image = imread("...");
Mat Gray;
cv::cvtColor(Image, Gray, CV_BGR2GRAY);
Mat Binar;
cv::Canny(Gray, Binar, 128, 255);
cv::vector<cv::vector<cv::Point> > contours;
cv::findContours(Binar, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
int x, y;
int width = Binar.cols;
int height = Binar.rows;
Mat Result(height, width, CV_8UC1);
Result.setTo(0);
uchar* resultPtr = Result.ptr<uchar>();
for (int i=0; i < contours.size(); ++i)
{
const vector<Point>& c = contours[i];
for (int j = 0; j < c.size(); ++j)
{
x = c[j].x;
y = c[j].y;
resultPtr[y * Result.step + x] = 255;
}
}
But it don't work in VS 2012 and VS 2013. I get unhandled exception (access violation) in line
const vector<Point>& c = contours[i];
Strange, but function drawContours works perfectly with this contours in all versions of VS.
I think, there is some bug in OpenCV for Visual Studio and wish to inform this.
when ever you experience a problem like this, first check all the prerequisites to to run an opencv application. Check your Include folders, libs & dll's. Check whether you are using correct lib's are not. If the problem still exists update your build environment here .
Shouldn't it be cv::vector on that line?