2

I am using the Intel RealSense L515. I want to align the depth and color images in two different numpy arrays so that their resolution is the same.

Here is my code

import pyrealsense2 as rs
import numpy as np


pc = rs.pointcloud()


pipe = rs.pipeline()
config = rs.config()

config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 960, 540, rs.format.bgr8, 30)

pipe.start(config)

try:

    frames = pipe.wait_for_frames()

    depth = frames.get_depth_frame()
    color = frames.get_color_frame()

    # These are the two different frames to align
    depth_image = np.asanyarray(depth.get_data())
    color_image = np.asanyarray(color.get_data())

    # The new color image
    # color_image_with_same_resolution = ?

finally:
    pipe.stop()

The color image has a greater resolution than the depth image. What would be the most efficient way to resize the color image so that it has the same dimensions as the depth image and each color pixel is mapped to the correct corresponding depth pixel. Speed and efficiency is critical in this scenario.

Essentially I want to be able to save two separate arrays that can be used in another program. The arrays must have the same dimension like this: (Z - Array 640x480x1) and (RGB -Array 640x480x3)

Paul Brink
  • 332
  • 1
  • 4
  • 21
  • What about calling [resize](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d)? – Jérôme Richard May 12 '21 at 15:26
  • I was hoping there was a way by using the librealsense module. For now I have just used opencv to resize the image. not sure if it is the best solution, but for now it has to do. – Paul Brink May 14 '21 at 10:10

2 Answers2

0

Check this librealsense example:

https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/align-depth2color.py

It uses pyrealsense2.align() which allows to perform alignment of depth frames to other frames.

0

The solution is very simple. When using the pyrealsense2 library its also very fast!

import pyrealsense2 as rs

pipeline = None
colorizer = rs.colorizer()
align = rs.align(rs.stream.depth)

pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16,30) config.enable_stream(rs.stream.color, 960, 540, rs.format.rgb8, 30)
profile = pipeline.start(config)

frameset = pipeline.wait_for_frames()
frameset = align.process(frameset)
aligned_color_frame = frameset.get_color_frame()
color_frame = np.asanyarray(aligned_color_frame.get_data())
depth = np.asanyarray(frameset.get_depth_frame().get_data())

Paul Brink
  • 332
  • 1
  • 4
  • 21