diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b9ff5a2..9866e07 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -107,7 +107,14 @@ "${workspaceRoot}", "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/src", "/usr/local/onnxruntime-linux-x64-gpu-1.19.2/include", - "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/libs/opencv/include/opencv4" + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOpenCv/libs/opencv/include/opencv4", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/src", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxNetwork/src", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxGui/src", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxTSNE/src", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/libs/oscpack/src/osc", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxOsc/libs/oscpack/src/ip", + "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/addons/ofxTSNE/src/bhtsne" ], "browse": { "limitSymbolsToIncludedHeaders": true, diff --git a/addons.make b/addons.make index ecff515..c9ca0d6 100644 --- a/addons.make +++ b/addons.make @@ -1,2 +1,10 @@ ofxOpenCv ofxOpenCv +ofxOsc +ofxOsc +ofxNetwork +ofxNetwork +ofxGui +ofxGui +ofxTSNE +ofxTSNE \ No newline at end of file diff --git a/src/Map.cpp b/src/Map.cpp new file mode 100644 index 0000000..7b23eb1 --- /dev/null +++ b/src/Map.cpp @@ -0,0 +1,70 @@ +#include "Map.h" + +Map::Map(){ + +} + +void Map::Setup(){ + ofDisableArbTex(); + isDebug = true; + + json_embeddings = ofLoadJson(jsonPath); + if(!json_embeddings.is_array()){ + ofLogError() << "JSON is not an array"; + return; + } else { + std::cout << "JSON LOADED" << std::endl; + SetupTSNE(); + } + + mapFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); +} + +void Map::Update(){ + +} + +void Map::Draw(){ + +} + +void Map::SetupNodes(){ + +} + +void Map::SetupTSNE(){ + for (const auto& entry: json_embeddings) { + if (entry.contains("vector") && entry["vector"].is_array()) { + Node n; + n.foldername = entry["folder"]; + n.image_path = entry["image"]; + n.isLost = entry["lost"].get(); + + std::vector emb; + + for (const auto& value: entry["vector"]){ + if(value.is_number()){ + emb.push_back(value.get()); + } else { + ofLogError() << "Vector value is not a number"; + } + } + + n.emotion_vector = emb; + + nodes.push_back(n); + embeddings.push_back(emb); + } + } + + std::cout << nodes.size() << std::endl; + std::cout << embeddings.size() << std::endl; + points = tsne.run(embeddings, dims, perplexity, theta, normalise, runManually); + + for (size_t i = 0; i < points.size(); i++){ + const auto& vec = points[i]; + auto& n = nodes[i]; + n.position = glm::vec3(vec[0], vec[1], vec[2]); + } + +} \ No newline at end of file diff --git a/src/Map.h b/src/Map.h new file mode 100644 index 0000000..b848c75 --- /dev/null +++ b/src/Map.h @@ -0,0 +1,65 @@ +#ifndef _MAP +#define _MAP + +#include "ofMain.h" +#include "ofxOsc.h" +#include "ofxTSNE.h" + +struct Node { + glm::vec2 speed; + glm::vec2 amplitude; + glm::vec2 phase; + ofImage texture; + glm::vec3 position; + std::string image_path; + std::string foldername; + std::vector emotion_vector; + int isLost; +}; + +class Map { + public: + + /* + Constructor + */ + + Map(); + + + /* + Methods + */ + + void Setup(); + void Update(); + void Draw(); + void SetupNodes(); + void SetupTSNE(); + + /* + Variables + */ + bool isDebug; + + ofFbo mapFbo; + vector geoms; + vector nodes; + + ofxTSNE tsne; + vector> points; + vector> embeddings; + int dims = 3; + float perplexity = 20; + float theta = 0.2; + bool normalise = true; + bool runManually = false; + ofJson json_embeddings; + std::string jsonPath = "data/json/embeddings.json"; + + private: + + +}; + +#endif \ No newline at end of file diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 4fbd135..6720ebe 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -5,6 +5,8 @@ void ofApp::setup(){ ofSetFrameRate(24); ofSetVerticalSync(true); + map.Setup(); + player.Setup(); player.SetVideo("videos/demo.mp4", fbo); diff --git a/src/ofApp.h b/src/ofApp.h index 3970985..a51db76 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -7,6 +7,7 @@ #include "Yolo.h" #include #include "Player.h" +#include "Map.h" class ofApp : public ofBaseApp{ @@ -46,4 +47,6 @@ class ofApp : public ofBaseApp{ Emotef emo; Yolo faceDetector; std::vector detected_faces; + + Map map; };