Get depth image

Depth images belongs to the upper layer of synthetic data. You need to start the EnableStreamData() beforehand, to get it through GetStreamData(). The depth image type is CV_16UC1. In addition, it should be check not be empty before use.

For detailed process description, please see Get original binocular image Get stereo camera correction image.

In addition, it is recommended to use plugins to calculate depth: Depth images work better and operate faster. Please refer to Using the plugin to get data.

Reference code snippet:

auto &&api = API::Create(argc, argv);




while (true) {

  auto &&left_data = api->GetStreamData(Stream::LEFT);
  auto &&right_data = api->GetStreamData(Stream::RIGHT);

  cv::Mat img;
  cv::hconcat(left_data.frame, right_data.frame, img);
  cv::imshow("frame", img);

  auto &&depth_data = api->GetStreamData(Stream::DEPTH);
  if (!depth_data.frame.empty()) {
    cv::imshow("depth", depth_data.frame);  // CV_16UC1

  char key = static_cast<char>(cv::waitKey(1));
  if (key == 27 || key == 'q' || key == 'Q') {  // ESC/Q


The above code uses OpenCV to display the image. When the display window is selected, pressing ESC/Q will end the program.

Complete code examples, see .

Preview the value of a region of the depth image, see .