ofxCv Contour tracking on Windows

Hi Everybody,

I am using the fantastic ofxCv add-on by Kyle McDonald in a project which I am now switching from Mac to Windows.

Using the contourFinder crashes the program on Windows, on Mac it works like a charm.
Even with the example provided with the add-on crashes.

This is the error Visual Studio throws at me:
map/set iterator not incrementable

Now according to the debugger the problem should be in these lines of code that can be found in the file Tracker.h in the ofxCv add-on around line 334.

  
  
std::map<unsigned int, cv::Rect>::iterator smoothedItr;  
   for(smoothedItr = smoothed.begin(); smoothedItr != smoothed.end(); smoothedItr++) {  
	unsigned int label = smoothedItr->first;  
              if(!existsCurrent(label)) {  
		smoothed.erase(smoothed.find(label));  
	      }  
}  

Now if I comment out the smoothed.erase part in the if statement everything works fine.
But that is not the solution off course.
If anybody knows how to deal with this kind of problem, it would be great to get this fixed.

I am using Visual Studio 2010/oF version 0.7.4/Windows 8

Thanks so much for the help,

Cheers,

Wim

its odd that this works on osx. If you erase elements in a map/vector/whatever in a for loop; the order gets thrown around and the iterator becomes invalid or points to wrong elements.
Thats why you get the error. Recent versions of VS warn about this; apparently XCode compilers don’t. Don’t know why. Its also odd that it doens’t crash with a nullpointer in OSX.

try something like this:

  
  
for (smoothedItr = smoothed.begin(); smoothedItr != smoothed.end(); /* no inc. */ )  
{  
    unsigned int label = smoothedItr->first;  
    if (!existsCurrent(label))  
    {  
	smoothed.erase(smoothed.find(label));  
    }  
    else  
    {  
        ++it;  
    }  
}  

This thread is pretty useful:
http://stackoverflow.com/questions/8997503/map-set-iterator-not-incrementablemap-set-iterator-not-incrementable

you should change the for loop like the last answer in that thread; and also submit an issue on kyle’s github.

Thanks for the reply man!

I was cautious about breaking Kyle’s code and the butterfly effect… Changing something and not being quite sure what the effect on long term is gonna be :slight_smile:

I will give this a try for sure.