C API Depth Perception Tutorial


In the default TangoConfig, config_enable_depth is set to false. In order to use depth perception, it must be set to true.

// Enable depth.
ret = (TangoConfig_setBool(config_, "config_enable_depth", true);
if (ret != TANGO_SUCCESS) {
  // Handle the error.

Specify the point cloud mode as XYZC.

ret = TangoConfig_setInt32(tango_config_, "config_depth_mode",
if (ret != TANGO_SUCCESS) {
  // Handle the error.

Define the callback

The caller is responsible for allocating memory, which will be released after the callback function has finished.

// Get the maximum vertex count for this device.
int temp = 0;
if (TangoConfig_getInt32(config_, "max_point_cloud_elements", &temp) !=
  LOGE("Get max_point_cloud_elements Failed");
  return false;
max_vertex_count = static_cast<uint32_t>(temp);

// Allocate the depth buffer (Each point has four values: X, Y, Z and C)
depth_data_buffer = new float[4 * max_vertex_count];

Define the onPointCloudAvailable() callback. Do not do any processing on the data within the callback; you will not receive new data until the callback returns.

static void onPointCloudAvailable(void* context, const TangoPointCloud* point_cloud) {
  memcpy(depth_data_buffer, point_cloud->points, point_cloud->num_points * 4 * sizeof(float));
  // Copy any other necessary data out of point_cloud.

Finally, attach the onPointCloudAvailable() callback.

if (TangoService_connectOnPointCloudAvailable(onPointCloudAvailable) != TANGO_SUCCESS) {
  // Handle the error.

Enviar comentarios sobre…