ofstream crashes

hi all,
im following learncpp while trying to hack a working program that will load a single jpg frame, process it using ofxCvContourFinder and dump its connected points to a text file using ofstream.

i got opencvExample working with this statement added to app::update and called with a keypress

  
  
ofstream outf;  
outf.open("countor.txt");  
  
//outf<<"blobs points: number,x,y"<<endl;  
for ( int j=0; j<contourFinder.blobs[0].nPts; j++ )  
{  
 //ofVertex( contourFinder.blobs[0].pts[j].x, contourFinder.blobs[0].pts[j].y);  
outf << j << ", " << contourFinder.blobs[0].pts[j].x<<" "<< contourFinder.blobs[0].pts[j].y << endl;;  
}  
outf.close();  
  

but when i try to make it a ‘console app’,
moving all image processing code to app::setup i compile but crash when calling the ofstream process (still once, on keypress) from app:updtate

http://rafb.net/p/td0AuZ69.html <-- full testApp.cpp pasted here
http://rafb.net/p/aJAzmC39.html <-- and this is the testApp.h

hope its ok i dont use the bbcode, its hard to format and read with more then a couple of lines…

btw.
in opencvExample adding a ofSetFrameRate(25) to app::update with the vid’s framerate will make the cpu happy ( i got 80% without, 7% with), isnt the vidGrabber.isFrameNew() job to be the judge of calling a new cv process ?

on first glance, I think you are crashing with this:

  
  
for ( int j=0; j<contourFinder.blobs[0].nPts; j++ )   
  

when nBlobs = 0 - you can’t access nPts in blobs[0], etc…

does that help?

take care!
zach

in opencvExample adding a ofSetFrameRate(25) to app::update with the vid’s framerate will make the cpu happy ( i got 80% without, 7% with), isnt the vidGrabber.isFrameNew() job to be the judge of calling a new cv process ?

glut’s job is to run as fast as possible, thus cpu usage 99%, no matter what you are doing (if you are doing CV or not). ofSetFrameRate actually sleeps if we are too fast, so you see cpu reducation. cpu is not however a good metric of how hard we are working – frame rate is.

take care!
zach