Eliminate too short or too long contours - Opencv2 Cookbook

asked 2014-06-03 03:43:52 -0500

updated 2014-06-03 04:41:59 -0500

berak gravatar image

Hello to everyone,

I've been following the tutorials of the OpenCV2 Cookbook, using Visual Stuido 2013. At some point I we have this code:

    // Eliminate too short or too long contours
int cmin = 1000;    // minimum contour length
int cmax = 10000;   // maximum contour length

std::vector<std::vector<cv::Point>>::iterator itc = contours.begin();

int i = 0;

while( itc != contours.end())
    if (itc->size() < cmin || itc->size() > cmax)
        itc = contours.erase(itc);
    std::cout << i << " ";

When the compiler gets to:

itc = contours.erase(itc);

It gives me this error: image description

I've searched everywhere tried every possible way of spelling it doesn't work. And here is the driving crazy part, I tried the code on Visual Studio 2010 it worked perfectly fine.

N.B.: I've tested the same code with a vector of vector of int in visual studio 2013 and it worked fine, so I guess the problem comes from VS2013 working with OpenCV. But I have no clue why.

edit retag flag offensive close merge delete



are you sure, you're using the correct c-runtime ? should be "multithreaded-dll" (same as the opencv libs were compiled against.)

berak gravatar imageberak ( 2014-06-03 04:41:22 -0500 )edit

I'm sorry i'm kind of a newbie, what do you mean by c-runtime. I'm using Opencv248 (i didn't use cmake like for the older versions of OpenCV) Thanks in advence

Slendermuse gravatar imageSlendermuse ( 2014-06-04 10:07:54 -0500 )edit