Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
examples
pose-and-image
rs-pose-and-image.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
#include <
librealsense2/rs.hpp
>
4
#include <iostream>
5
#include <iomanip>
6
#include <chrono>
7
#include <thread>
8
#include <mutex>
9
10
int
main
(
int
argc,
char
* argv[])
try
11
{
12
// Declare RealSense pipeline, encapsulating the actual device and sensors
13
rs2::pipeline
pipe
;
14
// Create a configuration for configuring the pipeline with a non default profile
15
rs2::config
cfg
;
16
// Add pose stream
17
cfg.
enable_stream
(
RS2_STREAM_POSE
,
RS2_FORMAT_6DOF
);
18
// Enable both image streams
19
// Note: It is not currently possible to enable only one
20
cfg.
enable_stream
(
RS2_STREAM_FISHEYE
, 1,
RS2_FORMAT_Y8
);
21
cfg.
enable_stream
(
RS2_STREAM_FISHEYE
, 2,
RS2_FORMAT_Y8
);
22
23
// Define frame callback
24
25
// The callback is executed on a sensor thread and can be called simultaneously from multiple sensors
26
// Therefore any modification to common memory should be done under lock
27
std::mutex data_mutex;
28
uint64_t
pose_counter = 0;
29
uint64_t
frame_counter
= 0;
30
bool
first_data =
true
;
31
auto
last_print =
std::chrono::system_clock::now
();
32
auto
callback
= [&](
const
rs2::frame
& frame)
33
{
34
std::lock_guard<std::mutex>
lock
(data_mutex);
35
// Only start measuring time elapsed once we have received the
36
// first piece of data
37
if
(first_data) {
38
first_data =
false
;
39
last_print =
std::chrono::system_clock::now
();
40
}
41
42
if
(
auto
fp = frame.as<
rs2::pose_frame
>()) {
43
pose_counter++;
44
}
45
else
if
(
auto
fs = frame.as<
rs2::frameset
>()) {
46
frame_counter++;
47
}
48
49
// Print the approximate pose and image rates once per second
50
auto
now
=
std::chrono::system_clock::now
();
51
if
(
now
- last_print >= std::chrono::seconds(1)) {
52
std::cout
<<
"\r"
<< std::setprecision(0) << std::fixed
53
<<
"Pose rate: "
<< pose_counter <<
" "
54
<<
"Image rate: "
<< frame_counter << std::flush;
55
pose_counter = 0;
56
frame_counter = 0;
57
last_print =
now
;
58
}
59
};
60
61
// Start streaming through the callback
62
rs2::pipeline_profile
profiles
= pipe.
start
(cfg,
callback
);
63
64
// Sleep this thread until we are done
65
while
(
true
) {
66
std::this_thread::sleep_for(std::chrono::milliseconds(10));
67
}
68
69
return
EXIT_SUCCESS;
70
}
71
catch
(
const
rs2::error
&
e
)
72
{
73
std::cerr
<<
"RealSense error calling "
<< e.
get_failed_function
() <<
"("
<< e.
get_failed_args
() <<
"):\n "
<< e.what() << std::endl;
74
return
EXIT_FAILURE;
75
}
76
catch
(
const
std::exception& e)
77
{
78
std::cerr
<< e.what() << std::endl;
79
return
EXIT_FAILURE;
80
}
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::config
Definition:
rs_pipeline.hpp:124
rs2::frame
Definition:
rs_frame.hpp:343
opencv_pointcloud_viewer.now
now
Definition:
opencv_pointcloud_viewer.py:302
rs2::pipeline_profile
Definition:
rs_pipeline.hpp:18
RS2_FORMAT_6DOF
Definition:
rs_sensor.h:79
RS2_STREAM_FISHEYE
Definition:
rs_sensor.h:48
RS2_STREAM_POSE
Definition:
rs_sensor.h:52
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
test-got-playback-frames.cfg
cfg
Definition:
test-got-playback-frames.py:115
Catch::cout
std::ostream & cout()
librealsense::legacy_file_format::frame_counter
constexpr uint32_t frame_counter
Definition:
ros_file_format.h:619
t265_stereo.profiles
profiles
Definition:
t265_stereo.py:139
t265_stereo.callback
def callback(frame)
Definition:
t265_stereo.py:91
uint64_t
unsigned __int64 uint64_t
Definition:
stdint.h:90
rs2::config::enable_stream
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
Definition:
rs_pipeline.hpp:156
rs2::pipeline
Definition:
rs_pipeline.hpp:362
Catch::cerr
std::ostream & cerr()
rs2::pipeline::start
pipeline_profile start()
Definition:
rs_pipeline.hpp:392
main
int main(int argc, char *argv[])
Definition:
rs-pose-and-image.cpp:10
rs2::pose_frame
Definition:
rs_frame.hpp:912
rs2::error::get_failed_function
const std::string & get_failed_function() const
Definition:
rs_types.hpp:112
RS2_FORMAT_Y8
Definition:
rs_sensor.h:70
librealsense2
Author(s): Sergey Dorodnicov
, Doron Hirshberg
, Mark Horn
, Reagan Lopez
, Itay Carpis
autogenerated on Mon May 3 2021 02:47:40