|
@ -3,28 +3,31 @@ |
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|
void ofApp::setup(){ |
|
|
void ofApp::setup(){ |
|
|
ofDisableArbTex(); |
|
|
ofDisableArbTex(); |
|
|
ofSetFrameRate(24); |
|
|
ofSetFrameRate(60); |
|
|
ofSetVerticalSync(true); |
|
|
// ofSetVerticalSync(true);
|
|
|
|
|
|
|
|
|
|
|
|
tf.load("data/fonts/jetbrainsmono-regular.ttf", 20); |
|
|
|
|
|
|
|
|
map.Setup(); |
|
|
map.Setup(); |
|
|
|
|
|
|
|
|
player.Setup(); |
|
|
//player.Setup();
|
|
|
player.SetVideo("videos/demo.mp4", fbo); |
|
|
//player.SetVideo("videos/demo.mp4", fbo);
|
|
|
|
|
|
|
|
|
emoteImage.allocate(260, 260); |
|
|
//emoteImage.allocate(260, 260);
|
|
|
tempImage.allocate(emoteImage.getWidth(), emoteImage.getHeight(), OF_IMAGE_COLOR); |
|
|
//tempImage.allocate(emoteImage.getWidth(), emoteImage.getHeight(), OF_IMAGE_COLOR);
|
|
|
|
|
|
|
|
|
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"; |
|
|
|
|
|
|
|
|
/* Setup Models (modelPath, log, useCuda) */ |
|
|
/* 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); |
|
|
emotion.Setup(modelPath3, false, true); |
|
|
//emotion.Setup(modelPath3, false, true);
|
|
|
|
|
|
|
|
|
/* Load shader, allocated rampedFbo */ |
|
|
/* Load shader, allocated rampedFbo */ |
|
|
depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); |
|
|
depthToColourShader.load("data/shader/rampShader.vert", "data/shader/rampShader.frag"); |
|
|
|
|
|
fbo.allocate(1600, 800, GL_RGB); |
|
|
rampedFbo.allocate(1600, 800); |
|
|
rampedFbo.allocate(1600, 800); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -34,6 +37,7 @@ 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; |
|
|
|
|
|
|
|
@ -48,11 +52,13 @@ 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{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto output_tensors = depth.Run(map.fboImage); |
|
|
auto output_tensors = depth.Run(map.fboImage); |
|
|
float* output_ptr = output_tensors.front().GetTensorMutableData<float>(); |
|
|
float* output_ptr = output_tensors.front().GetTensorMutableData<float>(); |
|
|
size_t num_elements = output_tensors.front().GetTensorTypeAndShapeInfo().GetElementCount(); |
|
|
size_t num_elements = output_tensors.front().GetTensorTypeAndShapeInfo().GetElementCount(); |
|
@ -64,17 +70,17 @@ void ofApp::update(){ |
|
|
|
|
|
|
|
|
depth.DataToFbo(output_ptr, 518, 518, fbo); |
|
|
depth.DataToFbo(output_ptr, 518, 518, fbo); |
|
|
|
|
|
|
|
|
auto output_tensors_face = yolo.Run(map.fboImage); |
|
|
// 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, fbo.getWidth(), fbo.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 */ |
|
@ -86,13 +92,13 @@ void ofApp::update(){ |
|
|
If the batch_size does change it will completely slow down inference, due to how the cudnn_search_algo is set. |
|
|
If the batch_size does change it will completely slow down inference, due to how the cudnn_search_algo is set. |
|
|
None of the other search alogithms bar EXHAUSTIVE will work.. no idea why. |
|
|
None of the other search alogithms bar EXHAUSTIVE will work.. no idea why. |
|
|
*/ |
|
|
*/ |
|
|
for(int i = 0; i < emotionImageMaxBatchSize; i++){ |
|
|
// for(int i = 0; i < emotionImageMaxBatchSize; i++){
|
|
|
tempImage.setFromPixels(emoteImage.getPixels()); |
|
|
// tempImage.setFromPixels(emoteImage.getPixels());
|
|
|
croppedFaces.push_back(tempImage); |
|
|
// croppedFaces.push_back(tempImage);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
// Run model to warmup
|
|
|
// Run model to warmup
|
|
|
auto emotion_output_tensor = emotion.RunBatch(croppedFaces); |
|
|
// auto emotion_output_tensor = emotion.RunBatch(croppedFaces);
|
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
//inferEmotionalState();
|
|
|
//inferEmotionalState();
|
|
@ -107,23 +113,39 @@ void ofApp::update(){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|
void ofApp::draw(){ |
|
|
void ofApp::draw(){ |
|
|
|
|
|
auto start = std::chrono::high_resolution_clock::now(); |
|
|
map.Draw(); |
|
|
map.Draw(); |
|
|
|
|
|
|
|
|
renderDepthMap(); |
|
|
renderDepthMap(); |
|
|
|
|
|
|
|
|
if(!firstRun){ |
|
|
// if(!firstRun){
|
|
|
faceDetector.DrawBox(detected_faces); |
|
|
// faceDetector.DrawBox(detected_faces);
|
|
|
faceDetector.DrawCenter(detected_faces); |
|
|
// faceDetector.DrawCenter(detected_faces);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
ofPushMatrix(); |
|
|
|
|
|
ofSetColor(255); |
|
|
|
|
|
ofSetBackgroundColor(0); |
|
|
|
|
|
tf.drawString(std::to_string(ofGetFrameRate()), 10, 30); |
|
|
|
|
|
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);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
auto end = std::chrono::high_resolution_clock::now(); |
|
|
|
|
|
std::chrono::duration<float> duration = end - start; |
|
|
|
|
|
std::cout << "Time taken for Draw: " << duration.count() << " seconds" << std::endl; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
@ -185,9 +207,9 @@ void ofApp::renderDepthMap(){ |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|
void ofApp::keyPressed(int key){ |
|
|
void ofApp::keyPressed(int key){ |
|
|
if (key=OF_KEY_LEFT){ |
|
|
// if (key=OF_KEY_LEFT){
|
|
|
player.SetRandomFrame(); |
|
|
// player.SetRandomFrame();
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
//--------------------------------------------------------------
|
|
|