View my account

RealSense D415 and D405 Precision

Comments

13 comments

  • Kvuong

    Here is the code: 

    import pyrealsense2 as rs
    import numpy as np
    importcv2
    import matplotlib.pyplot as plt
    font = cv2.FONT_HERSHEY_SIMPLEX

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

    color_res = [1920, 1080]
    depth_res = [1280, 720]
    fps = 30
    crosshairsize = 2
    max_dist = 700
    min_dist = 450

    cfg.enable_stream(rs.stream.color, color_res[0],color_res[1], rs.format.bgr8, fps)
    cfg.enable_stream(rs.stream.depth, depth_res[0], depth_res[1], rs.format.z16, fps)

    color_path = 'rgb.avi'
    depth_path = 'depth.avi'

    colorwriter = cv2.VideoWriter(color_path, cv2.VideoWriter_fourcc(*'XVID'), fps, (color_res[0],color_res[1]), 1)
    depthwriter = cv2.VideoWriter(depth_path, cv2.VideoWriter_fourcc(*'XVID'), fps, (depth_res[0],depth_res[1]), 1)

    pipe.start(cfg)

    depth_array = np.empty(0)
    depth_pixel = [int(depth_res[0]/2),int(depth_res[1]/2)]

    def filter_depth(depth, time, max_dist,min_dist):
        for i in range(len(depth)-1,-1,-1):
            if depth[i] > max_dist:
                depth = np.delete(depth,i)
                time = np.delete(time,i)
                continue

            if depth[i] < min_dist:
                depth = np.delete(depth,i)
                time = np.delete(time,i)
                continue
        return depth, time

    while True:
        frame = pipe.wait_for_frames()
        depth_frame = frame.get_depth_frame()
        color_frame = frame.get_color_frame()

        depth_image = np.asanyarray(depth_frame.get_data())
        color_image = np.asanyarray(color_frame.get_data())
        depth_cm = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha = 0.3), cv2.COLORMAP_JET)

        depth_at_pixel = depth_image[depth_pixel[1],depth_pixel[0]]
        depth_array = np.append(depth_array, depth_at_pixel)

        cv2.circle(color_image,(int(color_res[0]/2),int(color_res[1]/2)), crosshairsize, (0,0,255), -1)
        cv2.putText(color_image,'Depth: ' + str(depth_at_pixel) + 'mm',(10,100), font, 4,(255,255,255),2,cv2.LINE_AA)

        colorwriter.write(color_image)
        depthwriter.write(depth_cm)

        cv2.imshow('rgb', color_image)
        cv2.imshow('depth', depth_cm)

        if cv2.waitKey(1) == ord('q'):
            break

    colorwriter.release()
    depthwriter.release()
    pipe.stop()

    time_per_frame = 1/fps
    total_time = len(depth_array) * time_per_frame
    time = np.linspace(0,total_time,len(depth_array))

    depth_filtered,time_filtered = filter_depth(depth_array,time,max_dist,min_dist)

    plt.scatter(time_filtered,depth_filtered)
    plt.xlabel("Time [seconds]")
    plt.ylabel("Depth [mm]")
    plt.title("Depth at Center of Frame")
    plt.grid(True)
    plt.show()

    print(depth_image)

    And an example of the frame I want to access submillimeter precision with. 
    [451. 458. 464. 468. 475. 483. 487. 493. 498. 504. 505. 511. 514. 517.
     517. 576. 568. 593. 588. 570. 566. 568. 567. 565. 567. 564. 561. 562.
     560. 558. 552. 550. 553. 554. 556. 560. 560. 557. 555. 553. 552. 553.
     558. 565. 569. 565. 539. 539. 540. 482. 470. 456. 528. 515. 486. 528.
     509. 468. 465. 460. 462. 468. 476. 510. 543. 605. 520. 498. 481. 489.
     485. 483. 482. 483. 480. 478. 477. 488. 500. 521. 553. 555. 560. 563.
     527. 605. 603.]
    0
    Comment actions Permalink
  • Kvuong

    Correction: In the comment above the array is a list of depths returned from a specific pixel captured in the data.

    0
    Comment actions Permalink
  • MartyG

    Hi Kvuong  The RealSense D405 camera is the only model that is officially described as having sub-millimeter accuracy.

    https://store.intelrealsense.com/buy-intel-realsense-depth-camera-d405.html

     

    D405 is designed to provide high accuracy, high quality images at very close range.  The ideal depth sensing range is 7 cm to 50 cm, though its minimum depth can go as low as 4 cm if the Disparity Shift option is used.

     

    D415 can also provide high accuracy, low error images at distances below 1 meter.  The D405 will be more accurate though as it is designed specifically to provide optimum results at those low distances.  A chart demonstrating the error over distance of D415 is shown below.

     

    0
    Comment actions Permalink
  • Kvuong

    Hi Marty, thanks for the info. Does this mean that with the D405 we can retrieve a depth field matrix that provides values that read less than a millimeter through the get_depth_frame() function? 

    Thanks,

    Kenneth

    0
    Comment actions Permalink
  • MartyG

    Sub-millimeter refers to how the D405 has a minimum object detection accuracy at 7 cm distance that is as low as 500 microns (0.5 millimeters, hence 'sub-millimeter').

    0
    Comment actions Permalink
  • Kvuong

    So there's no method to retrieving the depth at that .5mm value? I want that method.

    0
    Comment actions Permalink
  • MartyG

    RealSense cameras have a minimum depth sensing distance, below which depth data breaks up and then disappears.  By default on D405 this minimum distance is 7 cm, so the depth image will only contain depth representing distances 7 cm or further from the camera.  This minimum can be reduced down to 4 cm using the Disparity Shift option.  But it is not possible to read the depth at 0.5 mm distance from the surface of an object. 

    0
    Comment actions Permalink
  • Kvuong

    Hi Marty, thank you for the response but my question is a bit different. I just want to make sure that the camera returns depth at .5mm increments (although in the main page it says .1mm increments? Depth Camera D405 – Intel® RealSense™ Depth and Tracking Cameras (intelrealsense.com)). 

    For example, reading an object at 10cm, i can retrieve through code 10.05mm, 10.10mm, 10.15mm, etc.

     

    0
    Comment actions Permalink
  • MartyG

    Thanks very much for the clarification.

     

    You can customize the scale that depth measurements are reported in by changing the depth scale option.  By default on D405, depth is reported in the centimeter scale (0.01 cm for every depth unit).  This can be reduced to millimeter scale by changing the depth scale to 0.001 (0.001 millimeters per increment of depth).  

     

    0.0001 scale is the lowest that the D405 model can be set to.  D415's depth scale can be set as low as 0.000001.

     

    In the RealSense Viewer tool the Depth Scale option can be found under Stereo Module > Controls

    0
    Comment actions Permalink
  • Kvuong

    Hi Marty, that sounds great. Do you know how to change the depth scale in Python code?

     

     

    0
    Comment actions Permalink
  • MartyG

    The link below has Python scripting for changing the depth scale with the instruction rs.option.depth_units

    https://github.com/IntelRealSense/librealsense/issues/10976#issuecomment-1271236193

    0
    Comment actions Permalink
  • Kvuong

    Thank you marty, I got it working such that it can return a higher resolution depth scale. Currently I'm using the D415, and what it returns is quite noisy. Is this just a property of the D415 camera, and if I get a D405 then would this be more smooth?

    Thanks,

    Kenneth

    0
    Comment actions Permalink
  • MartyG

    Depth images generated by the D415 model have less depth noise than the D435 / D435i models and so D415 has around 2x less error over distance (known as RMS Error) than D435 / D435i.

     

    A key difference between D405 and D415 though is that the D415 is equipped with a built-in infrared pattern projector whilst D405 does not have a projector.  There is a phenomenon called laser speckle where the pattern of semi-random dots cast onto surfaces by the projector can add noise to the depth image. 

     

    You can test whether the D415's projector is negatively affecting results by disabling the projector.  This can be done by setting the Laser Power option to a value of '0'.  Python code for setting the Laser Power value can be found here:

    https://github.com/IntelRealSense/librealsense/issues/9327#issuecomment-872907782

    0
    Comment actions Permalink

Please sign in to leave a comment.