View my account

[L515]Is it possible to match alignment of color image and depth image?

Comments

4 comments

  • Zulkifli Halim

    Hello N Kanbe l9,

     

    Change the line:

    align_to = rs.stream.color
    align = rs.align(align_to)

     

    with the line:

    align_to = rs.stream.depth
    align = rs.align(align_to)

     

    For the noise, we still investigating the issue. 

     

    Regards,

    Zulkifli 

    0
    Comment actions Permalink
  • Zulkifli Halim

    Hello N Kanbe l9,

     

    We suggest you use this python code:

    import pyrealsense2 as rs
    import numpy as np
    import cv2

    pipeline = rs.pipeline()

    config = rs.config()
    config.enable_stream(rs.stream.depth, 1280, 768, rs.format.z16, 30)
    config.enable_stream(rs.stream.color, 1280, 768, rs.format.bgr8, 30)

    profile = pipeline.start(config)

    depth_sensor = profile.get_device().first_depth_sensor()
    depth_scale = depth_sensor.get_depth_scale()
    print("Depth Scale is: " , depth_scale)

    clipping_distance_in_meters = 1 #1 meter
    clipping_distance = clipping_distance_in_meters / depth_scale

    align_to = rs.stream.color
    align = rs.align(align_to)

    try:
        while True:
            frames = pipeline.wait_for_frames()

            aligned_frames = align.process(frames)
            aligned_depth_frame = aligned_frames.get_depth_frame() # aligned_depth_frame is a 640x480 depth image

            color_frame = aligned_frames.get_color_frame()

            if not aligned_depth_frame or not color_frame:
                continue

            depth_image = np.asanyarray(aligned_depth_frame.get_data())
            color_image = np.asanyarray(color_frame.get_data())
            depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

            images = np.hstack((color_image, depth_colormap))

            cv2.namedWindow('Align Example', cv2.WINDOW_AUTOSIZE)
            cv2.imshow('Align Example', images)

            key = cv2.waitKey(1)
            if key & 0xFF == ord('q') or key == 27:
                cv2.destroyAllWindows()

                break
    finally:
        pipeline.stop()

     

    Regards,

    Zulkifli

    0
    Comment actions Permalink
  • N Kanbe I9

    Thank you very much.

    Since the range of color images is narrow, we will consider other methods.

    0
    Comment actions Permalink
  • Fvargas

    he corregido el codigo ahora funciona:::::

     

    import pyrealsense2 as rs
    import numpy as np
    import cv2

     

     

    # Configure depth and color streams
    pipeline = rs.pipeline()
    config = rs.config()

    # Get device product line for setting a supporting resolution
    pipeline_wrapper = rs.pipeline_wrapper(pipeline)
    pipeline_profile = config.resolve(pipeline_wrapper)
    device = pipeline_profile.get_device()
    device_product_line = str(device.get_info(rs.camera_info.product_line))

    config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)

    config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

    # Start streaming
    pipeline.start(config)

     


    depth_sensor = device.first_depth_sensor()
    depth_scale = depth_sensor.get_depth_scale()

     


    print("Depth Scale is: " , depth_scale)

    clipping_distance_in_meters = 1 #1 meter
    clipping_distance = clipping_distance_in_meters / depth_scale

    align_to = rs.stream.color
    align = rs.align(align_to)

    try:
    while True:
    frames = pipeline.wait_for_frames()

    aligned_frames = align.process(frames)
    aligned_depth_frame = aligned_frames.get_depth_frame() # aligned_depth_frame is a 640x480 depth image

    color_frame = aligned_frames.get_color_frame()

    if not aligned_depth_frame or not color_frame:
    continue

    depth_image = np.asanyarray(aligned_depth_frame.get_data())
    color_image = np.asanyarray(color_frame.get_data())
    depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

    images = np.hstack((color_image, depth_colormap))

    cv2.namedWindow('Align Example', cv2.WINDOW_AUTOSIZE)
    cv2.imshow('Align Example', images)

    key = cv2.waitKey(1)
    if key & 0xFF == ord('q') or key == 27:
    cv2.destroyAllWindows()

    break
    finally:
    pipeline.stop()

    0
    Comment actions Permalink

Please sign in to leave a comment.