|
|
@ -9,7 +9,6 @@ void ofApp::setup(){ |
|
|
|
const int queryCount = 10; |
|
|
|
const int k = 5; // Number of nearest neighbors to find
|
|
|
|
|
|
|
|
// Generate random vectors
|
|
|
|
auto vectors = vp_tree.generateRandomVectors(vectorCount, dimension); |
|
|
|
|
|
|
|
vpt::VpTree tree = vp_tree.buildTree(vectors); |
|
|
@ -20,9 +19,23 @@ void ofApp::setup(){ |
|
|
|
portrait_fbo.allocate((ofGetWindowWidth() / 3) * 1, ofGetWindowHeight(), GL_RGBA); |
|
|
|
comp_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|
|
|
model_outptut_fbo.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), GL_RGB); |
|
|
|
model_esp_out_fbo.allocate(128 * 2, 168 * 2, GL_RGB); |
|
|
|
|
|
|
|
/* k-d image comp (4-images) */ |
|
|
|
esp_comp_fbo.allocate(128 * 2, 168 * 2, GL_RGB); |
|
|
|
|
|
|
|
/* input images for model */ |
|
|
|
model_image_esp.allocate(128 * 2, 168 * 2, OF_IMAGE_COLOR); |
|
|
|
model_image.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), OF_IMAGE_COLOR); |
|
|
|
|
|
|
|
|
|
|
|
/* allocated ofImages in esp_images */ |
|
|
|
for(int i = 0; i < 4; i++){ |
|
|
|
ofFbo temp; |
|
|
|
temp.allocate(128, 168, GL_RGB); |
|
|
|
esp_images.push_back(temp); |
|
|
|
} |
|
|
|
|
|
|
|
/* of settings (not sure why putting this at the start of setup breaks the map - but it works!) */ |
|
|
|
ofSetVerticalSync(true); |
|
|
|
ofDisableArbTex(); |
|
|
@ -39,11 +52,10 @@ void ofApp::setup(){ |
|
|
|
bullet.setup(); |
|
|
|
|
|
|
|
depth_onnx.Setup(modelPath, true, true); |
|
|
|
depth_onnx_esp.Setup(modelPath, true, true); |
|
|
|
|
|
|
|
depth_thread.setup(&model_image, &model_outptut_fbo, &depth_onnx); |
|
|
|
|
|
|
|
server = std::make_unique<Server>(12345, embed, vp_tree, false, "192.168.0.253", 2000, "search"); |
|
|
|
server->start(); |
|
|
|
depth_esp.setup(&model_image_esp, &model_esp_out_fbo, &depth_onnx_esp); |
|
|
|
|
|
|
|
/* vp-test */ |
|
|
|
auto queries = server->generateRandomVectors(queryCount, dimension); |
|
|
@ -90,12 +102,29 @@ void ofApp::setup(){ |
|
|
|
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"); |
|
|
|
server->start(); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::update(){ |
|
|
|
|
|
|
|
server->update(model_esp_out_fbo); |
|
|
|
|
|
|
|
float current_time = ofGetElapsedTimef(); |
|
|
|
if(current_time - last_updated_time >= 3){ |
|
|
|
getNearestImages(); |
|
|
|
last_updated_time = current_time; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ofGetFrameNum() < 1){ |
|
|
|
depth_thread.start(); |
|
|
|
depth_esp.start(); |
|
|
|
} |
|
|
|
|
|
|
|
/* write pixels to model input image */ |
|
|
@ -105,7 +134,11 @@ void ofApp::update(){ |
|
|
|
|
|
|
|
try{ |
|
|
|
depth_thread.update(); |
|
|
|
depth_esp.update(); |
|
|
|
|
|
|
|
/* set output to fbo's */ |
|
|
|
depth_onnx.SetPixels(model_outptut_fbo); |
|
|
|
depth_onnx_esp.SetPixels(model_esp_out_fbo); |
|
|
|
|
|
|
|
} catch (exception e){ |
|
|
|
std::cout << "Model did not run" << std::endl; |
|
|
@ -143,6 +176,9 @@ void ofApp::draw(){ |
|
|
|
|
|
|
|
comp_fbo.draw(0,0); |
|
|
|
model_outptut_fbo.draw(ofGetWindowWidth() / 2, 0); |
|
|
|
model_esp_out_fbo.draw(0, 0); |
|
|
|
|
|
|
|
//server->print();
|
|
|
|
//shader_fbo.draw(0, 0);
|
|
|
|
// float planeScale = 0.75;
|
|
|
|
// int planeWidth = ofGetWidth() * planeScale;
|
|
|
@ -168,6 +204,53 @@ void ofApp::draw(){ |
|
|
|
//t.draw(ofGetWindowWidth() / 2, 0);
|
|
|
|
} |
|
|
|
|
|
|
|
/* creates an fbo with four cropped images, to preprare for model input */ |
|
|
|
void ofApp::getNearestImages(){ |
|
|
|
esp_comp_fbo.begin(); |
|
|
|
ofClear(255, 255, 255, 0); |
|
|
|
|
|
|
|
ofImage random_image; |
|
|
|
|
|
|
|
int imageIndex = 0; |
|
|
|
for(auto& img : esp_images){ |
|
|
|
random_image = images[ofRandom(images.size() - 1)]; |
|
|
|
// Calculate the scaling factor
|
|
|
|
float widthRatio = 128.0f / random_image.getWidth(); |
|
|
|
float heightRatio = 168.0f / random_image.getHeight(); |
|
|
|
float scale = std::max(widthRatio, heightRatio); |
|
|
|
|
|
|
|
// Calculate new dimensions
|
|
|
|
int newWidth = std::ceil(random_image.getWidth() * scale); |
|
|
|
int newHeight = std::ceil(random_image.getHeight() * scale); |
|
|
|
|
|
|
|
// Resize the image
|
|
|
|
random_image.resize(newWidth, newHeight); |
|
|
|
|
|
|
|
// Calculate the crop position to center the image
|
|
|
|
int cropX = (newWidth - 128) / 2; |
|
|
|
int cropY = (newHeight - 168) / 2; |
|
|
|
|
|
|
|
// Ensure crop dimensions don't exceed the image size
|
|
|
|
int cropWidth = std::min(128, newWidth); |
|
|
|
int cropHeight = std::min(168, newHeight); |
|
|
|
|
|
|
|
// Calculate the drawing position based on the image index
|
|
|
|
int drawX = (imageIndex % 2) * 128; |
|
|
|
int drawY = (imageIndex / 2) * 168; |
|
|
|
|
|
|
|
// Draw the resized and cropped image
|
|
|
|
random_image.drawSubsection(drawX, drawY, cropWidth, cropHeight, cropX, cropY); |
|
|
|
|
|
|
|
imageIndex++; |
|
|
|
if (imageIndex >= 4) break; // Stop after drawing 4 images
|
|
|
|
} |
|
|
|
esp_comp_fbo.end(); |
|
|
|
|
|
|
|
|
|
|
|
esp_comp_fbo.readToPixels(esp_comp_pixels); |
|
|
|
model_image_esp.setFromPixels(esp_comp_pixels); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::keyPressed(int key){ |
|
|
|
|
|
|
@ -223,3 +306,8 @@ void ofApp::dragEvent(ofDragInfo dragInfo){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void ofApp::exit(){ |
|
|
|
std::cout << "closing server" << std::endl; |
|
|
|
server->close(); |
|
|
|
} |
|
|
|
|
|
|
|