Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
examples
callback
rs-callback.cpp
Go to the documentation of this file.
1
// License: Apache 2.0. See LICENSE file in root directory.
2
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3
4
#include <
librealsense2/rs.hpp
>
// Include RealSense Cross Platform API
5
#include <iostream>
6
#include <map>
7
#include <chrono>
8
#include <mutex>
9
#include <thread>
10
11
// The callback example demonstrates asynchronous usage of the pipeline
12
int
main
(
int
argc,
char
* argv[])
try
13
{
14
//rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
15
16
std::map<int, int>
counters
;
17
std::map<int, std::string> stream_names;
18
std::mutex mutex;
19
20
// Define frame callback
21
// The callback is executed on a sensor thread and can be called simultaneously from multiple sensors
22
// Therefore any modification to common memory should be done under lock
23
auto
callback
= [&](
const
rs2::frame
& frame)
24
{
25
std::lock_guard<std::mutex>
lock
(mutex);
26
if
(
rs2::frameset
fs = frame.
as
<
rs2::frameset
>())
27
{
28
// With callbacks, all synchronized stream will arrive in a single frameset
29
for
(
const
rs2::frame
&
f
: fs)
30
counters[
f
.get_profile().unique_id()]++;
31
}
32
else
33
{
34
// Stream that bypass synchronization (such as IMU) will produce single frames
35
counters[frame.get_profile().unique_id()]++;
36
}
37
};
38
39
// Declare RealSense pipeline, encapsulating the actual device and sensors.
40
rs2::pipeline
pipe
;
41
42
// Start streaming through the callback with default recommended configuration
43
// The default video configuration contains Depth and Color streams
44
// If a device is capable to stream IMU data, both Gyro and Accelerometer are enabled by default
45
//
46
rs2::pipeline_profile
profiles
= pipe.
start
(
callback
);
47
48
// Collect the enabled streams names
49
for
(
auto
p
: profiles.
get_streams
())
50
stream_names[
p
.unique_id()] =
p
.stream_name();
51
52
std::cout
<<
"RealSense callback sample"
<< std::endl << std::endl;
53
54
while
(
true
)
55
{
56
std::this_thread::sleep_for(std::chrono::seconds(1));
57
58
std::lock_guard<std::mutex>
lock
(mutex);
59
60
std::cout
<<
"\r"
;
61
for
(
auto
p
: counters)
62
{
63
std::cout
<< stream_names[
p
.first] <<
"["
<<
p
.first <<
"]: "
<<
p
.second <<
" [frames] || "
;
64
}
65
}
66
67
return
EXIT_SUCCESS;
68
}
69
catch
(
const
rs2::error
&
e
)
70
{
71
std::cerr
<<
"RealSense error calling "
<< e.
get_failed_function
() <<
"("
<< e.
get_failed_args
() <<
"):\n "
<< e.what() << std::endl;
72
return
EXIT_FAILURE;
73
}
74
catch
(
const
std::exception& e)
75
{
76
std::cerr
<< e.what() << std::endl;
77
return
EXIT_FAILURE;
78
}
rs2::error
Definition:
rs_types.hpp:92
rs2::textual_icons::lock
static const textual_icon lock
Definition:
model-views.h:218
export_ply_example.pipe
pipe
Definition:
export_ply_example.py:18
rs2::frame
Definition:
rs_frame.hpp:343
rs2::pipeline_profile
Definition:
rs_pipeline.hpp:18
p
GLfloat GLfloat p
Definition:
glext.h:12687
counters
GLint GLint GLsizei GLuint * counters
Definition:
glext.h:5682
rs2::frameset
Definition:
rs_frame.hpp:943
rs.hpp
rmse.e
e
Definition:
rmse.py:177
rs2::error::get_failed_args
const std::string & get_failed_args() const
Definition:
rs_types.hpp:117
f
GLdouble f
Definition:
glad/glad/glad.h:1518
Catch::cout
std::ostream & cout()
t265_stereo.profiles
profiles
Definition:
t265_stereo.py:139
t265_stereo.callback
def callback(frame)
Definition:
t265_stereo.py:91
rs2::pipeline
Definition:
rs_pipeline.hpp:362
rs2::pipeline_profile::get_streams
std::vector< stream_profile > get_streams() const
Definition:
rs_pipeline.hpp:29
Catch::cerr
std::ostream & cerr()
main
int main(int argc, char *argv[])
Definition:
rs-callback.cpp:12
rs2::pipeline::start
pipeline_profile start()
Definition:
rs_pipeline.hpp:392
rs2::error::get_failed_function
const std::string & get_failed_function() const
Definition:
rs_types.hpp:112
rs2::frame::as
T as() const
Definition:
rs_frame.hpp:580
librealsense2
Author(s): Sergey Dorodnicov
, Doron Hirshberg
, Mark Horn
, Reagan Lopez
, Itay Carpis
autogenerated on Mon May 3 2021 02:47:40