|
|
@ -3,17 +3,6 @@ |
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::setup(){ |
|
|
|
|
|
|
|
|
|
|
|
const int vectorCount = 10000; |
|
|
|
const int dimension = 7; |
|
|
|
const int queryCount = 10; |
|
|
|
const int k = 5; // Number of nearest neighbors to find
|
|
|
|
|
|
|
|
auto vectors = vp_tree.generateRandomVectors(vectorCount, dimension); |
|
|
|
|
|
|
|
vpt::VpTree tree = vp_tree.buildTree(vectors); |
|
|
|
vp_tree.saveTree("./data/vp-tree.bin", tree); |
|
|
|
|
|
|
|
/* allocated fbo's */ |
|
|
|
map_fbo.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), GL_RGB); |
|
|
|
portrait_fbo.allocate((ofGetWindowWidth() / 3) * 1, ofGetWindowHeight(), GL_RGBA); |
|
|
@ -49,7 +38,7 @@ void ofApp::setup(){ |
|
|
|
ORTCHAR_T* modelPath = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/image-to-mesh/bin/data/models/depth_anything_v2_vits.onnx"; |
|
|
|
|
|
|
|
/* setup */ |
|
|
|
bullet.setup(); |
|
|
|
//bullet.setup(nodes);
|
|
|
|
|
|
|
|
depth_onnx.Setup(modelPath, true, true); |
|
|
|
depth_onnx_esp.Setup(modelPath, true, true); |
|
|
@ -57,21 +46,6 @@ void ofApp::setup(){ |
|
|
|
depth_thread.setup(&model_image, &model_outptut_fbo, &depth_onnx); |
|
|
|
depth_esp.setup(&model_image_esp, &model_esp_out_fbo, &depth_onnx_esp); |
|
|
|
|
|
|
|
/* vp-test */ |
|
|
|
auto queries = server->generateRandomVectors(queryCount, dimension); |
|
|
|
|
|
|
|
for (const auto& query : queries) { |
|
|
|
auto [distances, indices] = tree.getNearestNeighbors(query, k); |
|
|
|
|
|
|
|
// Uncomment the following lines to print results for each query
|
|
|
|
std::cout << "Query: "; |
|
|
|
for (double d : query) std::cout << d << " "; |
|
|
|
std::cout << "\nNearest neighbors:\n"; |
|
|
|
for (int i = 0; i < k; ++i) { |
|
|
|
std::cout << " Index: " << indices[i] << ", Distance: " << distances[i] << "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* mesh generation test */ |
|
|
|
std::string path = "images"; |
|
|
@ -95,17 +69,19 @@ void ofApp::setup(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<ofMesh> mesh_list; |
|
|
|
// vector<ofMesh> mesh_list;
|
|
|
|
|
|
|
|
for(auto& img : images){ |
|
|
|
mesh_list = mesh_generator.generateSimplifiedMesh(img); |
|
|
|
bullet.addMesh(mesh_list[0], mesh_list[1], img.getTexture()); |
|
|
|
mesh_list.clear(); |
|
|
|
} |
|
|
|
// for(auto& img : images){
|
|
|
|
// mesh_list = mesh_generator.generateSimplifiedMesh(img);
|
|
|
|
// bullet.addMesh(mesh_list[0], mesh_list[1], img.getTexture());
|
|
|
|
// mesh_list.clear();
|
|
|
|
// }
|
|
|
|
|
|
|
|
last_updated_time = ofGetElapsedTimef(); |
|
|
|
|
|
|
|
server = std::make_unique<Server>(6762, embed, vp_tree, false, "192.168.0.253", 2000, "search"); |
|
|
|
createNodes("data/json/embeddings.json"); |
|
|
|
|
|
|
|
server = std::make_unique<Server>(6762, embed, vp_tree, nodes, false, "192.168.0.253", 2000, "search"); |
|
|
|
server->start(); |
|
|
|
} |
|
|
|
|
|
|
@ -144,7 +120,7 @@ void ofApp::update(){ |
|
|
|
std::cout << "Model did not run" << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
bullet.update(); |
|
|
|
//bullet.update();
|
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
@ -153,7 +129,7 @@ void ofApp::draw(){ |
|
|
|
ofPushStyle(); |
|
|
|
map_fbo.begin(); |
|
|
|
ofClear(ofColor::grey); |
|
|
|
bullet.draw(); |
|
|
|
//bullet.draw();
|
|
|
|
map_fbo.end(); |
|
|
|
ofPopStyle(); |
|
|
|
|
|
|
@ -251,59 +227,102 @@ void ofApp::getNearestImages(){ |
|
|
|
model_image_esp.setFromPixels(esp_comp_pixels); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::keyPressed(int key){ |
|
|
|
void ofApp::createNodes(std::string json_path){ |
|
|
|
|
|
|
|
} |
|
|
|
/* read in json */ |
|
|
|
json = ofLoadJson(json_path); |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::keyReleased(int key){ |
|
|
|
|
|
|
|
} |
|
|
|
if(!json.is_array()){ |
|
|
|
ofLogError() << "json is not array"; |
|
|
|
return; |
|
|
|
} else { |
|
|
|
ofLogNotice() << "json loaded"; |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseMoved(int x, int y ){ |
|
|
|
/* setup nodes */ |
|
|
|
for(const auto& j : json){ |
|
|
|
if(j.contains("vector") && j["vector"].is_array()){ |
|
|
|
Node n; |
|
|
|
n.img.load(j["image"]); |
|
|
|
std::vector<float> t_embedding; |
|
|
|
|
|
|
|
for (const auto& value: j["vector"]){ |
|
|
|
if(value.is_number()){ |
|
|
|
t_embedding.push_back(value.get<float>()); |
|
|
|
} else { |
|
|
|
ofLogError() << "Vector value is not a number"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
n.raw_embedding = t_embedding; |
|
|
|
nodes.push_back(n); |
|
|
|
} |
|
|
|
} |
|
|
|
ofLogNotice() << "node count: " << nodes.size(); |
|
|
|
|
|
|
|
} |
|
|
|
/* build vp_tree */ |
|
|
|
auto vectors = createDoubleVectorFromNodes(nodes); |
|
|
|
vp_tree.buildTree(vectors); |
|
|
|
ofLogNotice() << "vpt built"; |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseDragged(int x, int y, int button){ |
|
|
|
/* run tsne */ |
|
|
|
vector<vector<float>> tsne_input; |
|
|
|
std::vector<std::vector<double>> tsne_points; |
|
|
|
|
|
|
|
} |
|
|
|
for(const auto& n : nodes){ |
|
|
|
tsne_input.push_back(n.raw_embedding); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mousePressed(int x, int y, int button){ |
|
|
|
|
|
|
|
} |
|
|
|
tsne_points = tsne.run(tsne_input, dims, perplexity, theta, normalise, runManually); |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseReleased(int x, int y, int button){ |
|
|
|
for(size_t i = 0; i < tsne_points.size(); i++){ |
|
|
|
const auto& vec = tsne_points[i]; |
|
|
|
auto& n = nodes[i]; |
|
|
|
n.tsne_position = (glm::vec3(vec[0] * tsne_scale, vec[1] * tsne_scale, -5.0f)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/* vp-test */ |
|
|
|
// auto queries = server->generateRandomVectors(10, 7);
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseEntered(int x, int y){ |
|
|
|
// int k = 5;
|
|
|
|
|
|
|
|
} |
|
|
|
// vector<vector<float>> test_vectors;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::mouseExited(int x, int y){ |
|
|
|
// // Set up random number generator
|
|
|
|
// std::random_device rd;
|
|
|
|
// std::mt19937 gen(rd());
|
|
|
|
// std::uniform_real_distribution<> dis(0.0, 1.0); // Random floats between -1 and 1
|
|
|
|
|
|
|
|
} |
|
|
|
// for (int i = 0; i < 1; ++i) {
|
|
|
|
// std::vector<float> vec;
|
|
|
|
// for (int j = 0; j < 7; ++j) {
|
|
|
|
// vec.push_back(static_cast<float>(dis(gen)));
|
|
|
|
// }
|
|
|
|
// test_vectors.push_back(vec);
|
|
|
|
// }
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::windowResized(int w, int h){ |
|
|
|
// std::cout << test_vectors.size() << std::endl;
|
|
|
|
|
|
|
|
// vector<int> q_index = vp_tree.query(test_vectors, 5);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::gotMessage(ofMessage msg){ |
|
|
|
std::vector<std::vector<double>> ofApp::createDoubleVectorFromNodes(const std::vector<Node>& nodes) { |
|
|
|
std::vector<std::vector<double>> result; |
|
|
|
result.reserve(nodes.size()); |
|
|
|
|
|
|
|
} |
|
|
|
for (const auto& node : nodes) { |
|
|
|
std::vector<double> doubleVector; |
|
|
|
doubleVector.reserve(node.raw_embedding.size()); |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::dragEvent(ofDragInfo dragInfo){ |
|
|
|
for (const float& value : node.raw_embedding) { |
|
|
|
doubleVector.push_back(static_cast<double>(value)); |
|
|
|
} |
|
|
|
|
|
|
|
result.push_back(std::move(doubleVector)); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
void ofApp::exit(){ |
|
|
|