From 729da3df8dc5cff807cb3278f419dd1601a673db Mon Sep 17 00:00:00 2001 From: Dan Zhu Date: Wed, 19 Jun 2019 21:34:22 -0700 Subject: [PATCH] add output of frame info Change-Id: I70d750be13d9a654d1f21d7809d8d44c491ae477 --- .../sketch_3D_reconstruction/MotionField.pde | 15 +++++++++++++++ .../3D-Reconstruction/sketch_3D_reconstruction/Scene.pde | 9 +++++++++ .../sketch_3D_reconstruction/sketch_3D_reconstruction.pde | 11 +++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/3D-Reconstruction/sketch_3D_reconstruction/MotionField.pde b/tools/3D-Reconstruction/sketch_3D_reconstruction/MotionField.pde index dbba327..883a8f8 100644 --- a/tools/3D-Reconstruction/sketch_3D_reconstruction/MotionField.pde +++ b/tools/3D-Reconstruction/sketch_3D_reconstruction/MotionField.pde @@ -76,4 +76,19 @@ class MotionField { line(ox, oy, ox + mv.x, oy + mv.y); } } + + void save(String path) { + int r_num = height / block_size; + int c_num = width / block_size; + String[] mvs = new String[r_num]; + for (int i = 0; i < r_num; i++) { + mvs[i] = ""; + for (int j = 0; j < c_num; j++) { + PVector mv = motion_field.get(i * c_num + j); + mvs[i] += str(mv.x) + "," + str(mv.y); + if (j != c_num - 1) mvs[i] += ";"; + } + } + saveStrings(path, mvs); + } } diff --git a/tools/3D-Reconstruction/sketch_3D_reconstruction/Scene.pde b/tools/3D-Reconstruction/sketch_3D_reconstruction/Scene.pde index 6189bc0..cf79ab7 100644 --- a/tools/3D-Reconstruction/sketch_3D_reconstruction/Scene.pde +++ b/tools/3D-Reconstruction/sketch_3D_reconstruction/Scene.pde @@ -5,6 +5,7 @@ class Scene { MotionField motion_field; Camera last_cam; Camera current_cam; + int frame_count; Scene(Camera camera, PointCloud point_cloud, MotionField motion_field) { this.point_cloud = point_cloud; @@ -26,12 +27,14 @@ class Scene { bvh = new BVH(mesh); last_cam = camera.copy(); current_cam = camera; + frame_count = 0; } void run() { last_cam = current_cam.copy(); current_cam.run(); motion_field.update(last_cam, current_cam, point_cloud, bvh); + frame_count += 1; } void render(boolean show_motion_field) { @@ -47,4 +50,10 @@ class Scene { motion_field.render(); } } + + void save(String path) { saveFrame(path + "_" + str(frame_count) + ".png"); } + + void saveMotionField(String path) { + motion_field.save(path + "_" + str(frame_count) + ".txt"); + } } diff --git a/tools/3D-Reconstruction/sketch_3D_reconstruction/sketch_3D_reconstruction.pde b/tools/3D-Reconstruction/sketch_3D_reconstruction/sketch_3D_reconstruction.pde index f9745c8..22a4954 100644 --- a/tools/3D-Reconstruction/sketch_3D_reconstruction/sketch_3D_reconstruction.pde +++ b/tools/3D-Reconstruction/sketch_3D_reconstruction/sketch_3D_reconstruction.pde @@ -10,7 +10,7 @@ void setup() { // default settings int frame_no = 0; // frame number float fov = PI / 3; // field of view - int block_size = 32; // block size + int block_size = 8; // block size float normalizer = 5000.0f; // normalizer // initialize PointCloud point_cloud = new PointCloud(); @@ -62,6 +62,13 @@ void draw() { inter = true; } scene.render( - true); // true: turn on motion field; false: turn off motion field + false); // true: turn on motion field; false: turn off motion field + // save frame with no motion field + scene.save("../data/frame/raw"); + background(0); + scene.render(true); showGrids(scene.motion_field.block_size); + // save frame with motion field + scene.save("../data/frame/raw_mv"); + scene.saveMotionField("../data/frame/mv"); } -- 2.7.4