Hi
I am trying to get a portion, a subsection from a texture (in specific from video source/webcam).
I see there is drawSubsection()method which draws the portion I want, but how do I translate the same portion as texture to bind()on to a ofMesh?
Ultimately what I want to achieve is having portions of videos delimited by a mesh area. That would work exactly like using a mesh as a mask. (which is my next test)
Anyway, so far, this is what I have tried:
in .h
ofxCvColorImage testImage;
in cpp
setup(){
//leRect is a getboundingBox() of the area I need - it is a dynamic value
testImage.allocate(leRect.width, leRect.height);
}
update(){
testImage = cam.getPixels();
testImage.setROI(feature.getBoundingBox());
}
draw(){
testImage.getTextureReference().bind();
mesh.draw();
testImage.getTextureReference().unbind();
}
I get these errors like the allocation doesn’t work…
[ error ] ofxCvImage: setROI(): image not allocated
[ error ] ofxCvColorImage: setFromPixels(): width and height are zero
Hi @arturo!
thanks for replying.
So I started from your suggestion. I tried few ways but I didn’t get that right.
I was trying to adapt a rectangle o a mesh that is not rectangular.
I eventually managed to get for each mesh point the relative coordinate
for (int i=0; i<feature.getVertices().size(); i++) {
mesh.addTexCoord(ofVec2f(feature.getVertices()[i].x, feature.getVertices()[i].y));
}
this did the trick!
I also tried the solution with the masks that worked very well. I used ofxLayerMask very easy and intuitive.
Now I need to understand which one works better and a way to smooth the mesh.