05-18-2022, 07:46 PM

To reproduce: Place a camera in a scene and point it at a 30x50x10 mm block (attached). Take a depth image of it with:

Open the resulting pcd.xyz file with MeshLab or your pointcloud viewer of choice.

Expected result: the resulting pointcloud is a rectangular block and has dimensions 30x50x10.

Actual result: the resulting pointcloud does not have dimensions 30x50x10 and has angles that are not 90 degrees.

Fixing z-distortion: if I insert the following line just after normalizing img to be between 0 and 1:

then the resulting pointcloud has correct dimensions. Note that the transformation above takes 0 to 0 and 1 to 1 and takes straight lines and flat planes to straight lines and flat planes, but distorts distances and angles. Maybe someone inserted some sort of gamma correction somewhere?

Code:

`from robodk import robolink`

import numpy as np

import os

import time

RDK = robolink.Robolink()

# Get depth snapshot

cam = RDK.Item('Depth Camera')

cam.setParam('Open')

time.sleep(0.1)

RDK.Cam2D_Snapshot(os.path.join(os.path.abspath('.'), 'tmp.grey32'), cam, 'Depth')

grey32 = np.fromfile('tmp.grey32', dtype='>u4')

w, h = grey32[:2]

img = np.flipud(np.reshape(grey32[2:], (h, w)))

img = (img / np.iinfo(np.uint32).max) # rescale to float 0.0 to 1.0

FAR_LENGTH = 100 # whatever FAR_LENGTH is set to

img = img * FAR_LENGTH

img = img.astype(np.uint16)

# Save as pointcloud with open3d

import open3d as o3d

FOV = 63.91 # whatever FOV is set to

fy = h / (2*np.tan(np.radians(FOV) / 2)) # FOV is camera field of view

intrinsic = o3d.camera.PinholeCameraIntrinsic(

width=w,

height=h,

fx=fy, # Use same value for fx and fy

fy=fy,

cx=w / 2,

cy=h / 2,

)

pcd = o3d.geometry.PointCloud.create_from_depth_image(o3d.geometry.Image(img), intrinsic)

o3d.io.write_point_cloud('pcd.xyz', pcd, write_ascii=True)

Expected result: the resulting pointcloud is a rectangular block and has dimensions 30x50x10.

Actual result: the resulting pointcloud does not have dimensions 30x50x10 and has angles that are not 90 degrees.

Fixing z-distortion: if I insert the following line just after normalizing img to be between 0 and 1:

Code:

`img = img / (2 - img)`

**Attached Files**

30x50x10.stl (Size: 684 bytes / Downloads: 126)