Ask Your Question

problem with contour - Invalid address specified to RtlValidateHeap

asked 2013-10-03 22:24:52 -0500

aliasofmike gravatar image

updated 2013-10-05 05:21:48 -0500

Guanta gravatar image

I have some code (that I will post below) that finds contours and then draws them. This was working previously, but I had to rebuild OpenCV in order to get GPU support (new feature I'm working on).

However, the code now fails at the last line. I've determined that this has to do with destroying the countours vector<vector<cv::point>>. As such, I have added a line to demonstrate the failure (rather than during the automatic out-of-scope cleanup).

I'm not sure where to look for solving this problem, because it probably isn't this code itself but rather some kind of project (or OpenCV build) issue.

void fof::contour(cv::Mat &dst, const cv::Mat &src, double largeness, int simplicity,float thickness, cv::Scalar color){
    //assumes that thresh has been called on SRC matrix
    std::vector <std::vector <cv::Point>> contours;
    std::vector<cv::Point> contour;
    cv::Mat temp=src.clone();

    //loop through all the contours, outputting only those with an area bigger than LARGENESS
    for (int i=0; i < contours.size(); i++){
        //create approximate polygon (SIMPLICITY determines how approximate)
        //note, might need to cast/construct the contour into a Mat

        //check to see if this contour meets LARGENESS criteria
        if (cv::contourArea(contour)>largeness){
            //draw the qualified contour using drawContours
        contours[i].clear(); //work around??
    contours.clear(); // Program fails here

Some additional info: I get a different error if I use the "Release" build instead of "Debug" in VC++ express 2010.

The error I get is: vector iterators incompatible

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-05 05:26:05 -0500

Guanta gravatar image

Just don't clear any contour-vector, it will be destroyed and cleared correctly when the scope of the function is left since it is placed on the program stack, so absolutely no need for you to clear it.

edit flag offensive delete link more


Hi, sorry but you misunderstand my problem. This happens without the clear(), I simply added that line to demonstrate in a more clear way where the failure is happening (with the destruction of the <vector<vector<cv::Point>>

aliasofmike gravatar imagealiasofmike ( 2013-10-05 23:39:27 -0500 )edit

So you neither call contours[i].clear() nor contours.clear() ?

Guanta gravatar imageGuanta ( 2013-10-06 05:17:20 -0500 )edit

Question Tools


Asked: 2013-10-03 22:24:52 -0500

Seen: 549 times

Last updated: Oct 05 '13