Example with Python

There are several steps to get camera data:
  1. Create a camera instance.

  2. Get camera resources

  3. Start the camera.

  4. Request a frame.

  5. Get Depth Data or Intensity Data from frame

  6. Release frame to buffer queue

  7. Stop the camera’s image acquisition thread

  8. Close the camera to free up resources

example

import cv2
import numpy as np
import ArducamDepthCamera as ac

def getPreviewRGB(preview: np.ndarray, confidence: np.ndarray) -> np.ndarray:
    preview = np.nan_to_num(preview)
    preview[confidence < 30] = (0, 0, 0)
    return preview

def main():
    cam = ac.ArducamCamera()
    black_color = (0, 0, 0)
    white_color = (255, 255, 255)

    ret = cam.open(ac.TOFConnect.CSI, 0)
    if ret != 0:
        print("Failed to open camera. Error code:", ret)
        return

    ret = cam.start(ac.TOFOutput.DEPTH)
    if ret != 0:
        print("Failed to start camera. Error code:", ret)
        cam.close()
        return

    r = cam.getControl(ac.TOFControl.RANGE)

    info = cam.getCameraInfo()
    print(f"Camera resolution: {info.width}x{info.height}")

    cv2.namedWindow("preview", cv2.WINDOW_AUTOSIZE)

    while True:
        frame = cam.requestFrame(2000)
        if frame is not None and isinstance(frame, ac.DepthData):
            depth_buf = frame.getDepthData()
            confidence_buf = frame.getConfidenceData()

            result_image = (depth_buf * (255.0 / r)).astype(np.uint8)
            result_image = cv2.applyColorMap(result_image, cv2.COLORMAP_RAINBOW)
            result_image = getPreviewRGB(result_image, confidence_buf)

            cv2.normalize(confidence_buf, confidence_buf, 1, 0, cv2.NORM_MINMAX)

            cv2.imshow("preview_confidence", confidence_buf)
            cv2.imshow("preview", result_image)
            cam.releaseFrame(frame)

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

    cam.stop()
    cam.close()

if __name__ == "__main__":
    main()

Test Results

python_test