← Xvisio SDK 深度
← Xvisio 功能介绍和快速启动
← Xvisio SDK 文档主页
Xvisio SeerSense™ DS80 系列模组产品可以支持 SGBM 深度算法也是被动双目视觉深度算法,其他产品可以参考对应的数据手册来确认是否支持。
支持两种分辨率:
分辨率类型定义:
enum class Resolution {
SGBM_640x480 = 0, ///< SGBM 480p
SGBM_1280x720 = 1, ///< SGBM 720p
};
设置 API 示例:
device->sgbmCamera()->setSgbmResolution(xv::SgbmCamera::Resolution::SGBM_640x480);
Xvisio SDK 提供了一些参数配置接口,配置结构定义:
/**
* @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
};
说明:
设置 API 示例:
xv::sgbm_config global_config = {...};
device->sgbmCamera()->start(global_config);
或者可以直接传递空字符串使用默认配置:
device->sgbmCamera()->start("");
SGBM 深度不可以设置帧率,和分辨率对应固定帧率,查看表格:
数据类型 | 分辨率 | 帧率(fps) | USB 带宽(最大) |
---|---|---|---|
深度数据 | VGA | 60 | 281.25Mbps |
深度数据 | 720P | 30 | 421.875Mbps |
点云数据 | VGA | 60 | 843.75Mbps |
点云数据 | 720P | 30 | 1265.25Mbps |
注意:点云数据既可以使能设备的点云数据输出后通过 USB 输出,也可以调用SDK 的 API 做深度点云的转换。
SGBM 的图像源是双目鱼眼相机,实际上是和 SLAM 共用的图像源,所以曝光策略也会存在互相影响,当前设备内默认使能的是自动曝光策略,默认最大曝光时间为3ms。
SGBM 和 SLAM 同时工作或者只有 SGBM 时,最大曝光时间会切换为8ms ,当只有SLAM工作时会保持最大曝光时间为3ms。
另外Xvisio SDK 提供了最大曝光时间的设置接口,设置 API 示例:
/*
* @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
可以通过注册回调获取到 SGBM 深度数据和点云数据,数据格式都是16位深度数据,单位毫米。
/**
* @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;
};
说明:
使用注册回调方式获取 SgbmImage,接口调用流程如下所示:
Xvisio SDK 提供了 API 可以把深度数据转换为点云数据格式。
/**
* @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;
};
说明:
转换 PointCloud 必须要先获取 SgbmImage,然后再调用接口做转换,流程如下:
device->tofCamera()->depthImageToPointCloud(sgbm_image)
std::shared_ptr<xv::Device> device = nullptr;
auto device_list = xv::getDevices(10., "");
if (device_list.empty())`
{
LOG(LOG_Function,"initDevice faiiled:Timeout for device detection.");
return false;
}
device = device_list.begin()->second;
device->sgbmCamera()->setSgbmResolution(xv::SgbmCamera::Resolution::SGBM_640x480);
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
};
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 tof,If you use the default config can call: device->sgbmCamera()->start("");
device->sgbmCamera()->start(global_config);
device->sgbmCamera()->unregisterCallback(sgbmId);
device->sgbmCamera()->stop();