microsoft / Azure-Kinect-Sensor-SDK

A cross platform (Linux and Windows) user mode SDK to read data from your Azure Kinect device.
https://Azure.com/Kinect
MIT License
1.47k stars 613 forks source link

How to transform depth to color image offline? #1918

Open pursueyyh opened 1 year ago

pursueyyh commented 1 year ago

Hello Professor, I am trying to transform depth to color image offline. However, the code I used as shown bellow return transformed image with all zeros. Could you please help me to check the code? Or is there another way to transform depth to color image offline? Looking forward to your reply.

def transform_depth_color(args): with k4a.Device.open() as device: device_config = k4a.DeviceConfiguration( color_format=k4a.EImageFormat.COLOR_BGRA32, color_resolution=COLOR_RESOLUTION[args.resolution], depth_mode=DEPTH_MODE[args.depth_mode], camera_fps=FPS[args.fps], synchronized_images_only=True, depth_delay_off_color_usec=0, wired_sync_mode=k4a.EWiredSyncMode.STANDALONE, subordinate_delay_off_master_usec=0, disable_streaming_indicator=False)

    status = device.start_cameras(device_config)

    if status != k4a.EStatus.SUCCEEDED:
        raise IOError("Failed to start cameras.")

    calibration = device.get_calibration(
        depth_mode=device_config.depth_mode,
        color_resolution=device_config.color_resolution)

    depth_arr = np.array(cv2.imread(args.filename, cv2.CV_16UC1))
    depth = Image.create(image_format=k4a.EImageFormat.DEPTH16, width_pixels=depth_arr.shape[1], height_pixels=depth_arr.shape[0], stride_bytes=depth_arr.shape[1]*depth_arr.itemsize)
    depth._data = depth_arr

    transform = k4a.Transformation(calibration)
    depth_transformed = transform.depth_image_to_color_camera(depth)._data
    # print(np.max(depth_transformed)) # 0
    depth_transformed = cv2.imwrite(args.filename.replace('.png', '_trans_m.png'), depth_transformed)

kinect_6_color kinect_6_depth kinect_6_depth_trans_m