Skip to content

Commit c7d0c43

Browse files
committed
update to py39
1 parent 3f22a94 commit c7d0c43

File tree

4 files changed

+389
-375
lines changed

4 files changed

+389
-375
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
__pycache__
22
*.ply
3+
4+
.idea*

demo.py

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,60 @@
88

99
import fusion
1010

11-
1211
if __name__ == "__main__":
13-
# ======================================================================================================== #
14-
# (Optional) This is an example of how to compute the 3D bounds
15-
# in world coordinates of the convex hull of all camera view
16-
# frustums in the dataset
17-
# ======================================================================================================== #
18-
print("Estimating voxel volume bounds...")
19-
n_imgs = 1000
20-
cam_intr = np.loadtxt("data/camera-intrinsics.txt", delimiter=' ')
21-
vol_bnds = np.zeros((3,2))
22-
for i in range(n_imgs):
23-
# Read depth image and camera pose
24-
depth_im = cv2.imread("data/frame-%06d.depth.png"%(i),-1).astype(float)
25-
depth_im /= 1000. # depth is saved in 16-bit PNG in millimeters
26-
depth_im[depth_im == 65.535] = 0 # set invalid depth to 0 (specific to 7-scenes dataset)
27-
cam_pose = np.loadtxt("data/frame-%06d.pose.txt"%(i)) # 4x4 rigid transformation matrix
12+
# ======================================================================================================== #
13+
# (Optional) This is an example of how to compute the 3D bounds
14+
# in world coordinates of the convex hull of all camera view
15+
# frustums in the dataset
16+
# ======================================================================================================== #
17+
print("Estimating voxel volume bounds...")
18+
n_imgs = 1000
19+
cam_intr = np.loadtxt("data/camera-intrinsics.txt", delimiter=' ')
20+
vol_bnds = np.zeros((3, 2))
21+
for i in range(n_imgs):
22+
# Read depth image and camera pose
23+
depth_im = cv2.imread("data/frame-%06d.depth.png" % (i), -1).astype(float)
24+
depth_im /= 1000. # depth is saved in 16-bit PNG in millimeters
25+
depth_im[depth_im == 65.535] = 0 # set invalid depth to 0 (specific to 7-scenes dataset)
26+
cam_pose = np.loadtxt("data/frame-%06d.pose.txt" % (i)) # 4x4 rigid transformation matrix
2827

29-
# Compute camera view frustum and extend convex hull
30-
view_frust_pts = fusion.get_view_frustum(depth_im, cam_intr, cam_pose)
31-
vol_bnds[:,0] = np.minimum(vol_bnds[:,0], np.amin(view_frust_pts, axis=1))
32-
vol_bnds[:,1] = np.maximum(vol_bnds[:,1], np.amax(view_frust_pts, axis=1))
33-
# ======================================================================================================== #
28+
# Compute camera view frustum and extend convex hull
29+
view_frust_pts = fusion.get_view_frustum(depth_im, cam_intr, cam_pose)
30+
vol_bnds[:, 0] = np.minimum(vol_bnds[:, 0], np.amin(view_frust_pts, axis=1))
31+
vol_bnds[:, 1] = np.maximum(vol_bnds[:, 1], np.amax(view_frust_pts, axis=1))
32+
# ======================================================================================================== #
3433

35-
# ======================================================================================================== #
36-
# Integrate
37-
# ======================================================================================================== #
38-
# Initialize voxel volume
39-
print("Initializing voxel volume...")
40-
tsdf_vol = fusion.TSDFVolume(vol_bnds, voxel_size=0.02)
34+
# ======================================================================================================== #
35+
# Integrate
36+
# ======================================================================================================== #
37+
# Initialize voxel volume
38+
print("Initializing voxel volume...")
39+
tsdf_vol = fusion.TSDFVolume(vol_bnds, voxel_size=0.02)
4140

42-
# Loop through RGB-D images and fuse them together
43-
t0_elapse = time.time()
44-
for i in range(n_imgs):
45-
print("Fusing frame %d/%d"%(i+1, n_imgs))
41+
# Loop through RGB-D images and fuse them together
42+
t0_elapse = time.time()
43+
for i in range(n_imgs):
44+
print("Fusing frame %d/%d" % (i + 1, n_imgs))
4645

47-
# Read RGB-D image and camera pose
48-
color_image = cv2.cvtColor(cv2.imread("data/frame-%06d.color.jpg"%(i)), cv2.COLOR_BGR2RGB)
49-
depth_im = cv2.imread("data/frame-%06d.depth.png"%(i),-1).astype(float)
50-
depth_im /= 1000.
51-
depth_im[depth_im == 65.535] = 0
52-
cam_pose = np.loadtxt("data/frame-%06d.pose.txt"%(i))
46+
# Read RGB-D image and camera pose
47+
color_image = cv2.cvtColor(cv2.imread("data/frame-%06d.color.jpg" % (i)), cv2.COLOR_BGR2RGB)
48+
depth_im = cv2.imread("data/frame-%06d.depth.png" % (i), -1).astype(float)
49+
depth_im /= 1000.
50+
depth_im[depth_im == 65.535] = 0
51+
cam_pose = np.loadtxt("data/frame-%06d.pose.txt" % (i))
5352

54-
# Integrate observation into voxel volume (assume color aligned with depth)
55-
tsdf_vol.integrate(color_image, depth_im, cam_intr, cam_pose, obs_weight=1.)
53+
# Integrate observation into voxel volume (assume color aligned with depth)
54+
tsdf_vol.integrate(color_image, depth_im, cam_intr, cam_pose, obs_weight=1.)
5655

57-
fps = n_imgs / (time.time() - t0_elapse)
58-
print("Average FPS: {:.2f}".format(fps))
56+
fps = n_imgs / (time.time() - t0_elapse)
57+
print("Average FPS: {:.2f}".format(fps))
5958

60-
# Get mesh from voxel volume and save to disk (can be viewed with Meshlab)
61-
print("Saving mesh to mesh.ply...")
62-
verts, faces, norms, colors = tsdf_vol.get_mesh()
63-
fusion.meshwrite("mesh.ply", verts, faces, norms, colors)
59+
# Get mesh from voxel volume and save to disk (can be viewed with Meshlab)
60+
print("Saving mesh to mesh.ply...")
61+
verts, faces, norms, colors = tsdf_vol.get_mesh()
62+
fusion.meshwrite("mesh.ply", verts, faces, norms, colors)
6463

65-
# Get point cloud from voxel volume and save to disk (can be viewed with Meshlab)
66-
print("Saving point cloud to pc.ply...")
67-
point_cloud = tsdf_vol.get_point_cloud()
68-
fusion.pcwrite("pc.ply", point_cloud)
64+
# Get point cloud from voxel volume and save to disk (can be viewed with Meshlab)
65+
print("Saving point cloud to pc.ply...")
66+
point_cloud = tsdf_vol.get_point_cloud()
67+
fusion.pcwrite("pc.ply", point_cloud)

0 commit comments

Comments
 (0)