conourFinder more than one outline?

Hi all,

While using the contourFinder I am able get the outline of a figure using live video. However it only draws the largest one. Anybody know how to find and draw more?

Thank you!

when you call the contour finder’s findContours function, you can say how many blobs you want to find and what the min and max sizes of blobs to find are.

you may need to adjust these numbers if it’s only getting one blob and it should get more.

take care!
zach

How about if we wanted to use Theo’s code that smoothed it out? In other words how would I adjust the following to get more blobs?

IN UPDATE

cvThresh.threshold(threshold);
int numBlobs = contour.findContours(cvThresh, 100, 9999999, 40, false, false);

if(numBlobs > 0){

//lets get out the contour data
int length_of_contour = contour.blobs[0].pts.size();

//clear the old contours
contourReg.clear();
contourReg.assign(length_of_contour, ofxPoint2f());
contourSmooth.clear();
contourSmooth.assign(length_of_contour, ofxPoint2f());

//lets make a copy for ourselves
for(int i = 0; i < length_of_contour; i++){
contourReg[i] = contour.blobs[0].pts[i];
}

contourSimp.smooth(contourReg, contourSmooth, smoothPct);
}
}

IN DRAW

ofBeginShape();
for(int i = 0; i < contourSmooth.size(); i++){
ofVertex(contourSmooth[i].x, contourSmooth[i].y);
}
ofEndShape(true);

Thanks again - this is totally fun!!!

hey can you use the code tag ? it helps make the code look good on the forum. otherwise everything looses formatting…

I’m not so sure about theo’s code… but for example, you can have an array of vectors, like:

vector contourReg [2];
vector contourSmooth [2];

then,

  
  
if(numBlobs > 1){	  
  
for (int i = 0; i < 2; i++){  
int length_of_contour = contour.blobs[i].pts.size();  
  
//clear the old contours  
contourReg[i].clear();  
contourReg[i].assign(length_of_contour, ofxPoint2f());  
contourSmooth[i].clear();  
contourSmooth[i].assign(length_of_contour, ofxPoint2f());  
  

be careful with multiple for loops inside of for loops, ie don’t write:

  
  
for (int i = 0; i < foo; i++){  
for (int i = 0; i < bar; i++){  
}  
}  
  

but rather write:

  
  
for (int i = 0; i < foo; i++){  
for (int j = 0; j < bar; j++){  
}  
}  
  

:slight_smile:

take care!
zach

sorry about that! but thanks - I’ll go through his sample and give it a try. enjoy your weekend!