dkogan / mrcal

Next-generation camera-modeling toolkit
http://mrcal.secretsauce.net
Apache License 2.0
196 stars 16 forks source link

point cloud reconstruction from time of flight camera depth image #23

Open Baehn opened 3 months ago

Baehn commented 3 months ago

I have a time of flight camera, that is I get a depth image as raw data from my camera, after calibration, is mrcal.unprocject the supposed way to compute the corresponding point cloud, e.g. like this?:

import numpy as np
import mrcal

model = mrcal.cameramodel(filename)
depth_image = ...  # load depth image
width, height = depth_image.shape
x, y = np.mgrid[0:width, 0:height]
points = np.stack((x, y), axis=-1).reshape(-1, 2)
upts = mrcal.unproject(points, *model.intrinsics(), normalize=True)

points_3d = (upts.T * depth_image.flatten()).T
dkogan commented 3 months ago

From a high-level, that's right: you mrcal.unproject() to get directions, and scale them up with the ranges. If it doesn't work, tell me.