Cameras for Raspberry Pi

  1. Home
  2. Docs
  3. Cameras for Raspberry Pi
  4. ToF Camera for Raspberry Pi
  5. Arducam ToF Camera SDK

Arducam ToF Camera SDK

Software Stack of Arducam ToF Camera

ArduCam TOF SDK is a dynamic link library written in C++, There are three classes, Camera, Frame, and Sensor. Camera is responsible for managing camera image acquisition calculation, Frame is responsible for memory management of camera data storage, and Sensor is the specific implementation of calling the camera. It is called as a member object in the Camera class, and users generally do not touch it. 

arducam tof framework

Demos with Arducam ToF camera.

Driver Installation

Please refer to this guide to install drivers and dependencies.

SDK Installation

cd Release/
mkdir build
cd build
cmake ..
sudo make install
sudo ldconfig
log
how to install arducam tof SDK

Examples with C

SDK workflow

  1. create a camera instance.
  2. start the camera.
  3. request a frame.
  4. get frame data
  5. release frame space
  6. stop the camera

Demo

ArducamDepthCamera tof = createArducamDepthCamera();
FrameBuffer frame;
if (initialize(tof,DEPTH_TYPE))
    exit(-1);
if (start(tof))
    exit(-1);

FrameFormat format;
if ((frame = requestFrame(tof,200)) != 0x00){
    getFormat(frame,DEPTH_FRAME,format);
}
releaseFrame(tof,frame);
uint8_t *preview_ptr = malloc(format.width*format.height*sizeof(uint8_t)) ;
float* depth_ptr = 0;
int16_t *raw_ptr = 0;
float *amplitude_ptr = 0;
for (;;)
{
    if ((frame = requestFrame(tof,200)) != 0x00)
    {
        depth_ptr = (float*)getDepthData(frame);
        amplitude_ptr = (float*)getAmplitudeData(frame);
        getPreview(preview_ptr,depth_ptr,amplitude_ptr);
        releaseFrame(tof,frame);
    }
}

if (stop(tof))
    exit(-1);
return 0;

Results

c test results

Examples with C++

SDK workflow

  1. create a camera instance.
  2. initialize camera instance.
  3. start the camera.
  4. request a frame.
  5. get frame data
  6. release frame space
  7. stop the camera

Demo

ArduCam::ArduCamTOFCamera tof;
ArduCam::ArduCamTOFFrame *frame;
if (tof.initialize(ArduCam::RAW_TYPE))
    exit(-1);

if (tof.start())
    exit(-1);

ArduCam::FrameFormat tofFormat = tof.getFrameFormats();

int16_t *raw_ptr;


for (;;)
{
    frame = tof.requestFrame(200);
    if (frame != nullptr)
    {
        raw_ptr = (int16_t *)frame->getFrameData(ArduCam::RAW_FRAME);
        cv::Mat raw_frame(720, 240, CV_16S, raw_ptr);
        raw_frame.convertTo(raw_frame,CV_32F);
        cv::imshow("preview", raw_frame);

        if (cv::waitKey(1) == 27)
            break;
        display_fps();
    }
    tof.releaseFrame(frame);
}

if (tof.stop())
    exit(-1);
return 0;

Results

cpp test

Example with Python

SDK workflow

  1. create a camera instance.
  2. initialize camera instance.
  3. start the camera.
  4. request a frame.
  5. get frame data
  6. release frame space
  7. stop the camera

Demo

cam = ac.ArducamCamera()
cam.initialize(ac.TOFOutput.RAW)
cam.start()
while True:
    frame = cam.requestFrame(200)
    buf = frame.getRawData()
    cam.releaseFrame(frame)
    cv2.imshow("window", buf.astype(np.float32))
    key = cv2.waitKey(1)
    if key == ord("q"):
        cam.stop()
        sys.exit(0)

Results

python test

API References for C

You can find C references here.

API References for C++

You can find C++ references here.

Was this article helpful to you? Yes No