Navigation Menu

Skip to content

Commit

Permalink
remask: fix independent faces
Browse files Browse the repository at this point in the history
  • Loading branch information
arturoc committed Oct 17, 2012
1 parent 4350a4b commit e048abb
Showing 1 changed file with 110 additions and 98 deletions.
208 changes: 110 additions & 98 deletions remask/src/testApp.cpp
Expand Up @@ -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)<thresholdFaceRot)||
(currentOrientation1.x<lastOrientation1.x && currentOrientation1.y<lastOrientation1.y) ||
Expand All @@ -179,7 +184,12 @@ void testApp::newBuffer(ofPixels & buffer){
lastOrientationMouthOpenness1 = mouthOpenDetector1.getOpennes();
half1NeedsUpdate = true;
}
mesh1.getVertices() = faceTracker1.getImageMesh().getVertices();
mesh1.getIndices() = faceTracker1.getImageMesh().getIndices();
}

if(meshesInitialized && found2){
mouthOpenDetector2.update();
ofVec2f currentOrientation2(fabs(faceTracker2.getOrientation().x),fabs(faceTracker2.getOrientation().y));
if((!updateOnLessOrientation && ofRadToDeg(currentOrientation2.y)<thresholdFaceRot) ||
(currentOrientation2.x<lastOrientation2.x && currentOrientation2.y<lastOrientation2.y) ||
Expand All @@ -190,19 +200,11 @@ void testApp::newBuffer(ofPixels & buffer){
lastOrientationMouthOpenness2 = mouthOpenDetector2.getOpennes();
half2NeedsUpdate = true;
}
mesh2.getVertices() = faceTracker2.getImageMesh().getVertices();
mesh2.getIndices() = faceTracker2.getImageMesh().getIndices();
}


if(!meshesInitialized){
mesh1 = faceTracker1.getImageMesh();
mesh2 = faceTracker2.getImageMesh();
meshesInitialized = true;
}else{
mesh1.getVertices() = faceTracker1.getImageMesh().getVertices();
mesh2.getVertices() = faceTracker2.getImageMesh().getVertices();
mesh1.getIndices() = faceTracker1.getImageMesh().getIndices();
mesh2.getIndices() = faceTracker2.getImageMesh().getIndices();
}
}
newFrame = true;
videoMutex.unlock();
}
Expand All @@ -213,104 +215,114 @@ void testApp::update(){
video->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-lastTimeFaceFound<showWireMS){
interpolatedMesh1 = vboMesh1;
interpolatedMesh2 = vboMesh2;
}else if(now-lastTimeFaceFound>showWireMS && now-lastTimeFaceFound<noSwapMS+showWireMS){

float pct = double(now-lastTimeFaceFound-showWireMS)/double(noSwapMS);
interpolatedMesh1 = vboMesh1;
for(int i=0;i<interpolatedMesh1.getNumVertices();i++){
interpolatedMesh1.getVertices()[i].interpolate(vboMesh2.getVertices()[i],pct);
}
interpolatedMesh2 = vboMesh2;
for(int i=0;i<interpolatedMesh2.getNumVertices();i++){
interpolatedMesh2.getVertices()[i].interpolate(vboMesh1.getVertices()[i],pct);
if(found){
if(lastTimeFaceFound==0){
recorder.setup(ofGetTimestampString()+".mov","",1280,720,30);
lastTimeFaceFound = now;
clone1.strength = 0;
clone2.strength = 0;
}else if(now-lastTimeFaceFound<showWireMS){
interpolatedMesh1 = vboMesh1;
interpolatedMesh2 = vboMesh2;
}else if(now-lastTimeFaceFound>showWireMS && now-lastTimeFaceFound<noSwapMS+showWireMS){
float pct = double(now-lastTimeFaceFound-showWireMS)/double(noSwapMS);
interpolatedMesh1 = vboMesh1;
for(int i=0;i<interpolatedMesh1.getNumVertices();i++){
interpolatedMesh1.getVertices()[i].interpolate(vboMesh2.getVertices()[i],pct);
}
interpolatedMesh2 = vboMesh2;
for(int i=0;i<interpolatedMesh2.getNumVertices();i++){
interpolatedMesh2.getVertices()[i].interpolate(vboMesh1.getVertices()[i],pct);
}
}else if (now - lastTimeFaceFound - noSwapMS - showWireMS<rampStrenghtMS){
interpolatedMesh1.getVertices()=vboMesh2.getVertices();
interpolatedMesh2.getVertices()=vboMesh1.getVertices();
ofxEasingQuart easing;
int s = ofxTween::map(now-lastTimeFaceFound-noSwapMS-showWireMS,0,rampStrenghtMS,0,maxStrength,true,easing,ofxTween::easeIn);
clone1.strength = s;
clone2.strength = s;
}
}else if (now - lastTimeFaceFound - noSwapMS - showWireMS<rampStrenghtMS){
interpolatedMesh1.getVertices()=vboMesh2.getVertices();
interpolatedMesh2.getVertices()=vboMesh1.getVertices();
ofxEasingQuart easing;
int s = ofxTween::map(now-lastTimeFaceFound-noSwapMS-showWireMS,0,rampStrenghtMS,0,maxStrength,true,easing,ofxTween::easeIn);
clone1.strength = s;
clone2.strength = s;
}
recorder.addFrame(video->getPixelsRef());


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);
}
Expand Down Expand Up @@ -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<showWireMS){
float pct = double(now-lastTimeFaceFound)/double(showWireMS);
pct*=pct;
Expand Down

0 comments on commit e048abb

Please sign in to comment.