Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert the depth map to 3D point clouds?

When I convert depth map to 3D point cloud, I found there is a term called scaling factor. Can anyone give me some idea what scaling factor actually is. Is there any relationship between scaling factor and focal length. The code is as follows:

import argparse
import sys
import os
from PIL import Image

focalLength = 938.0
centerX = 319.5
centerY = 239.5
scalingFactor = 5000

def generate_pointcloud(rgb_file,depth_file,ply_file):

    rgb = Image.open(rgb_file)
    depth = Image.open(depth_file).convert('I')

    if rgb.size != depth.size:
        raise Exception("Color and depth image do not have the same 
resolution.")
    if rgb.mode != "RGB":
        raise Exception("Color image is not in RGB format")
    if depth.mode != "I":
        raise Exception("Depth image is not in intensity format")


    points = []    
    for v in range(rgb.size[1]):
        for u in range(rgb.size[0]):
            color = rgb.getpixel((u,v))
            Z = depth.getpixel((u,v)) / scalingFactor
            print(Z)
            if Z==0: continue
            X = (u - centerX) * Z / focalLength
            Y = (v - centerY) * Z / focalLength
            points.append("%f %f %f %d %d %d 0\n"% 
like image 566
d19911222 Avatar asked Apr 01 '18 14:04

d19911222


People also ask

How do I get point cloud from depth image?

Factory function to create a pointcloud from a depth image and a camera. Given depth value d at (u, v) image coordinate, the corresponding 3d point is: z = d / depth_scale. x = (u - cx) * z / fx.

What is 3D depth map?

In 3D computer graphics and computer vision, a depth map is an image or image channel that contains information relating to the distance of the surfaces of scene objects from a viewpoint. The term is related (and may be analogous) to depth buffer, Z-buffer, Z-buffering, and Z-depth.

Can you create point cloud from photos?

The ELCOVISION 10 software creates 3D point clouds from real photos using photogrammetry. 3D point clouds have conquered the digital world in the past two years. There are many different ways to create a 3D view of an object.


1 Answers

In this context "scaling factor" refers to the relation between depth map units and meters; it has nothing to do with the focal length of the camera.

Depth maps are typically stored in 16-bit unsigned integers at millimeter scale, thus to obtain Z value in meters, the depth map pixels need to be divided by 1000. You have a somewhat unconventional scaling factor of 5000, meaning that the unit of your depth maps is 200 micrometers.

like image 144
taketwo Avatar answered Sep 24 '22 21:09

taketwo