Comparing image from webcam to a shape drawn

Hi,

I am working on a project to compare an image from my webcam to a shape I draw.

In order to compare any image from my webcam with ofVideoGrabber, I am using contour finder;
and I use the catmule method (drawing 11 draggableVertex) to create the shape.

I am struggling with comparing the pixels between the image from my webcam to the shape as the shape is filled with ofFill(), is it possible for me to do an if statement like:

if (finder.size() > ofFill()*0.7){
do something;
}

below is my code:

void ofApp::draw(){

ofFill();
ofEnableAlphaBlending();
ofSetColor(255,255,255,128);
cam.draw(0,0);
thresholded.draw(0,0,1080,810);

ofNoFill();
int numContours = finder.size();

if (numContours > 0){
    vector<cv::Point> points = finder.getContour(0);
    cout << "points " << points.size() << endl;
        
    //everytime when it sees a contour, it draws shape
    ofBeginShape();

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

   ofEndShape();
        finder.draw();
}

ofBeginShape();

for (int i = 0; i < nCurveVertices; i++){
    
    if (i == 0){
        ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0
        ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0
    } else if (i == nCurveVertices-1){
        ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
        ofCurveVertex(curveVertices[0].x, curveVertices[0].y);	// to draw a curve from pt 6 to pt 0
        ofCurveVertex(curveVertices[0].x, curveVertices[0].y);	// we duplicate the first point twice
    } else {
        ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
    }
    
}

ofEndShape();

}

Any comments would be very helpful :))) Cheers :)))

Karen xxx

I’m not sure what exactly do you try to achieve here, but to call ofFill() like that is clearly not an option, cause ofFill() only sets internal renderer’s mode to draw filled shapes.

In order to come up with a proper solution, you need to specify exactly what kind of comparison do you want to perform.

If I understand you correctly, you want to draw a shape on your computer and then compare that to an shape that you are imaging from a live image from your webcam.

Quite often with programming, the challenge is knowing what to search for!

I just did a search for “two dimensional shape recognition” and got the following links:

and

which in turn link to:

and

You’ll want to use the openCV library, which has been beautifully brought to openFrameworks by the frankly ace @kylemcdonald , you can find it here:

There may be some syntax / version changes between the various links I’ve posted above, but learning the differences will give you a great introduction to oF/C++/openCV.

Hope this helps.

Joel

Thanks a lot! I will look into it now :)))
CHEERS :DDD x

Hi JGL,

I have now changed my project, do you reckon if I could use the same method for comparing pixel positions from a webcam image to an image (where both of them are blob detected)?

Cheers,
Karen x

Yes! That should work for either an image loaded from disk or for an image from a webcam.