From e048abbeabf05bb9e7a0a27549683d1a586a6a33 Mon Sep 17 00:00:00 2001 From: arturo Date: Wed, 17 Oct 2012 11:52:45 +0200 Subject: [PATCH] remask: fix independent faces --- remask/src/testApp.cpp | 208 ++++++++++++++++++++++------------------- 1 file changed, 110 insertions(+), 98 deletions(-) diff --git a/remask/src/testApp.cpp b/remask/src/testApp.cpp index 3a8759a..d667a71 100644 --- a/remask/src/testApp.cpp +++ b/remask/src/testApp.cpp @@ -165,10 +165,15 @@ void testApp::newBuffer(ofPixels & buffer){ found1 = faceTracker1.getFound(); found2 = faceTracker2.getFound(); found = found1 && found2; - if(found){ - mouthOpenDetector1.update(); - mouthOpenDetector2.update(); + if(found && !meshesInitialized){ + mesh1 = faceTracker1.getImageMesh(); + mesh2 = faceTracker2.getImageMesh(); + meshesInitialized = true; + } + + if(meshesInitialized && found1){ + mouthOpenDetector1.update(); ofVec2f currentOrientation1(fabs(faceTracker1.getOrientation().x),fabs(faceTracker1.getOrientation().y)); if((!updateOnLessOrientation && ofRadToDeg(currentOrientation1.y)update(); videoMutex.lock(); - bool isNewFrame = newFrame; - bool foundFaces = found; - newFrame = false; - - if(isNewFrame){ - if(foundFaces){ - half1.update(); - half2.update(); - if(half1NeedsUpdate){ - half1Src.update(); - half1NeedsUpdate=false; - vboMesh2.getTexCoords() = mesh2.getTexCoords(); - } - if(half2NeedsUpdate){ - half2Src.update(); - half2NeedsUpdate=false; - vboMesh1.getTexCoords() = mesh1.getTexCoords(); - } - if(!vbosInitialized){ + if(newFrame){ + newFrame = false; + if(found || (vbosInitialized && lastTimeFaceFound>0 && (found1 || found2))){ + if(found && !vbosInitialized){ vboMesh1 = mesh1; vboMesh1.setUsage(GL_DYNAMIC_DRAW); vboMesh2 = mesh2; vboMesh2.setUsage(GL_DYNAMIC_DRAW); vbosInitialized = true; - }else{ + } + + if(found1){ + half1.update(); + if(half1NeedsUpdate){ + half1Src.update(); + half1NeedsUpdate=false; + vboMesh2.getTexCoords() = mesh2.getTexCoords(); + } vboMesh1.getVertices() = mesh1.getVertices(); - vboMesh2.getVertices() = mesh2.getVertices(); vboMesh1.getIndices() = mesh1.getIndices(); + } + if(found2){ + half2.update(); + if(half2NeedsUpdate){ + half2Src.update(); + half2NeedsUpdate=false; + vboMesh1.getTexCoords() = mesh1.getTexCoords(); + } + vboMesh2.getVertices() = mesh2.getVertices(); vboMesh2.getIndices() = mesh2.getIndices(); } videoMutex.unlock(); - - if(lastTimeFaceFound==0){ - recorder.setup(ofGetTimestampString()+".mov","",1280,720,30); - lastTimeFaceFound = now; - clone1.strength = 0; - clone2.strength = 0; - }else if(now-lastTimeFaceFoundshowWireMS && now-lastTimeFaceFoundshowWireMS && now-lastTimeFaceFoundgetPixelsRef()); - mask1Fbo.begin(); - ofClear(0, 255); - vboMesh1.draw(); - mask1Fbo.end(); - - mask2Fbo.begin(); - ofClear(0, 255); - vboMesh2.draw(); - mask2Fbo.end(); - - src1Fbo.begin(); - ofClear(0, 255); - half2Src.getTextureReference().bind(); - vboMesh1.draw(); - half2Src.getTextureReference().unbind(); - src1Fbo.end(); - - src2Fbo.begin(); - ofClear(0, 255); - half1Src.getTextureReference().bind(); - vboMesh2.draw(); - half1Src.getTextureReference().unbind(); - src2Fbo.end(); - - clone1.update(src1Fbo.getTextureReference(), half1.getTextureReference(), mesh1, mask1Fbo.getTextureReference()); - clone2.update(src2Fbo.getTextureReference(), half2.getTextureReference(), mesh2, mask2Fbo.getTextureReference()); - - if(videoFrame%10==0){ - mask1Fbo.readToPixels(mask1); - mask2Fbo.readToPixels(mask2); - mask1.pasteInto(maskPixels,0,0); - mask2.pasteInto(maskPixels,0,0); - half1.getPixelsRef().pasteInto(pixelsCombined,0,0); - half2.getPixelsRef().pasteInto(pixelsCombined,0,0); + if(found1){ + mask1Fbo.begin(); + ofClear(0, 255); + vboMesh1.draw(); + mask1Fbo.end(); + + src1Fbo.begin(); + ofClear(0, 255); + half2Src.getTextureReference().bind(); + vboMesh1.draw(); + half2Src.getTextureReference().unbind(); + src1Fbo.end(); + + clone1.update(src1Fbo.getTextureReference(), half1.getTextureReference(), mesh1, mask1Fbo.getTextureReference()); + } + + if(found2){ + mask2Fbo.begin(); + ofClear(0, 255); + vboMesh2.draw(); + mask2Fbo.end(); + + src2Fbo.begin(); + ofClear(0, 255); + half1Src.getTextureReference().bind(); + vboMesh2.draw(); + half1Src.getTextureReference().unbind(); + src2Fbo.end(); + + clone2.update(src2Fbo.getTextureReference(), half2.getTextureReference(), mesh2, mask2Fbo.getTextureReference()); + } + + if(videoFrame%30==0){ + if(found1){ + mask1Fbo.readToPixels(mask1); + mask1.pasteInto(maskPixels,0,0); + half1.getPixelsRef().pasteInto(pixelsCombined,0,0); + } + if(found2){ + mask2Fbo.readToPixels(mask2); + mask2.pasteInto(maskPixels,0,0); + half2.getPixelsRef().pasteInto(pixelsCombined,0,0); + } if(video==&grabber){ exposure.update(pixelsCombined,maskPixels); } @@ -338,9 +350,9 @@ void testApp::update(){ void testApp::drawOutput(){ video->draw(1280,0,-1280,720); - if(found){ - clone1.draw(1280,0,-640,720); - clone2.draw(640,0,-640,720); + if(found || (lastTimeFaceFound>0 && (found1 || found2))){ + if(found1) clone1.draw(1280,0,-640,720); + if(found2) clone2.draw(640,0,-640,720); if(now -lastTimeFaceFound