rs-hello-realsense.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
5 #include <iostream> // for cout
6 
7 // Hello RealSense example demonstrates the basics of connecting to a RealSense device
8 // and taking advantage of depth data
9 int main(int argc, char * argv[]) try
10 {
11  // Create a Pipeline - this serves as a top-level API for streaming and processing frames
13 
14  // Configure and start the pipeline
15  p.start();
16 
17  while (true)
18  {
19  // Block program until frames arrive
21 
22  // Try to get a frame of a depth image
24 
25  // Get the depth frame's dimensions
26  auto width = depth.get_width();
27  auto height = depth.get_height();
28 
29  // Query the distance from the camera to the object in the center of the image
30  float dist_to_center = depth.get_distance(width / 2, height / 2);
31 
32  // Print the distance
33  std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";
34  }
35 
36  return EXIT_SUCCESS;
37 }
38 catch (const rs2::error & e)
39 {
40  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
41  return EXIT_FAILURE;
42 }
43 catch (const std::exception& e)
44 {
45  std::cerr << e.what() << std::endl;
46  return EXIT_FAILURE;
47 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
GLfloat GLfloat p
Definition: glext.h:12687
GLint GLint GLsizei GLsizei GLsizei depth
e
Definition: rmse.py:177
depth_frame get_depth_frame() const
Definition: rs_frame.hpp:1006
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
std::ostream & cout()
GLint GLsizei GLsizei height
float get_distance(int x, int y) const
Definition: rs_frame.hpp:833
int main(int argc, char *argv[])
int get_height() const
Definition: rs_frame.hpp:671
std::ostream & cerr()
pipeline_profile start()
int get_width() const
Definition: rs_frame.hpp:659
const std::string & get_failed_function() const
Definition: rs_types.hpp:112
GLint GLsizei width


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40