用力推ead Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(API) Cam2D_Snapshot depth image returns incorrect depth values
#1
To reproduce:Place a camera in a scene and point it at a 30x50x10 mm block (attached). Take a depth image of it with:
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
内在= 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)
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:

Code:
img = img / (2 - img)
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?


Attached Files
.stl 30x50x10.stl(Size: 684 bytes / Downloads: 164)


Messages In This Thread
(API) Cam2D_Snapshot depth image returns incorrect depth values - byhn-cso- 05-18-2022, 07:46 PM



Users browsing this thread:
1 Guest(s)