Hi,
I see some ways to do that. I haven’t tested all of them, but the 1 and the 3.
1-
Draw the path in a ofFbo fbo1. You have to do this only once, or each time the path change, but not every frame.
Draw the webcam in a second ofFbo fbo2, masked with fbo1 (check the examples to find how to mask).
Read the pixels from fbo2 into an ofPixels: fbo2.readToPixels( pixels )
You can now get the openCV Mat: Mat img = ofxCv::toCv( pixels )
2-
Draw the webcam in a ofFbo fbo.
Draw the path in the same fbo, in black. Not exactly the path, but its outside.
Read the pixels from fbo into an ofPixels: fbo.readToPixels( pixels )
You can now get the openCV Mat: Mat img = ofxCv::toCv( pixels )
3-
Get a mesh from the ofPath:
ofVboMesh mesh = path.getTessellation();
int num = mesh.getNumVertices();
for ( int i = 0; i < num; i++ ){
mesh.addTexCoord( mesh.getVertex( i) );
}
You have to do this only once, or each time the path change, but not every frame.
Use this mesh to draw only the cropped part in a fbo. Something like:
fbo.begin();
webcam.getTexture().bind();
mesh.draw();
webcam.getTexture().unbind();
fbo.end();
Read the pixels from fbo into an ofPixels: fbo.readToPixels( pixels )
You can now get the openCV Mat: Mat img = ofxCv::toCv( pixels )
This is perhaps a little faster than the 2 previous methods.
4-
Draw the path in a ofFbo.
Create a openCV image from this fbo.
You have to do this only once, or each time the path change, but not every frame.
Use a openCV method to apply the mask to the webcam image, like in this topic.
Depending on your harware, this may be faster than the others methods, because readToPixels can be an expensive operation (transfert from graphics card memory to main memory), and it is the only method which use it only when the path change. But on the other side, the masking operation is done by the CPU in this method…
5-
Draw the path with openCV (but I don’t know if openCV have primitive drawing methods to do that), and use it to mask the webcam image like in the previous method.