MCPcopy Index your code
hub / github.com/DIVE128/DMVSNet / generate_pointcloud

Function generate_pointcloud

tools.py:204–239  ·  view source on GitHub ↗

Generate a colored point cloud in PLY format from a color and a depth image. Input: rgb_file -- filename of color image depth_file -- filename of depth image ply_file -- filename of ply file

(rgb, depth, ply_file, intr, scale=1.0)

Source from the content-addressed store, hash-verified

202
203
204def generate_pointcloud(rgb, depth, ply_file, intr, scale=1.0):
205 """
206 Generate a colored point cloud in PLY format from a color and a depth image.
207
208 Input:
209 rgb_file -- filename of color image
210 depth_file -- filename of depth image
211 ply_file -- filename of ply file
212
213 """
214 fx, fy, cx, cy = intr[0, 0], intr[1, 1], intr[0, 2], intr[1, 2]
215 points = []
216 for v in range(rgb.shape[0]):
217 for u in range(rgb.shape[1]):
218 color = rgb[v, u] # rgb.getpixel((u, v))
219 Z = depth[v, u] / scale
220 if Z == 0: continue
221 X = (u - cx) * Z / fx
222 Y = (v - cy) * Z / fy
223 points.append("%f %f %f %d %d %d 0\n" % (X, Y, Z, color[0], color[1], color[2]))
224 file = open(ply_file, "w")
225 file.write('''ply
226 format ascii 1.0
227 element vertex %d
228 property float x
229 property float y
230 property float z
231 property uchar red
232 property uchar green
233 property uchar blue
234 property uchar alpha
235 end_header
236 %s
237 ''' % (len(points), "".join(points)))
238 file.close()
239 print("save ply, fx:{}, fy:{}, cx:{}, cy:{}".format(fx, fy, cx, cy))
240
241
242def get_schedular(optimizer, args):

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected