• DepthAI-v2
  • X_LINK_ERROR with ToF camera in a Jupyter notebook

Hello:

What is the best way to query a ToF camera (OAK-FFC ToF 33D) using DepthAI in a Jupyter Notebook?

When I take the tof_depth.py example code and run it directly in a Jupyter Notebook it gives communication errors on the dai.Device(pipeline).getOutputQueue(name="depth").get() call.

I followed the advise on a related issue with an 'rgb' camera and it seems to be connecting via USB3 when the python (not Jupyter notebook) is called.

Thanks!

PS. If it helps, please see the notebook is here.  The full error is:

Cell In[10], line 4
1# Connect to device and start pipeline
2q = dai.Device(pipeline).getOutputQueue(name="depth") ---->
4 imgFrame = q.get() # blocking call, will wait until a new data has arrived
5depth_map = imgFrame.getFrame()
7# Colorize the depth frame to jet colormap RuntimeError: Communication exception - possible device error/misconfiguration. Original message 'Couldn't read data from stream: 'depth' (X_LINK_ERROR)'

    Hi spnsingh
    Does an RGB example work? Can you get preview stream from OV9782 camera?

    Thanks,
    Jaka

    Hi Jaka,

    At present, I just have a ToF 33D camera for the OAK-FFC-3P we have.
    (I can order one and get back to you on this.)

    Thanks,
    Surya

      Hi spnsingh
      Could you post the whole notebook please. I can test this locally to see if I can reproduce the issue.

      Thanks,
      Jaka

        Hi Jaka,

        I have uploaded the Jupyter Notebook again (via Google Drive).

        For simplicity, there is not much to it. It basically runs through the tof_depth.py example, but as a notebook.

        What might be causing the 'Couldn't read data from stream: 'depth' (X_LINK_ERROR)' message?

        Thanks,

        Surya

        Hi @spnsingh
        The way you have divided your blocks opens the code up for a bunch of errors. Please put the pipeline related code in its own cell.
        You can put the rest in a separate cell but keep in mind that each time you use dai.Device(), the device will be opened and run.

        Call the device with this code.

        # Connect to device and start pipeline
        with dai.Device(pipeline) as device:
            print('Connected cameras:', device.getConnectedCameraFeatures())
            q = device.getOutputQueue(name="depth")
        
            while True:
                imgFrame = q.get()  # blocking call, will wait until a new data has arrived
                depth_map = imgFrame.getFrame()
        
                # Colorize the depth frame to jet colormap
                depth_downscaled = depth_map[::4]
                non_zero_depth = depth_downscaled[depth_downscaled != 0] # Remove invalid depth values
                if len(non_zero_depth) == 0:
                    min_depth, max_depth = 0, 0
                else:
                    min_depth = np.percentile(non_zero_depth, 3)
                    max_depth = np.percentile(non_zero_depth, 97)
                depth_colorized = np.interp(depth_map, (min_depth, max_depth), (0, 255)).astype(np.uint8)
                depth_colorized = cv2.applyColorMap(depth_colorized, cv2.COLORMAP_JET)
        
                cv2.imshow("Colorized depth", depth_colorized)
        
                if cv2.waitKey(1) == ord('q'):
                    break

        Thanks,
        Jaka

          jakaskerl

          Thanks. Perhaps the point is there a good way to open the device, do some interactive things (across multiple cells), and then close then device.

          Using with dai.Device(pipeline) as device everytime is slow because opening and closing the device takes 2-3 seconds each.

          Otherwise, yes, I agree that this approach does resolve the connection issue. Thank you!

          Hi @spnsingh
          The issue is that by only booting the device and not creating queues, the device has nowhere to put the frames so you have to specify the nodes to non-blocking.

          Thanks
          Jaka