From a84c188f0e1db9d22165b5aa2a9e031f72d281c4 Mon Sep 17 00:00:00 2001 From: cailean Date: Wed, 2 Oct 2024 12:25:14 +0100 Subject: [PATCH] blue&white depth-map added --- src/ofApp.cpp | 46 +++++++++++++++++++++------------------------- src/ofApp.h | 2 +- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/ofApp.cpp b/src/ofApp.cpp index f43cf6b..09c4339 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -23,9 +23,9 @@ void ofApp::setup(){ depth.Setup(modelPath, false, true); emotion.Setup(modelPath3, false, true); + /* Load shader, allocated rampedFbo */ depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); - rampedFbo.allocate(1600, 800, GL_RGB); - drawMesh =ofMesh::plane(1600, 800 ); + rampedFbo.allocate(1600, 800); } @@ -47,11 +47,10 @@ void ofApp::update(){ map.Draw(); } - /* Setup model input using ofImage */ + /* Setup model input using ofImage, allocated fbo */ player.Update(img); img.setFromPixels(player.GetVideoPixels()); - - + /* Run Models */ try{ auto output_tensors = depth.Run(map.fboImage); @@ -114,26 +113,7 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ map.Draw(); - //fbo.draw(0, 0); - - auto& texCoords = drawMesh.getTexCoords(); - auto& tex = rampedFbo.getTexture(); - for( auto& tc : texCoords ){ - tc = rampedFbo.getTexture().getCoordFromPercent(tc.x, (1.0-tc.y)); - } - - rampedFbo.begin(); - depthToColourShader.begin(); - depthToColourShader.setUniformTexture("alphaTex", fbo.getTexture(), 0); - ofPushMatrix(); - // translate to center of window because ofMesh::plane origin is in the center // - ofTranslate(ofGetWidth()/2, ofGetHeight()/2 ); - drawMesh.draw(); - ofPopMatrix(); - depthToColourShader.end(); - rampedFbo.end(); - - rampedFbo.draw(0, 0); + renderDepthMap(); if(!firstRun){ faceDetector.DrawBox(detected_faces); @@ -187,6 +167,22 @@ void ofApp::inferEmotionalState(){ } } +void ofApp::renderDepthMap(){ + rampedFbo.begin(); + + depthToColourShader.begin(); + depthToColourShader.setUniformTexture("tex0", fbo.getTexture(), 0); + depthToColourShader.setUniformTexture("tex1", map.fboImage.getTexture(), 1); + depthToColourShader.setUniform1f("texW", rampedFbo.getWidth()); + depthToColourShader.setUniform1f("texH", rampedFbo.getHeight()); + fbo.draw(0, 0); + depthToColourShader.end(); + + rampedFbo.end(); + + rampedFbo.draw(0,0); +} + //-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (key=OF_KEY_LEFT){ diff --git a/src/ofApp.h b/src/ofApp.h index 3ebb12f..66a5be6 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -28,6 +28,7 @@ class ofApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); void inferEmotionalState(); + void renderDepthMap(); ofImage img; ofFbo fbo; @@ -52,5 +53,4 @@ class ofApp : public ofBaseApp{ ofShader depthToColourShader; ofFbo rampedFbo; - ofMesh drawMesh; };