Access violation error to vector<vector<Point>>,wich was created by function findContours [closed]

asked 2014-09-11 14:55:19 -0500

updated 2017-11-12 06:19:18 -0500

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);
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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-10 14:05:07.676506



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 .

Balaji R gravatar imageBalaji R ( 2014-09-12 01:08:15 -0500 )edit

Shouldn't it be cv::vector on that line?

boaz001 gravatar imageboaz001 ( 2014-09-12 02:19:25 -0500 )edit