|
@ -4,11 +4,16 @@ |
|
|
void ofApp::setup(){ |
|
|
void ofApp::setup(){ |
|
|
|
|
|
|
|
|
/* allocated fbo's */ |
|
|
/* allocated fbo's */ |
|
|
map_fbo.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), GL_RGB); |
|
|
map_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGB); |
|
|
portrait_fbo.allocate((ofGetWindowWidth() / 3) * 1, ofGetWindowHeight(), GL_RGBA); |
|
|
map_fbo_alpha.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|
|
|
|
|
portrait_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|
|
|
|
|
portrait_pre_fbo.allocate((ofGetWindowWidth() / 3) * 1, ofGetWindowHeight(), GL_RGB); |
|
|
|
|
|
portrait_pre_fbo_alpha.allocate((ofGetWindowWidth() / 3) * 1, ofGetWindowHeight(), GL_RGBA); |
|
|
comp_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|
|
comp_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA); |
|
|
model_outptut_fbo.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), GL_RGB); |
|
|
|
|
|
|
|
|
model_outptut_fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGB); |
|
|
model_esp_out_fbo.allocate(128 * 2, 168 * 2, GL_RGB); |
|
|
model_esp_out_fbo.allocate(128 * 2, 168 * 2, GL_RGB); |
|
|
|
|
|
model_portrait_out_fbo.allocate(portrait_pre_fbo_alpha.getWidth(), portrait_pre_fbo_alpha.getHeight(), GL_RGB); |
|
|
|
|
|
|
|
|
/* k-d image comp (4-images) */ |
|
|
/* k-d image comp (4-images) */ |
|
|
kd_out.allocate(128 * 2, 168 * 2, GL_RGB); |
|
|
kd_out.allocate(128 * 2, 168 * 2, GL_RGB); |
|
@ -16,8 +21,10 @@ void ofApp::setup(){ |
|
|
|
|
|
|
|
|
/* input images for model */ |
|
|
/* input images for model */ |
|
|
model_image_esp.allocate(128 * 2, 168 * 2, OF_IMAGE_COLOR); |
|
|
model_image_esp.allocate(128 * 2, 168 * 2, OF_IMAGE_COLOR); |
|
|
model_image.allocate((ofGetWindowWidth() / 3) * 2, ofGetWindowHeight(), OF_IMAGE_COLOR); |
|
|
model_image.allocate(ofGetWindowWidth(), ofGetWindowHeight(), OF_IMAGE_COLOR); |
|
|
|
|
|
model_image_portrait.allocate(portrait_pre_fbo_alpha.getWidth(), portrait_pre_fbo_alpha.getHeight(), OF_IMAGE_COLOR); |
|
|
|
|
|
|
|
|
|
|
|
map_pixels.allocate(ofGetWindowWidth(), ofGetWindowHeight(), OF_PIXELS_RGB); |
|
|
|
|
|
|
|
|
/* allocated ofImages in esp_images */ |
|
|
/* allocated ofImages in esp_images */ |
|
|
for(int i = 0; i < 4; i++){ |
|
|
for(int i = 0; i < 4; i++){ |
|
@ -34,22 +41,33 @@ void ofApp::setup(){ |
|
|
ofEnableAlphaBlending(); |
|
|
ofEnableAlphaBlending(); |
|
|
|
|
|
|
|
|
/* load */ |
|
|
/* load */ |
|
|
|
|
|
ofLoadImage(bayer, "images/bayer.png"); |
|
|
|
|
|
bayer.setTextureWrap(GL_REPEAT, GL_REPEAT); |
|
|
shaders.load("shaders/dither"); |
|
|
shaders.load("shaders/dither"); |
|
|
esp_shader.load("shaders/espDepth"); |
|
|
esp_shader.load("shaders/espDepth"); |
|
|
|
|
|
vert_snap.load("shaders/vertex_snap"); |
|
|
|
|
|
p_depth.load("shaders/p_depth"); |
|
|
|
|
|
|
|
|
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"; |
|
|
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"; |
|
|
|
|
|
ORTCHAR_T* modelPath_Small = "/home/cailean/Desktop/openframeworks/of_v0.12.0_linux64gcc6_release/apps/myApps/image-to-mesh/bin/data/models/depth_anything_v2_vits.onnx"; |
|
|
|
|
|
|
|
|
/* setup */ |
|
|
/* setup */ |
|
|
bullet.setup(nodes); |
|
|
bullet.setup(nodes); |
|
|
|
|
|
|
|
|
depth_onnx.Setup(modelPath, true, true); |
|
|
depth_onnx.Setup(modelPath, false, true); |
|
|
depth_onnx_esp.Setup(modelPath, true, true); |
|
|
depth_onnx_esp.Setup(modelPath_Small, false, true); |
|
|
|
|
|
depth_onnx_portrait.Setup(modelPath_Small, false, true); |
|
|
|
|
|
|
|
|
depth_thread.setup(&model_image, &model_outptut_fbo, &depth_onnx); |
|
|
depth_thread.setup(&model_image, &model_outptut_fbo, &depth_onnx); |
|
|
depth_esp.setup(&model_image_esp, &model_esp_out_fbo, &depth_onnx_esp); |
|
|
depth_esp.setup(&model_image_esp, &model_esp_out_fbo, &depth_onnx_esp); |
|
|
|
|
|
depth_portrait.setup(&model_image_portrait, &model_portrait_out_fbo, &depth_onnx_portrait); |
|
|
|
|
|
|
|
|
ofLoadImage(bayer, "images/bayer.png"); |
|
|
/* camera settings for portrait */ |
|
|
bayer.setTextureWrap(GL_REPEAT, GL_REPEAT); |
|
|
portrait_camera.setFov(90); |
|
|
|
|
|
portrait_camera.setPosition(0, 150, 480); |
|
|
|
|
|
portrait_camera.removeAllInteractions(); |
|
|
|
|
|
portrait_camera.disableMouseInput(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createNodes("data/json/embeddings.json"); |
|
|
createNodes("data/json/embeddings.json"); |
|
|
|
|
|
|
|
@ -82,20 +100,28 @@ void ofApp::update(){ |
|
|
if(ofGetFrameNum() < 1){ |
|
|
if(ofGetFrameNum() < 1){ |
|
|
depth_thread.start(); |
|
|
depth_thread.start(); |
|
|
depth_esp.start(); |
|
|
depth_esp.start(); |
|
|
|
|
|
depth_portrait.start(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* write pixels to model input image */ |
|
|
/* write pixels to model input image */ |
|
|
map_fbo.readToPixels(map_pixels); |
|
|
try{ |
|
|
model_image.setFromPixels(map_pixels); |
|
|
map_fbo.readToPixels(map_pixels); |
|
|
|
|
|
model_image.setFromPixels(map_pixels); |
|
|
|
|
|
} catch (exception e) { |
|
|
|
|
|
ofLogError() << "couldn't set pixels!"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
try{ |
|
|
depth_thread.update(); |
|
|
depth_thread.update(); |
|
|
depth_esp.update(); |
|
|
depth_esp.update(); |
|
|
|
|
|
depth_portrait.update(); |
|
|
|
|
|
|
|
|
/* set output to fbo's */ |
|
|
/* set output to fbo's */ |
|
|
depth_onnx.SetPixels(model_outptut_fbo); |
|
|
depth_onnx.SetPixels(model_outptut_fbo); |
|
|
depth_onnx_esp.SetPixels(model_esp_out_fbo); |
|
|
depth_onnx_esp.SetPixels(model_esp_out_fbo); |
|
|
|
|
|
depth_onnx_portrait.SetPixels(model_portrait_out_fbo); |
|
|
|
|
|
|
|
|
} catch (exception e){ |
|
|
} catch (exception e){ |
|
|
std::cout << "Model did not run" << std::endl; |
|
|
std::cout << "Model did not run" << std::endl; |
|
@ -108,67 +134,124 @@ void ofApp::update(){ |
|
|
void ofApp::draw(){ |
|
|
void ofApp::draw(){ |
|
|
|
|
|
|
|
|
ofPushStyle(); |
|
|
ofPushStyle(); |
|
|
map_fbo.begin(); |
|
|
map_fbo_alpha.begin(); |
|
|
ofClear(ofColor::grey); |
|
|
ofClear(0, 0, 0, 0); |
|
|
bullet.draw(); |
|
|
bullet.draw(); |
|
|
map_fbo.end(); |
|
|
map_fbo_alpha.end(); |
|
|
ofPopStyle(); |
|
|
ofPopStyle(); |
|
|
|
|
|
|
|
|
|
|
|
map_fbo.begin(); |
|
|
|
|
|
ofClear(0, 0, 0, 0); |
|
|
|
|
|
map_fbo_alpha.draw(0, 0); |
|
|
|
|
|
map_fbo.end(); |
|
|
|
|
|
|
|
|
ofTexture t = map_fbo.getTexture(); |
|
|
ofTexture t = map_fbo.getTexture(); |
|
|
|
|
|
ofTexture d = model_outptut_fbo.getTexture(); |
|
|
|
|
|
|
|
|
|
|
|
//model_outptut_fbo.draw(ofGetWindowWidth() / 2, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esp_comp_fbo.begin(); |
|
|
|
|
|
|
|
|
|
|
|
esp_shader.begin(); |
|
|
|
|
|
esp_shader.setUniformTexture("tex0", model_esp_out_fbo.getTexture(), 0); |
|
|
|
|
|
model_esp_out_fbo.draw(0, 0); |
|
|
|
|
|
esp_comp_fbo.end(); |
|
|
|
|
|
esp_shader.end(); |
|
|
|
|
|
|
|
|
|
|
|
portrait_fbo.begin(); |
|
|
|
|
|
|
|
|
|
|
|
ofBackground(0, 0, 0, 0); |
|
|
|
|
|
|
|
|
|
|
|
drawPortraitZ(); |
|
|
|
|
|
|
|
|
|
|
|
portrait_fbo.end(); |
|
|
|
|
|
|
|
|
|
|
|
drawPortrait(); |
|
|
|
|
|
|
|
|
comp_fbo.begin(); |
|
|
comp_fbo.begin(); |
|
|
|
|
|
ofClear(0, 0, 0, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shaders.begin(); |
|
|
shaders.begin(); |
|
|
shaders.setUniformTexture("tex0", t, 0); |
|
|
shaders.setUniformTexture("tex0", t, 0); |
|
|
shaders.setUniformTexture("tex1", bayer, 1); |
|
|
shaders.setUniformTexture("tex1", bayer, 1); |
|
|
shaders.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); |
|
|
shaders.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); |
|
|
shaders.setUniform1f("time", ofGetElapsedTimef()); |
|
|
shaders.setUniform1f("time", ofGetElapsedTimef()); |
|
|
shaders.setUniform1i("frame", ofGetFrameNum()); |
|
|
shaders.setUniform1i("frame", ofGetFrameNum()); |
|
|
ofClear(0, 0, 0, 0); |
|
|
model_outptut_fbo.draw(0, 0); |
|
|
map_fbo.draw(0,0); |
|
|
portrait_fbo.draw(0, 0); |
|
|
|
|
|
map_fbo_alpha.draw(0,0); |
|
|
shaders.end(); |
|
|
shaders.end(); |
|
|
comp_fbo.end(); |
|
|
comp_fbo.end(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
comp_fbo.draw(0,0); |
|
|
comp_fbo.draw(0,0); |
|
|
model_outptut_fbo.draw(ofGetWindowWidth() / 2, 0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esp_comp_fbo.begin(); |
|
|
|
|
|
|
|
|
|
|
|
esp_shader.begin(); |
|
|
|
|
|
esp_shader.setUniformTexture("tex0", model_esp_out_fbo.getTexture(), 0); |
|
|
|
|
|
model_esp_out_fbo.draw(0, 0); |
|
|
|
|
|
esp_comp_fbo.end(); |
|
|
|
|
|
esp_shader.end(); |
|
|
|
|
|
|
|
|
|
|
|
esp_comp_fbo.draw(0, 0); |
|
|
void ofApp::drawPortrait(){ |
|
|
|
|
|
|
|
|
|
|
|
Node n = server->getChosenNode(); |
|
|
|
|
|
portrait_pre_fbo.begin(); |
|
|
|
|
|
float scale = min( |
|
|
|
|
|
(float)portrait_pre_fbo.getWidth() / n.img.getWidth(), |
|
|
|
|
|
(float)portrait_pre_fbo.getHeight() / n.img.getHeight() |
|
|
|
|
|
); |
|
|
|
|
|
float scaledWidth = n.img.getWidth() * scale; |
|
|
|
|
|
float scaledHeight = n.img.getHeight() * scale; |
|
|
|
|
|
float xPos = (portrait_pre_fbo.getWidth() - scaledWidth) / 2; |
|
|
|
|
|
float yPos = (portrait_pre_fbo.getHeight() - scaledHeight) / 2; |
|
|
|
|
|
n.img.draw(xPos, yPos, scaledWidth, scaledHeight); |
|
|
|
|
|
portrait_pre_fbo.end(); |
|
|
|
|
|
|
|
|
|
|
|
portrait_pre_fbo_alpha.begin(); |
|
|
|
|
|
ofClear(0, 0, 0, 0); |
|
|
|
|
|
n.img.draw(xPos, yPos, scaledWidth, scaledHeight); |
|
|
|
|
|
portrait_pre_fbo_alpha.end(); |
|
|
|
|
|
|
|
|
//server->print();
|
|
|
ofPixels pix; |
|
|
//shader_fbo.draw(0, 0);
|
|
|
portrait_pre_fbo.readToPixels(pix); |
|
|
// float planeScale = 0.75;
|
|
|
model_image_portrait.setFromPixels(pix); |
|
|
// int planeWidth = ofGetWidth() * planeScale;
|
|
|
} |
|
|
// int planeHeight = ofGetHeight() * planeScale;
|
|
|
|
|
|
// int planeGridSize = 20;
|
|
|
|
|
|
// int planeColumns = planeWidth / planeGridSize;
|
|
|
|
|
|
// int planeRows = planeHeight / planeGridSize;
|
|
|
|
|
|
|
|
|
|
|
|
// plane.set(planeWidth, planeHeight, planeColumns, planeRows, OF_PRIMITIVE_TRIANGLES);
|
|
|
void ofApp::drawPortraitZ(){ |
|
|
|
|
|
ofTexture tex_color = portrait_pre_fbo_alpha.getTexture(); |
|
|
|
|
|
ofTexture tex_depth = model_portrait_out_fbo.getTexture(); |
|
|
|
|
|
|
|
|
// plane.mapTexCoordsFromTexture(t);
|
|
|
portrait_camera.begin(); |
|
|
|
|
|
ofEnableDepthTest(); |
|
|
|
|
|
|
|
|
// t.bind();
|
|
|
float time = ofGetElapsedTimef() / 10; |
|
|
// shaders.begin();
|
|
|
float p_noise_x = ofSignedNoise(time, time) * 20; |
|
|
// ofPushMatrix();
|
|
|
float p_noise_y = ofSignedNoise(time + 100, time + 100) * 20; |
|
|
// ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
|
|
|
|
|
|
// plane.draw();
|
|
|
|
|
|
// ofPopMatrix();
|
|
|
|
|
|
// shaders.end();
|
|
|
|
|
|
// t.unbind();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ofPushMatrix(); |
|
|
|
|
|
|
|
|
|
|
|
float planeScale = 1.0; |
|
|
|
|
|
int planeWidth = portrait_pre_fbo_alpha.getWidth() * planeScale; |
|
|
|
|
|
int planeHeight = portrait_pre_fbo_alpha.getHeight() * planeScale; |
|
|
|
|
|
int planeGridSize = plane_size; |
|
|
|
|
|
int planeColumns = planeWidth / planeGridSize; |
|
|
|
|
|
int planeRows = planeHeight / planeGridSize; |
|
|
|
|
|
|
|
|
|
|
|
plane.set(planeWidth, planeHeight, planeColumns, planeRows, OF_PRIMITIVE_TRIANGLES); |
|
|
|
|
|
plane.mapTexCoords(0, 0, planeWidth, planeHeight); |
|
|
|
|
|
|
|
|
|
|
|
p_depth.begin(); |
|
|
|
|
|
p_depth.setUniform1f("gridSize", g_size); |
|
|
|
|
|
p_depth.setUniform2f("resolution", glm::vec2(portrait_fbo.getWidth(), portrait_fbo.getHeight())); |
|
|
|
|
|
p_depth.setUniformTexture("tex0", tex_color, 0); |
|
|
|
|
|
p_depth.setUniformTexture("tex1", tex_depth, 1); |
|
|
|
|
|
ofFill(); |
|
|
|
|
|
ofTranslate(p_noise_x, p_noise_y, 0); |
|
|
|
|
|
plane.draw(); |
|
|
|
|
|
p_depth.end(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ofPopMatrix(); |
|
|
|
|
|
ofDisableDepthTest(); |
|
|
|
|
|
|
|
|
//t.draw(ofGetWindowWidth() / 2, 0);
|
|
|
portrait_camera.end(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* creates an fbo with four cropped images, to preprare for model input */ |
|
|
/* creates an fbo with four cropped images, to preprare for model input */ |
|
@ -372,7 +455,27 @@ void ofApp::queryKD(glm::vec3& _position, int k){ |
|
|
|
|
|
|
|
|
size_t index = kd_result[0].second; |
|
|
size_t index = kd_result[0].second; |
|
|
|
|
|
|
|
|
std::cout << "camera positions: " << _position << ", nearest node: "<< nodes[index].tsne_position << " " << index << std::endl; |
|
|
//std::cout << "camera positions: " << _position << ", nearest node: "<< nodes[index].tsne_position << " " << index << std::endl;
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ofApp::keyPressed(int key) { |
|
|
|
|
|
switch(key) { |
|
|
|
|
|
case OF_KEY_UP: |
|
|
|
|
|
g_size += 10; |
|
|
|
|
|
ofLog() << "Grid Size: " << g_size; |
|
|
|
|
|
break; |
|
|
|
|
|
case OF_KEY_DOWN: |
|
|
|
|
|
g_size -= 10; |
|
|
|
|
|
ofLog() << "Grid Size: " << g_size; |
|
|
|
|
|
break; |
|
|
|
|
|
case 'q': |
|
|
|
|
|
plane_size += 10; |
|
|
|
|
|
ofLog() << "Plane Size: " << plane_size; |
|
|
|
|
|
break; |
|
|
|
|
|
case 'w': |
|
|
|
|
|
plane_size -=10; |
|
|
|
|
|
ofLog() << "Plane Size: " << plane_size; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |