Xvisio SDK Depth
Xvisio Features and Quick Start
Xvisio SDK Documentation Home Page


1. Overview

Xvisio SeerSense™ DS80 series products support SGBM(passive binocular vision) depth algorithm. Refer to the corresponding datasheet of other products to confirm whether it supports SGBM depth algorithm.

2. Features

2.1 Work Mode

Support two resolutions:

  • VGA:640*480
  • 720P:1280*720

The depth image quality of 720P resolution will be higher than VGA resolution. Please refer to the product datasheet or ask Xvisio FAE personnel for the differences of the image quality.
Resolution definition:

enum class Resolution {
        SGBM_640x480   = 0,  ///< SGBM 480p
        SGBM_1280x720  = 1,  ///< SGBM 720p
    };

Set API example:

device->sgbmCamera()->setSgbmResolution(xv::SgbmCamera::Resolution::SGBM_640x480);
2.2 Configuration

Xvisio SDK provides some parameter configuration interfaces and configuration structure definitions:

/**
 * @brief SGBM CONFIG STRUCT
*/
struct sgbm_config
    {
        int32_t enable_dewarp;
        float dewarp_zoom_factor;
        int32_t enable_disparity;
        int32_t enable_depth;
        int32_t enable_point_cloud;
        float baseline;
        float fov;
        uint8_t disparity_confidence_threshold;
        float homography[9];
        int32_t enable_gamma;
        float gamma_value;
        int32_t enable_gaussian;
        uint8_t mode;//standard 0 /Default:LRcheck 1 /Extended 2 /Subpixel 3
        uint16_t max_distance;//mm
        uint16_t min_distance;//mm
    };

Note:

  1. “enable_dewarp” : enable/disable distortion correction function. Default to enable. All products officially released by Xvisio need to be enabled. Value:0 disbale 1 enable.
  2. “dewarp_zoom_factor”: Distortion correction factor. Default to 1.0. Xvisio SeerSense™ DS80 series products are set to 1.0. Refer to the other datasheet for other products or ask Xvisio FAE for help.
  3. “enable_disparity”: enable/disable disparity image output. Default to disable. Disable is recommended for working status. Value:0 disbale 1 enable.
  4. “enable_depth”: enable/disable depth image output. Default to enable.Enable is recommended for working status. Value:0 disbale 1 enable.
  5. “enable_point_cloud”: enable/disable point cloud data output. Default to disable. Select enable or disable according to the application. If point cloud computing is enabled on the xvisio device side, or you can choose to disable and call the SDK API for deep point cloud conversion. Value:0 disbale 1 enable.
  6. “baseline”: The distance between the fisheye. Default to 0.08. Xvisio SeerSense™ DS80 series products should be set to 0.08. Refer to the other datasheet for other products or ask Xvisio FAE for help.
  7. “fov: The effective FOV of binocular camera image applied to SGBM algorithm which is not the real FOV of camera. Default to 96. Xvisio SeerSense™ DS80 series products should be set to 96. Refer to the other datasheet for other products or ask Xvisio FAE for help.
  8. “disparity_confidence_threshold”: Parallax confidence threshold. Default to 255. 255 is recommended for working status.
  9. “homography”: Homography transformation matrix. Default value is {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}. It is recommended to use default value for working status.
  10. “enable_gamma”: enable/disable gamma. It is default to enable. Enable is recommended for working status. Value:0 disable,1 enable.
  11. “gamma_value”: gamma value. It is default to 2.2. 2.2 is recommended for working status.
  12. “enable_gaussian”: enable/disable gaussian filter. It is default to disable. Disable is recommended for working mode. Value:0 disable, 1 enable.
  13. “mode”: algorithm mode,default to 0 and 0 is recommended for working mode.Value: 0:lrcheck 1:standard 2:extended 3:subpixel.
  14. “max_distance”: max-distance threshold with an unit of mm.The default value is 8000, and 8000 is recommended for working status.
  15. “min_distance”: min-distance threshold with an unit of mm.The default value is 100, and 100 is recommended for working status.

Set API examples:

xv::sgbm_config global_config = {...};
device->sgbmCamera()->start(global_config);

Or pass an empty string directly to use the default configuration:

device->sgbmCamera()->start("");
2.4 Frame Rate and Data Bandwidth

The frame rate and resolution of SGBM depth can't be set.

Data Type Resolution Frame rate(fps) USB bandwidth(max)
Depth Data VGA 60 281.25Mbps
Depth Data 720P 30 421.875Mbps
Point Cloud Data VGA 60 843.75Mbps
Point Cloud Data 720P 30 1265.25Mbps

Note: point cloud data can not only enable the output of the device's point cloud data through USB, but also call the SDK API for deep point cloud conversion.

2.5 Exposure Time

The image source of SGBM is binocular fisheye camera, actually it is a shared image source with SLAM. So the exposure strategy will also affect each other. Currently, it is default to enable the automatic exposure strategy in the device, and the default maximum exposure time is 3ms.
When SGBM and SLAM work simultaneously or only SGBM works, the maximum exposure time will be switched to 8ms. When only SLAM works, the maximum exposure time will be maintained at 3ms.
In addition, Xvisio SDK provides setting interface for the maximum exposure time. API example:

/*
 * @brief Exposure setting.
 * @param[in] aecMode 0:auto exposure 1:manual exposure
 * @param[in] exposureGain Only valid in manual exposure mode, [0,255]
 * @param[in] exposureTimeMs Only valid in manual exposure mode, in milliseconds
bool setExposure( int aecMode = 0,  int exposureGain = 0,  float exposureTime = 0.0 )
*/
//Examples:
device->fisheyeCameras()->setExposure(0);   //auto exposure
//Or:
device->fisheyeCameras()->setExposure(1,20,5);    //manual exposure

3 Depth Data and Point Cloud Data

SGBM depth data and point cloud data can be obtained through the registration callback. The data format is 16 bit depth data (unit:mm).

3.1 DepthImage Definition
/**
 * @brief SGBM data.
 * @note Length, width and depth are in millimeters.
 */
struct SgbmImage {
    enum class Type { Disparity = 0, Depth, PointCloud};
    const Type type;
    explicit SgbmImage(Type t) : type(t) {}
    std::size_t width = 0; //!< width of the image (in pixel)
    std::size_t height = 0; //!< height of the image (in pixel)
    std::shared_ptr<const std::uint8_t> data = nullptr; //! data of SGBM
    unsigned int dataSize = 0;
    double hostTimestamp = std::numeric_limits<double>::infinity(); //!< host timestamp of the physical measurement (in second based on the `std::chrono::steady_clock`).
    std::int64_t edgeTimestampUs = (std::numeric_limits<std::int64_t>::min)(); //!< timestamp of the physical measurement (in microsecond based on edge clock).
    /**
     * @brief Convert to a #xv::RgbImage
     */
    RgbImage toRgb() const;
};

Note:

  1. The value of “type” is "Depth” or “PointCloud”.
  2. “width” and “height” is corresponds with SGBM resolution.
  3. The type of “data” is determined by "type":
    When "type" is "Depth","data" is the depth data(unit:mm). The bit width of each pixel is 16 bits. The corresponding conversion is carried out according to the application scenario once used.
    When "type" is "PointCloud","data" is point cloud data.Each pixel consists of three unsigned 16 bit types,which representing the depth data of x, y, z axis (unit:mm).
  4. “data size” indicates "width" * "height" * 2 (bitwidth of 16bits).
  5. “hostTimestamp” is synchronously converted to the timestamp of the same baseline on the host side by the timestamp of the SDK. The unit is seconds and the accuracy reach to microseconds.
  6. “edgeTimestampUs” is the Xvisio device sampling timestamp with a unit of microseconds.
  7. “toRgb()” is temporarily invalid, reserved.
3.2 Get SgbmImage

Get SgbmImage by register callback way. The interface call process is as follows:

  1. Set sgbm config,
  2. Register sgbmCamera callback,
  3. Call start() and convert to sgbm config to start SGBM streaming,
  4. Trigger callback, and do data processing in callback,
  5. Call stop() after deregistering callback to stop SGBM Streaming.
    Refer to demo-api.cpp(case 67,68)for detail code.demo-api

4 Point Cloud Data Conversion

Xvisio SDK provides API which can convert depth data to point cloud data format.

4.1 PointCloud Definition
/**
 * @brief A point cloud of 3D points.
 */
struct PointCloud {
    double hostTimestamp = std::numeric_limits<double>::infinity(); //!< host timestamp of ? (in second based on the `std::chrono::steady_clock`).
    std::int64_t edgeTimestampUs = (std::numeric_limits<std::int64_t>::min)(); //!< timestamp of ? (in microsecond based on edge clock).
    std::vector<Vector3f> points;
};

Notes:

  1. After the timestamp synchronization of SDK, “hostTimestamp” is converted to the timestamp of the same baseline on the host side. The unit is second and the accuracy can reach to microsecond.
  2. “edgeTimestampUs” indicates Xvisio device sampling timestamp (unit:s).
  3. “points” indicates point cloud data. Each pixel is composed of three float types,which representing the depth data of x, y, z axis (unit:mm).
4.2 Covert PointCloud

To get Pointcloud, firstly you should obtain the SgbmImage, and then call the interface for conversion. The process is as follows:

  1. Register callback of sgbmCamera,
  2. Call start() to start SGBM streaming,
  3. Trigger callback, and use API to do point cloud convert processing in callback:
    device->tofCamera()->depthImageToPointCloud(sgbm_image)
  4. Call stop() after deregistering callback to stop SGBM Streaming.
    Refer to demo-api.cpp(case 67,68)demo-api for detail code.

5 Code

  • Define Xvisio Device
    std::shared_ptr<xv::Device> device = nullptr;
  • Read device_list, set timeout value to 10 seconds(recommonds value which can be shorten.)
    auto device_list = xv::getDevices(10., "");
  • Judge whether the obtained device is empty. It fails if it is empty.
    if (device_list.empty())`
    {
            LOG(LOG_Function,"initDevice faiiled:Timeout for device detection.");
            return false;
    }
    
    
  • Get device(only for single equipment, please refer to the corresponding document description for multiple equipments.)
    device = device_list.begin()->second;
  • Set "resolution". It is default of VGA.
    device->sgbmCamera()->setSgbmResolution(xv::SgbmCamera::Resolution::SGBM_640x480);
    
  • Initial SGBM Config
    struct xv::sgbm_config global_config = {
        1 ,//enable_dewarp
        1.0, //dewarp_zoom_factor
        0, //enable_disparity
        1, //enable_depth
        0, //enable_point_cloud
        0.08, //baseline
        96, //fov
        255, //disparity_confidence_threshold
        {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, //homography
        1, //enable_gamma
        2.2, //gamma_value
        0, //enable_gaussian
        0, //mode
        8000, //max_distance
        100, //min_distance
    };
    
    
  • Register callback. Get depth data or point cloud data in the callback definition.
    int sgbmId = -1;
    sgbmId = device->sgbmCamera()->registerCallback([&](xv::SgbmImage const & sgbmDepthImage){
            if(sgbmDepthImage.type == xv::SgbmImage::Type::Depth)
            {
                //Operation on sgbmDepthImage
                //...
    
                //point cloud process
                auto points = device->sgbmCamera()->depthImageToPointCloud(sgbmDepthImage)->points;
            
                for (auto iter = points.begin(); iter != points.end();iter++)
                {
                     auto point = *iter;
                     printf(buff, "x=%f ,y=%f ,z=%f\n", point[0], point[1], point[2]);
                        //...
                }
            }
            else if(sgbmDepthImage.type == SgbmImage::Type::PointCloud )//The enable_point_cloud item in sgbm_config must be enabled to enable PointCloud reporting.
            {
                //Operation on sgbm PointCloud
                //...
            }
        });
    
    
  • Start SGBM
    //start tof,If you use the default config can call: device->sgbmCamera()->start("");
    device->sgbmCamera()->start(global_config);
    
  • Stop SGBM
    The sgbmId used here is the value assigned when registering callback.
    device->sgbmCamera()->unregisterCallback(sgbmId);
    device->sgbmCamera()->stop();
    

6 Note

  1. "sgbm_config" set "enable_point_cloud" to 1 to enable the device reporting point cloud data, so that to increase USB bandwidth. Refer to [2.4 Frame rate and data bandwidth](#24-frame rate and data bandwidth) for detail information。If API "depthImageToPointCloud" is used for point cloud conversion, the load of the host CPU will be increased. User needs to choose the appropriate method according to the usage scenario.

Xvisio SDK Depth
Xvisio Features and Quick Start
Xvisio SDK Documentation Home Page