Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Using ofxCvContourFinder's findContours

$
0
0

@darthrivan wrote:

Hi again,

Here's the second project/problem. It's about using openCV to get image contours of pictures, so I read the documentation and the example of ofxCvContourFinder's findContours function which seems that it's what I'm looking for but I must be using it wrong.

As I understand, it returns the number of blobs found, and then you add them to a polyline object to draw each contour line found.

myImage.loadImage ("appelbaum1.png");
grayImage.setFromPixels(myImage.getPixels(), 1039, 585);
contourFinder.findContours(grayImage, 1039 * 585, ofGetWindowWidth() * ofGetWindowHeight(), 1200, false, true);
polylines.clear();
for(unsigned int i = 0; i < contourFinder.blobs.size(); i++) {
    ofPolyline cur;
    // add all the current vertices to cur polyline
    cur.addVertices(contourFinder.blobs[i].pts);
    cur.setClosed(true);
    
    // add the cur polyline to all these vector<ofPolyline>
    polylines.push_back(cur);
}

And then in the draw function I just draw each polyline:

ofBackground(0);

ofSetColor(255);
for (int i = 0; i < polylines.size(); ++i) {
    polylines[i].draw();
}

but nothing shows up on the window. I've tried to do a

contourFinder.draw();

instead of that for loop but nothing is shown.

What I'm missing here ?

Thanks for the help,

DarthRivan

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles