|
@ -2,33 +2,47 @@ |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|
void ofApp::setup(){ |
|
|
void ofApp::setup(){ |
|
|
|
|
|
/* ofSettings */ |
|
|
ofDisableArbTex(); |
|
|
ofDisableArbTex(); |
|
|
ofSetFrameRate(60); |
|
|
ofSetFrameRate(24); |
|
|
// ofSetVerticalSync(true);
|
|
|
ofSetVerticalSync(true); |
|
|
|
|
|
window_width = ofGetWindowWidth(); |
|
|
|
|
|
window_height = ofGetWindowHeight(); |
|
|
|
|
|
|
|
|
|
|
|
/* load font */ |
|
|
tf.load("data/fonts/jetbrainsmono-regular.ttf", 20); |
|
|
tf.load("data/fonts/jetbrainsmono-regular.ttf", 20); |
|
|
|
|
|
|
|
|
map.Setup(); |
|
|
/* load shader */ |
|
|
|
|
|
depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); |
|
|
|
|
|
|
|
|
//player.Setup();
|
|
|
/* setup map */ |
|
|
//player.SetVideo("videos/demo.mp4", fbo);
|
|
|
map.Setup(); |
|
|
|
|
|
|
|
|
emoteImage.allocate(260, 260); |
|
|
/* setup video */ |
|
|
tempImage.allocate(emoteImage.getWidth(), emoteImage.getHeight(), OF_IMAGE_COLOR); |
|
|
player.Setup(); |
|
|
|
|
|
player.SetVideo("videos/demo.mp4", model_output_fbo_1); |
|
|
|
|
|
|
|
|
|
|
|
/* setup models (modelPath, log, useCuda) */ |
|
|
ORTCHAR_T* modelPath = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/depth_anything_v2_vitb.onnx"; |
|
|
ORTCHAR_T* modelPath = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/depth_anything_v2_vitb.onnx"; |
|
|
ORTCHAR_T* modelPath2 = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/yolov5s-face.onnx"; |
|
|
ORTCHAR_T* modelPath2 = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/yolov5s-face.onnx"; |
|
|
ORTCHAR_T* modelPath3 = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/rgb_emotion.onnx"; |
|
|
ORTCHAR_T* modelPath3 = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/rgb_emotion.onnx"; |
|
|
|
|
|
ORTCHAR_T* modelPath4 = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/onnx-test/bin/data/depth_anything_v2_vits.onnx"; |
|
|
|
|
|
|
|
|
/* Setup Models (modelPath, log, useCuda) */ |
|
|
|
|
|
yolo.Setup(modelPath2, false, true); |
|
|
yolo.Setup(modelPath2, false, true); |
|
|
depth.Setup(modelPath, false, true); |
|
|
depth.Setup(modelPath, false, true); |
|
|
|
|
|
depth_small.Setup(modelPath4, false, true); |
|
|
emotion.Setup(modelPath3, false, true); |
|
|
emotion.Setup(modelPath3, false, true); |
|
|
|
|
|
|
|
|
/* Load shader, allocated rampedFbo */ |
|
|
/* Depth output fbo */ |
|
|
depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); |
|
|
model_output_fbo.allocate(window_width / 2, window_height, GL_RGB); |
|
|
fbo.allocate(1600, 800, GL_RGB); |
|
|
|
|
|
rampedFbo.allocate(1600, 800); |
|
|
/* Shader output */ |
|
|
|
|
|
rampedFbo.allocate(window_width, window_height); |
|
|
|
|
|
|
|
|
|
|
|
emoteImage.allocate(260, 260); |
|
|
|
|
|
tempImage.allocate(emoteImage.getWidth(), emoteImage.getHeight(), OF_IMAGE_COLOR); |
|
|
|
|
|
|
|
|
|
|
|
screen_fbo.allocate(window_width, window_height, GL_RGB); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,7 +51,6 @@ void ofApp::setup(){ |
|
|
void ofApp::update(){ |
|
|
void ofApp::update(){ |
|
|
/* Check to see if the application has moved to the first frame
|
|
|
/* Check to see if the application has moved to the first frame
|
|
|
As the models need to load first, as the first inference is quite slow */ |
|
|
As the models need to load first, as the first inference is quite slow */ |
|
|
auto start = std::chrono::high_resolution_clock::now(); |
|
|
|
|
|
if(ofGetFrameNum() > 0) |
|
|
if(ofGetFrameNum() > 0) |
|
|
firstRun = false; |
|
|
firstRun = false; |
|
|
|
|
|
|
|
@ -52,35 +65,29 @@ void ofApp::update(){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Setup model input using ofImage, allocated fbo */ |
|
|
/* Setup model input using ofImage, allocated fbo */ |
|
|
//player.Update(img);
|
|
|
player.Update(img); |
|
|
//img.setFromPixels(player.GetVideoPixels());
|
|
|
img.setFromPixels(player.GetVideoPixels()); |
|
|
|
|
|
|
|
|
/* Run Models */ |
|
|
/* Run Models */ |
|
|
try{ |
|
|
try{ |
|
|
|
|
|
|
|
|
|
|
|
// map
|
|
|
|
|
|
inferDepthImage(model_output_fbo, map.fboImage, depth); |
|
|
|
|
|
|
|
|
auto output_tensors = depth.Run(map.fboImage); |
|
|
// video player
|
|
|
float* output_ptr = output_tensors.front().GetTensorMutableData<float>(); |
|
|
inferDepthImage(model_output_fbo_1, img, depth_small); |
|
|
size_t num_elements = output_tensors.front().GetTensorTypeAndShapeInfo().GetElementCount(); |
|
|
|
|
|
|
|
|
|
|
|
float min_value = depth.ReduceMin(output_ptr, num_elements); |
|
|
|
|
|
float max_value = depth.ReduceMax(output_ptr, num_elements); |
|
|
|
|
|
|
|
|
|
|
|
depth.Normalize(output_ptr, num_elements, min_value, max_value); |
|
|
|
|
|
|
|
|
|
|
|
depth.DataToFbo(output_ptr, 518, 518, fbo); |
|
|
// auto output_tensors_face = yolo.Run(model_input_img);
|
|
|
|
|
|
|
|
|
auto output_tensors_face = yolo.Run(map.fboImage); |
|
|
// auto output_faces = output_tensors_face.front().GetTensorTypeAndShapeInfo().GetShape();
|
|
|
|
|
|
|
|
|
auto output_faces = output_tensors_face.front().GetTensorTypeAndShapeInfo().GetShape(); |
|
|
// unsigned int num_anchors = output_faces[1]; // Number of anchors
|
|
|
|
|
|
|
|
|
unsigned int num_anchors = output_faces[1]; // Number of anchors
|
|
|
// float* output_face_ptr = output_tensors_face.front().GetTensorMutableData<float>();
|
|
|
|
|
|
|
|
|
float* output_face_ptr = output_tensors_face.front().GetTensorMutableData<float>(); |
|
|
// faceDetector.ParseOutput(output_face_ptr, detected_faces, num_anchors);
|
|
|
|
|
|
|
|
|
faceDetector.ParseOutput(output_face_ptr, detected_faces, num_anchors); |
|
|
// faceDetector.ConvertBoxCoordsToOriginalSize(detected_faces, outFbo.getWidth(), outFbo.getHeight());
|
|
|
|
|
|
|
|
|
faceDetector.ConvertBoxCoordsToOriginalSize(detected_faces, fbo.getWidth(), fbo.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
/* As no input is generated for the emotion recognition model, run a dummy vector through the model
|
|
|
/* As no input is generated for the emotion recognition model, run a dummy vector through the model
|
|
|
So it can load */ |
|
|
So it can load */ |
|
@ -112,11 +119,6 @@ void ofApp::update(){ |
|
|
std::cout << "Model did not run" << std::endl; |
|
|
std::cout << "Model did not run" << std::endl; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
auto end = std::chrono::high_resolution_clock::now(); |
|
|
|
|
|
std::chrono::duration<float> duration = end - start; |
|
|
|
|
|
std::cout << "Time taken for Update: " << duration.count() << " seconds" << std::endl; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,18 +126,52 @@ void ofApp::update(){ |
|
|
void ofApp::draw(){ |
|
|
void ofApp::draw(){ |
|
|
map.Draw(); |
|
|
map.Draw(); |
|
|
|
|
|
|
|
|
renderDepthMap(); |
|
|
screen_fbo.begin(); |
|
|
|
|
|
|
|
|
if(!firstRun && detected_faces.size() != 0){ |
|
|
// Calculate the target width and height for model_output_fbo_1
|
|
|
faceDetector.DrawBox(detected_faces); |
|
|
float fbo_1_target_width = window_width * 0.5; // 1/2 of the screen width (990px)
|
|
|
faceDetector.DrawCenter(detected_faces); |
|
|
float fbo_1_target_height = window_height; // Full height of the screen
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the aspect ratio of the video and the FBO
|
|
|
|
|
|
float video_aspect_ratio = model_output_fbo_1.getWidth() / model_output_fbo_1.getHeight(); |
|
|
|
|
|
float fbo_aspect_ratio = fbo_1_target_width / fbo_1_target_height; |
|
|
|
|
|
|
|
|
|
|
|
// Adjust the scaling to cover the FBO area while maintaining aspect ratio
|
|
|
|
|
|
float new_width, new_height; |
|
|
|
|
|
if (fbo_aspect_ratio > video_aspect_ratio) { |
|
|
|
|
|
// FBO is wider; scale by width to fill the FBO
|
|
|
|
|
|
new_width = fbo_1_target_width; |
|
|
|
|
|
new_height = new_width / video_aspect_ratio; // Scale height to maintain aspect ratio
|
|
|
|
|
|
} else { |
|
|
|
|
|
// FBO is taller; scale by height to fill the FBO
|
|
|
|
|
|
new_height = fbo_1_target_height; |
|
|
|
|
|
new_width = new_height * video_aspect_ratio; // Scale width to maintain aspect ratio
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Center the video to ensure it fills the FBO and is cropped if necessary
|
|
|
|
|
|
float x_pos = (window_width * 0.75) - (new_width / 2); |
|
|
|
|
|
float y_pos = (window_height - new_height) / 2; // Center vertically
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the scaled video inside the FBO
|
|
|
|
|
|
model_output_fbo_1.draw(x_pos, y_pos, new_width, new_height); |
|
|
|
|
|
|
|
|
|
|
|
model_output_fbo.draw(0, 0); |
|
|
|
|
|
|
|
|
|
|
|
screen_fbo.end(); |
|
|
|
|
|
|
|
|
|
|
|
renderDepthMap(); |
|
|
|
|
|
|
|
|
|
|
|
// if(!firstRun && detected_faces.size() != 0){
|
|
|
|
|
|
// faceDetector.DrawBox(detected_faces);
|
|
|
|
|
|
// faceDetector.DrawCenter(detected_faces);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
ofPushMatrix(); |
|
|
ofPushMatrix(); |
|
|
ofSetColor(255); |
|
|
ofSetColor(255); |
|
|
ofSetBackgroundColor(0); |
|
|
ofSetBackgroundColor(0); |
|
|
tf.drawString(std::to_string(ofGetFrameRate()), 10, 30); |
|
|
tf.drawString(std::to_string(ofGetFrameRate()), 10, 30); |
|
|
ofPopMatrix(); |
|
|
ofPopMatrix(); |
|
|
|
|
|
|
|
|
// emoteImage.draw(640, 0);
|
|
|
// emoteImage.draw(640, 0);
|
|
|
// for(auto& face : detected_faces){
|
|
|
// for(auto& face : detected_faces){
|
|
|
// ofDrawBitmapString(std::to_string(face.box.emotional_state.emotions[0]), 700, 300);
|
|
|
// ofDrawBitmapString(std::to_string(face.box.emotional_state.emotions[0]), 700, 300);
|
|
@ -143,6 +179,19 @@ void ofApp::draw(){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ofApp::inferDepthImage(ofFbo& fbo, ofImage& img, Onnx& model){ |
|
|
|
|
|
auto output_tensors = model.Run(img); |
|
|
|
|
|
float* output_ptr = output_tensors.front().GetTensorMutableData<float>(); |
|
|
|
|
|
size_t num_elements = output_tensors.front().GetTensorTypeAndShapeInfo().GetElementCount(); |
|
|
|
|
|
|
|
|
|
|
|
float min_value = model.ReduceMin(output_ptr, num_elements); |
|
|
|
|
|
float max_value = model.ReduceMax(output_ptr, num_elements); |
|
|
|
|
|
|
|
|
|
|
|
model.Normalize(output_ptr, num_elements, min_value, max_value); |
|
|
|
|
|
|
|
|
|
|
|
model.DataToFbo(output_ptr, 518, 518, fbo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|
void ofApp::inferEmotionalState(){ |
|
|
void ofApp::inferEmotionalState(){ |
|
|
|
|
|
|
|
@ -184,15 +233,17 @@ void ofApp::inferEmotionalState(){ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Depth Map Shader Pass |
|
|
|
|
|
*/ |
|
|
void ofApp::renderDepthMap(){ |
|
|
void ofApp::renderDepthMap(){ |
|
|
rampedFbo.begin(); |
|
|
rampedFbo.begin(); |
|
|
|
|
|
|
|
|
depthToColourShader.begin(); |
|
|
depthToColourShader.begin(); |
|
|
depthToColourShader.setUniformTexture("tex0", fbo.getTexture(), 0); |
|
|
depthToColourShader.setUniformTexture("tex0", screen_fbo.getTexture(), 0); |
|
|
depthToColourShader.setUniformTexture("tex1", map.fboImage.getTexture(), 1); |
|
|
|
|
|
depthToColourShader.setUniform1f("texW", rampedFbo.getWidth()); |
|
|
depthToColourShader.setUniform1f("texW", rampedFbo.getWidth()); |
|
|
depthToColourShader.setUniform1f("texH", rampedFbo.getHeight()); |
|
|
depthToColourShader.setUniform1f("texH", rampedFbo.getHeight()); |
|
|
fbo.draw(0, 0); |
|
|
screen_fbo.draw(0, 0); |
|
|
depthToColourShader.end(); |
|
|
depthToColourShader.end(); |
|
|
|
|
|
|
|
|
rampedFbo.end(); |
|
|
rampedFbo.end(); |
|
|