Skip to content

GDK Camera Interface Documentation (C++)

Overview

The Camera module provides the G02 robot with the ability to acquire real-time image data. Through the C++ interface, developers can conveniently obtain the robot's visual perception data, suitable for various scenarios such as object detection, image recognition, visual navigation, SLAM mapping, and environment monitoring.

Interface Description

Camera Class

This class encapsulates the main data acquisition interfaces of the camera sensor.

1. GetLatestImage()

  • Function: Get the latest image data
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
timeout_ms const float Timeout duration (milliseconds)
image std::shared_ptr<Image>& Output parameter, pointer to the image data
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the image parameter containing the image data

Image Object Details

The Image struct contains the following members:

Member Name Type Description Unit
timestamp_ns uint64_t Timestamp of image capture Nanoseconds
width uint32_t Image width (pixels) Pixels
height uint32_t Image height (pixels) Pixels
encoding Encoding Image encoding format enum Enum value
color_format ColorFormat Image color format enum Enum value
bit_depth uint8_t Number of bits per pixel Bits
data_view DataView Raw pixel data view of the image Data view

struct Image {
  uint32_t width{0};   ///< image width
  uint32_t height{0};  ///< image height

  enum class Encoding : uint8_t {
    UNCOMPRESSED,  ///< uncompressed
    JPEG,          ///< JPEG
    PNG            ///< PNG
  } encoding{Encoding::UNCOMPRESSED};

  enum class ColorFormat : uint8_t {
    RGB,
    BGR,
    RGBA,
    BGRA,

    YUV420,
    YUV422,
    YUV444,
    NV12,
    NV21,

    GRAY8,
    GRAY16,

    BAYER_RGGB,
    BAYER_BGGR,
    BAYER_GBRG,
    BAYER_GRBG,

    RS2_FORMAT_Z16
  } color_format{ColorFormat::RGB};

  uint8_t bit_depth{8};  ///< bit depth

  DataView data_view{};      ///< image data view
  uint64_t timestamp_ns{0};  ///< image timestamp(ns)
};
encoding (encoding format):

  • Type: Encoding enum
  • Common values:
  • Encoding::UNCOMPRESSED: Uncompressed
  • Encoding::JPEG: JPEG compression
  • Encoding::PNG: PNG compression

 enum class Encoding : uint8_t {
   UNCOMPRESSED,  ///< uncompressed
   JPEG,          ///< JPEG
   PNG            ///< PNG
 } encoding{Encoding::UNCOMPRESSED};
color_format (color format):

  • Type: ColorFormat enum
  • Common values:
  • ColorFormat::RGB: Red-Green-Blue
  • ColorFormat::BGR: Blue-Green-Red
  • ColorFormat::RGBA: Red-Green-Blue-Alpha
  • ColorFormat::BGRA: Blue-Green-Red-Alpha
  • ColorFormat::GRAY8: 8-bit grayscale
  • ColorFormat::GRAY16: 16-bit grayscale
  • ColorFormat::YUV420: YUV420 format
  • ColorFormat::YUV422: YUV422 format
  • ColorFormat::YUV444: YUV444 format
  • ColorFormat::NV12: NV12 format
  • ColorFormat::NV21: NV21 format
  • ColorFormat::BAYER_RGGB: RGGB Bayer pattern
  • ColorFormat::BAYER_BGGR: BGGR Bayer pattern
  • ColorFormat::BAYER_GBRG: GBRG Bayer pattern
  • ColorFormat::BAYER_GRBG: GRBG Bayer pattern
  • ColorFormat::RS2_FORMAT_Z16: RealSense Z16 depth format
 enum class ColorFormat : uint8_t {
   RGB,
   BGR,
   RGBA,
   BGRA,

   YUV420,
   YUV422,
   YUV444,
   NV12,
   NV21,

   GRAY8,
   GRAY16,

   BAYER_RGGB,
   BAYER_BGGR,
   BAYER_GBRG,
   BAYER_GRBG,

   RS2_FORMAT_Z16
 } color_format{ColorFormat::RGB};

bit_depth (bit depth):

  • Type: uint8_t
  • Common values:
  • 8: 8-bit (0-255)
  • 16: 16-bit (0-65535)
  • 32: 32-bit (floating point)

data_view (image data):

  • Type: DataView
  • Description: Raw pixel data view of the image
  • Purpose: Image processing, display, saving
  • Note: Needs to be parsed according to the encoding and dimensions

Camera Types: - CameraType::kHeadBackFisheye: Head rear fisheye camera - CameraType::kHeadLeftFisheye: Head left fisheye camera - CameraType::kHeadRightFisheye: Head right fisheye camera - CameraType::kHeadStereoLeft: Head stereo left camera - CameraType::kHeadStereoRight: Head stereo right camera - CameraType::kHandLeftColor: Left hand color camera - CameraType::kHandRightColor: Right hand color camera - CameraType::kHeadColor: Head color camera - CameraType::kHeadDepth: Head depth camera (outputs depth image) - CameraType::kHandLeftDepth: Left hand depth camera (outputs depth image) - CameraType::kHandRightDepth: Right hand depth camera (outputs depth image)

  • CameraType::kHandLeftUpperColor: Left hand upper color camera (reserved)
  • CameraType::kHandRightUpperColor: Right hand upper color camera (reserved)
  • CameraType::kHandLeftLowerColor: Left hand lower color camera (reserved)
  • CameraType::kHandRightLowerColor: Right hand lower color camera (reserved)
  • CameraType::kHandLeftUpperDepth: Left hand upper depth camera (outputs depth image) (reserved)
  • CameraType::kHandRightUpperDepth: Right hand upper depth camera (outputs depth image) (reserved)
  • CameraType::kHandLeftLowerDepth: Left hand lower depth camera (outputs depth image) (reserved)
  • CameraType::kHandRightLowerDepth: Right hand lower depth camera (outputs depth image) (reserved)

  • In normal mode, the head stereo left camera, head stereo right camera, left and right color cameras, right hand color camera, head color camera, and head depth camera are enabled by default; the remaining cameras are disabled by default, and it is not recommended to enable the remaining cameras in normal mode

  • The remaining cameras can be enabled or disabled in develop mode

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::shared_ptr<agibot::gdk::Image> image = std::make_shared<agibot::gdk::Image>();

    agibot::gdk::CameraType camera_type = agibot::gdk::CameraType::kHandLeftColor;

    if (gdk_camera.GetLatestImage(camera_type, 500, image) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to get latest image" << std::endl;
    } else {
        std::cout << "Image shape: " << image->width << "x" << image->height << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

2. GetNearestImage()

  • Function: Get the nearest image data closest to the specified timestamp
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
timestamp_ns const uint64_t Target timestamp (nanoseconds)
timeout_ms const float Timeout duration (milliseconds)
image std::shared_ptr<Image>& Output parameter, pointer to the image data
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the image parameter containing the image data, structured the same as GetLatestImage()

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::shared_ptr<agibot::gdk::Image> image = std::make_shared<agibot::gdk::Image>();

    agibot::gdk::CameraType camera_type = agibot::gdk::CameraType::kHandLeftColor;

    if(gdk_camera.GetNearestImage(camera_type, 0, 2000.0, image) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GetNearestImage failed" << std::endl;
        return -1;
    } else {
        std::cout << "Image shape: " << image->width << " x " << image->height << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

3. GetImageShape()

  • Function: Get the image data size
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
shape std::tuple<int, int>& Output parameter, tuple of image width and height
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the shape parameter containing the image dimensions

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::shared_ptr<agibot::gdk::Image> image = std::make_shared<agibot::gdk::Image>();

    agibot::gdk::CameraType camera_type = agibot::gdk::CameraType::kHandRightColor;

    std::tuple<int, int> shape;
    if (gdk_camera.GetImageShape(camera_type, shape) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to get image shape" << std::endl;
    } else {
        std::cout << "Image shape: " << std::get<0>(shape) << "x" << std::get<1>(shape) << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

4. GetImageFps()

  • Function: Get the image capture frame rate
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
fps float& Output parameter, image frame rate (FPS)
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the fps parameter containing the frame rate value

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::shared_ptr<agibot::gdk::Image> image = std::make_shared<agibot::gdk::Image>();

    agibot::gdk::CameraType camera_type = agibot::gdk::CameraType::kHandLeftColor;

    float fps;
    if (gdk_camera.GetImageFps(camera_type, fps) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to get image fps" << std::endl;
    } else {
        std::cout << "Image fps: " << fps << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

5. GetImageLatency()

  • Note: Before getting image latency statistics, time synchronization must be performed first, otherwise the latency statistics will be inaccurate
  • Function: Get image latency statistics
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
window_seconds const float Statistics window duration (seconds)
latency LatencyStats& Output parameter, latency statistics
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the latency parameter containing the latency statistics

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::shared_ptr<agibot::gdk::Image> image = std::make_shared<agibot::gdk::Image>();

    agibot::gdk::CameraType camera_type = agibot::gdk::CameraType::kHandLeftColor;

    agibot::gdk::LatencyStats latency;
    if (gdk_camera.GetImageLatency(agibot::gdk::CameraType::kHeadStereoLeft, 1.0, latency) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to get image latency" << std::endl;
    } else {
        std::cout << "Image latency: " << latency.max_latency_ms << "ms" << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

6. GetCameraIntrinsic()

  • Function: Get camera intrinsic parameter information
  • Parameters:
Parameter Name Type Description
camera_type const CameraType& Camera type enum value
intrinsic CameraIntrinsic& Output parameter, camera intrinsic parameter information
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success, with the intrinsic parameter containing the camera intrinsics

  • Note: Not all camera types support intrinsic parameter retrieval. Camera types that support intrinsics include: kHeadBackFisheye, kHeadLeftFisheye, kHeadRightFisheye, kHeadStereoLeft, kHeadStereoRight, kHandLeftColor, kHandRightColor, kHeadColor, kHeadDepth, kHandLeftDepth, kHandRightDepth. For unsupported camera types, calling this interface will return an error.

  • CameraIntrinsic struct description:

struct CameraIntrinsic {
  std::vector<double> intrinsic{};  ///< camera intrinsic, fx, fy, cx, cy
  std::vector<double> distortion{}; ///< camera distortion, k1, k2, p1, p2, k3, k4, k5, k6
};
Member Name Type Description Index Unit
intrinsic[0] double Focal length in x direction (fx) 0 Pixels
intrinsic[1] double Focal length in y direction (fy) 1 Pixels
intrinsic[2] double Principal point x coordinate (cx) 2 Pixels
intrinsic[3] double Principal point y coordinate (cy) 3 Pixels
distortion[0] double Radial distortion coefficient 1 (k1) 0 Dimensionless
distortion[1] double Radial distortion coefficient 2 (k2) 1 Dimensionless
distortion[2] double Tangential distortion coefficient 1 (p1) 2 Dimensionless
distortion[3] double Tangential distortion coefficient 2 (p2) 3 Dimensionless
distortion[4] double Radial distortion coefficient 3 (k3) 4 Dimensionless
distortion[5] double Radial distortion coefficient 4 (k4) 5 Dimensionless
distortion[6] double Radial distortion coefficient 5 (k5) 6 Dimensionless
distortion[7] double Radial distortion coefficient 6 (k6) 7 Dimensionless
  • Intrinsic parameter support by camera type:
Camera Type intrinsic vector size distortion vector size Description
Stereo camera 4 (fx, fy, cx, cy) 8 (k1, k2, p1, p2, k3, k4, k5, k6) Full 12-parameter distortion model
RGBD camera 4 (fx, fy, cx, cy) 5 (k1, k2, p1, p2, k3) 9-parameter distortion model
Fisheye camera 4 (fx, fy, cx, cy) 6 (k1, k2, p1, p2, k3, k4) 10-parameter distortion model
  • Distortion model description:
  • Radial distortion: k1, k2, k3, k4, k5, k6 - used to correct lens radial distortion
  • Tangential distortion: p1, p2 - used to correct lens tangential distortion
  • Different camera types: use different numbers of distortion parameters depending on lens characteristics

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

void printCameraIntrinsic(const agibot::gdk::CameraType& camera_type,
                         const agibot::gdk::CameraIntrinsic& intrinsic) {
    std::cout << "Camera intrinsic for " << static_cast<int>(camera_type) << ":" << std::endl;

    // Display the intrinsic matrix (fx, fy, cx, cy)
    if (intrinsic.intrinsic.size() >= 4) {
        std::cout << "  fx: " << intrinsic.intrinsic[0] << ", fy: " << intrinsic.intrinsic[1] << std::endl;
        std::cout << "  cx: " << intrinsic.intrinsic[2] << ", cy: " << intrinsic.intrinsic[3] << std::endl;
    }

    // Display distortion parameters
    if (intrinsic.distortion.size() > 0) {
        std::cout << "  k1: " << intrinsic.distortion[0];
        if (intrinsic.distortion.size() > 1) std::cout << ", k2: " << intrinsic.distortion[1];
        if (intrinsic.distortion.size() > 2) std::cout << ", p1: " << intrinsic.distortion[2];
        if (intrinsic.distortion.size() > 3) std::cout << ", p2: " << intrinsic.distortion[3];
        if (intrinsic.distortion.size() > 4) std::cout << ", k3: " << intrinsic.distortion[4];
        std::cout << std::endl;

        // Display additional distortion parameters based on camera type
        if (camera_type == agibot::gdk::CameraType::kHeadStereoLeft ||
            camera_type == agibot::gdk::CameraType::kHeadStereoRight) {
            // Stereo camera: display k4, k5, k6
            if (intrinsic.distortion.size() > 5) std::cout << "  k4: " << intrinsic.distortion[5];
            if (intrinsic.distortion.size() > 6) std::cout << ", k5: " << intrinsic.distortion[6];
            if (intrinsic.distortion.size() > 7) std::cout << ", k6: " << intrinsic.distortion[7];
            std::cout << " (stereo camera, 12-parameter distortion model)" << std::endl;
        } else if (camera_type == agibot::gdk::CameraType::kHeadDepth) {
            // RGBD camera: only display k1, k2, k3
            std::cout << "  (RGBD camera, 9-parameter distortion model)" << std::endl;
        } else if (camera_type == agibot::gdk::CameraType::kHeadBackFisheye ||
                   camera_type == agibot::gdk::CameraType::kHandLeftColor ||
                   camera_type == agibot::gdk::CameraType::kHandRightColor) {
            // Fisheye camera: display k4
            if (intrinsic.distortion.size() > 5) {
                std::cout << "  k4: " << intrinsic.distortion[5] << " (fisheye camera, 10-parameter distortion model)" << std::endl;
            }
        }
    }
}

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    // Get intrinsics for different camera types
    std::vector<agibot::gdk::CameraType> camera_types = {
        agibot::gdk::CameraType::kHeadStereoLeft,    // Stereo camera
        agibot::gdk::CameraType::kHeadDepth,         // RGBD camera
        agibot::gdk::CameraType::kHeadBackFisheye  // Fisheye camera
    };

    for (auto camera_type : camera_types) {
        agibot::gdk::CameraIntrinsic intrinsic;
        if (gdk_camera.GetCameraIntrinsic(camera_type, intrinsic) != agibot::gdk::GDKRes::kSuccess) {
            std::cout << "Failed to get camera intrinsic for type " << static_cast<int>(camera_type) << std::endl;
        } else {
            printCameraIntrinsic(camera_type, intrinsic);
        }
        std::cout << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

7. SetDevCameraConfig()

  • Function: Camera customization function (turn cameras on/off, set frame rate)
  • Parameters:
Parameter Name Type Description
cam_conf_path const std::string& Path to the camera configuration file
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success

  • Note:

  • The configuration file path must exist, otherwise GDKRes::kInvalidInput is returned
  • After each modification of the customized camera configuration file and calling the interface, you need to switch back to develop mode again
Configuration Options

GDK supports configuring the on/off state and frame rate of cameras. The customized camera configuration file is under the deployment package, and its absolute path is typically ~/.cache/agibot/app/gdk/config/r1_camera_conf.json or ~/.cache/agibot/app/gdk/config/thor_camera_conf.json (where ~ represents the user's home directory, e.g. /home/your_name) The configuration file for the r1 robot is r1_camera_conf.json, and for the thor robot it is thor_camera_conf.json; pay attention to the file name when using it Set publish to true to enable the camera, false to disable it, and set fps to control the camera frame rate

The specific camera configuration format is as follows

{
    "cam0": {
        "fps": "30",
        "name": "head_stereo_right",
        "publish": true
    },
    "cam3": {
        "fps": "30",
        "name": "head_stereo_left",
        "publish": true
    },
    "cam4": {
        "fps": "30",
        "name": "hand_left_depth",
        "publish": false
    },
    "cam5": {
        "fps": "30",
        "name": "hand_left_color",
        "publish": true
    },
    "cam6": {
        "fps": "30",
        "name": "hand_right_depth",
        "publish": false
    },
    "cam7": {
        "fps": "30",
        "name": "hand_right_color",
        "publish": true
    },
    "cam10": {
        "fps": "30",
        "name": "head_right_fisheye",
        "publish": false
    },
    "cam11": {
        "fps": "30",
        "name": "head_left_fisheye",
        "publish": false
    },
    "cam12": {
        "fps": "30",
        "name": "head_back_fisheye",
        "publish": false
    },
    "cam14": {
        "fps": "30",
        "name": "head_depth",
        "publish": true
    },
    "cam15": {
        "fps": "30",
        "name": "head_color",
        "publish": true
    }
}

Mode Switching

./mode_switch --mode develop # Switch to develop mode
To switch back to the previous base mode, run
./mode_switch --mode base # Switch to base mode

  • Example:
#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));

    // Set the camera configuration
    std::string config_path = "/home/<your_name>/.cache/agibot/app/gdk/config/r1_camera_conf.json";
    if (gdk_camera.SetDevCameraConfig(config_path) != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to set camera config" << std::endl;
    } else {
        std::cout << "Camera config set successfully" << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

8. CloseCamera()

  • Function: Close the camera DDS connection
  • Parameters: None
  • Return Value: GDKRes, the operation result status code. Returns GDKRes::kSuccess on success

  • Example:

#include <iostream>
#include <thread>
#include "gdk/gdk.h"

int main() {
    // Initialize the GDK system
    if (agibot::gdk::GDKInit() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK initialization failed" << std::endl;
        return -1;
    }
    std::cout << "GDK initialized successfully" << std::endl;

    agibot::gdk::Camera gdk_camera;
    std::cout << "Camera init" << std::endl;

    // Use the camera...

    // Close the camera
    if (gdk_camera.CloseCamera() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "Failed to close camera" << std::endl;
    } else {
        std::cout << "Camera closed successfully" << std::endl;
    }

    // Release GDK system resources
    if (agibot::gdk::GDKRelease() != agibot::gdk::GDKRes::kSuccess) {
        std::cout << "GDK release failed" << std::endl;
        return -1;
    }
    std::cout << "GDK released successfully" << std::endl;

    return 0;
}

Usage Notes

  1. GDK initialization: You must call agibot::gdk::GDKInit() to initialize the GDK system before using the Camera functionality
  2. GDK release: You must call agibot::gdk::GDKRelease() before the program ends to release GDK system resources
  3. Initialization wait: After creating the Camera object, it is recommended to wait 1 second to ensure the camera has finished initializing
  4. Timeout setting: Set an appropriate timeout duration according to actual needs to avoid long blocking
  5. Data validity: Check whether the returned image data is nullptr before use
  6. Timestamp precision: The timestamp unit is nanoseconds, which can be used for precise time synchronization
  7. Image processing: Image data volume is large, so pay attention to memory usage when processing
  8. Camera selection: Choose the appropriate camera type (fisheye/stereo/depth, etc.) according to the application scenario
  9. Frame rate control: Be mindful of the camera's frame rate limits to avoid excessive requests
  10. Camera configuration: When using SetDevCameraConfig() to set the camera configuration, make sure the configuration file path is valid
  11. Error handling: Always check the GDKRes return value to ensure the operation succeeded
  12. Camera switches: In normal mode/develop mode, enabling more cameras carries a performance risk

Application Scenarios

  • Object detection: Use image data for object recognition and detection
  • Visual navigation: Provide visual information for robot navigation
  • SLAM mapping: Combine image data for simultaneous localization and mapping
  • Environment monitoring: Monitor changes in the surrounding environment in real time
  • Depth perception: Use the depth camera to obtain 3D environmental information
  • Stereo vision: Use the stereo camera for distance measurement
  • Image recognition: Perform object classification and recognition
  • Data fusion: Fuse with other sensor data to improve perception accuracy
  • Camera calibration: Use camera intrinsics for image correction and distortion compensation
  • 3D reconstruction: Combine camera intrinsics for 3D point cloud reconstruction
  • Visual measurement: Use camera intrinsics for precise dimensional measurement