C++

A simple C++ example can be found below.

#include <chronoptics/tof.hpp>
#include <iostream>

namespace tof = chronoptics::tof;

int main() {
  try {
    tof::KeaCamera cam("2020004");
    cam.set_output_frame_types({tof::FrameType::Z});
    cam.start();

    for (size_t i = 0; i < 100; i++) {
      std::vector<tof::Data> frames = cam.get_frames();
      tof::Data z{std::move(frames[0])};
      float *z_ptr = reinterpret_cast<float*>(z.data());
    }

    cam.stop();
  } catch (std::exception &e) {
    std::cout << "An error occurred " << e.what() << "\n";
  }
}

Default error handling uses exceptions, but this is configurable. See the cpp/error_handling.cpp example for more information. Using the tof.Data with OpenCV is really easy.

cv::Mat mat(z.rows(), z.cols(), static_cast<int>(z.mat_type()),
            z.data());

The example cpp/data_to_pcl.cpp shows how to convert a tof.Data class to a point cloud. There’s also a way to avoid data copies when converting to a point cloud, this is shown in the ros/kea_camera_node.cpp example.