43 #include <visp3/core/vpMeterPixelConversion.h>
44 #include <visp3/gui/vpDisplayGDI.h>
45 #include <visp3/gui/vpDisplayX.h>
46 #include <visp3/sensor/vpRealSense2.h>
48 #if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_THREADS) \
49 && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
56 #ifdef ENABLE_VISP_NAMESPACE
62 unsigned int confidence;
64 std::list<std::pair<unsigned int, vpImagePoint> >
66 unsigned int display_scale = 2;
72 config.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
73 config.enable_stream(RS2_STREAM_FISHEYE, 1, RS2_FORMAT_Y8);
74 config.enable_stream(RS2_STREAM_FISHEYE, 2, RS2_FORMAT_Y8);
84 std::function<void(rs2::frame)> callback = [&](
const rs2::frame &frame) {
85 if (rs2::frameset fs = frame.as<rs2::frameset>()) {
87 rs2::video_frame left_frame = fs.get_fisheye_frame(1);
88 size_t size = left_frame.get_width() * left_frame.get_height();
89 memcpy(I_left.
bitmap, left_frame.get_data(), size);
91 rs2::video_frame right_frame = fs.get_fisheye_frame(2);
92 size = right_frame.get_width() * right_frame.get_height();
93 memcpy(I_right.
bitmap, right_frame.get_data(), size);
95 rs2_pose pose_data = fs.get_pose_frame().get_pose_data();
98 static_cast<double>(pose_data.translation.y),
99 static_cast<double>(pose_data.translation.z));
100 vpQuaternionVector cqw(
static_cast<double>(pose_data.rotation.x),
static_cast<double>(pose_data.rotation.y),
101 static_cast<double>(pose_data.rotation.z),
static_cast<double>(pose_data.rotation.w));
106 odo_vel[0] =
static_cast<double>(pose_data.velocity.x);
107 odo_vel[1] =
static_cast<double>(pose_data.velocity.y);
108 odo_vel[2] =
static_cast<double>(pose_data.velocity.z);
109 odo_vel[3] =
static_cast<double>(pose_data.angular_velocity.x);
110 odo_vel[4] =
static_cast<double>(pose_data.angular_velocity.y);
111 odo_vel[5] =
static_cast<double>(pose_data.angular_velocity.z);
114 odo_acc[0] =
static_cast<double>(pose_data.acceleration.x);
115 odo_acc[1] =
static_cast<double>(pose_data.acceleration.y);
116 odo_acc[2] =
static_cast<double>(pose_data.acceleration.z);
117 odo_acc[3] =
static_cast<double>(pose_data.angular_acceleration.x);
118 odo_acc[4] =
static_cast<double>(pose_data.angular_acceleration.y);
119 odo_acc[5] =
static_cast<double>(pose_data.angular_acceleration.z);
121 confidence = pose_data.tracker_confidence;
125 rs2_pose pose_data = frame.as<rs2::pose_frame>().get_pose_data();
127 static_cast<double>(pose_data.translation.y),
128 static_cast<double>(pose_data.translation.z));
129 vpQuaternionVector cqw(
static_cast<double>(pose_data.rotation.x),
static_cast<double>(pose_data.rotation.y),
130 static_cast<double>(pose_data.rotation.z),
static_cast<double>(pose_data.rotation.w));
135 odo_vel[0] =
static_cast<double>(pose_data.velocity.x);
136 odo_vel[1] =
static_cast<double>(pose_data.velocity.y);
137 odo_vel[2] =
static_cast<double>(pose_data.velocity.z);
138 odo_vel[3] =
static_cast<double>(pose_data.angular_velocity.x);
139 odo_vel[4] =
static_cast<double>(pose_data.angular_velocity.y);
140 odo_vel[5] =
static_cast<double>(pose_data.angular_velocity.z);
143 odo_acc[0] =
static_cast<double>(pose_data.acceleration.x);
144 odo_acc[1] =
static_cast<double>(pose_data.acceleration.y);
145 odo_acc[2] =
static_cast<double>(pose_data.acceleration.z);
146 odo_acc[3] =
static_cast<double>(pose_data.angular_acceleration.x);
147 odo_acc[4] =
static_cast<double>(pose_data.angular_acceleration.y);
148 odo_acc[5] =
static_cast<double>(pose_data.angular_acceleration.z);
150 confidence = pose_data.tracker_confidence;
156 frame_origins.push_back(std::make_pair(confidence, frame_origin));
160 g.
open(config, callback);
166 #if defined(VISP_HAVE_X11)
167 vpDisplayX display_left;
168 vpDisplayX display_right;
169 vpDisplayX display_pose;
170 #elif defined(VISP_HAVE_GDI)
176 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
178 display_right.setDownScalingFactor(display_scale);
179 display_left.init(I_left, 10, 10,
"Left image");
180 display_right.init(I_right,
static_cast<int>(I_left.
getWidth() / display_scale) + 80, 10,
"Right image");
181 display_pose.init(I_pose, 10,
static_cast<int>(I_left.
getHeight() / display_scale) + 80,
188 frame_origins.push_back(std::make_pair(confidence, frame_origin));
192 std::this_thread::sleep_for(std::chrono::milliseconds(1));
200 frame_origins.push_back(std::make_pair(confidence, frame_origin));
211 std::list<std::pair<unsigned int, vpImagePoint> >::const_iterator it = frame_origins.begin();
212 std::pair<unsigned int, vpImagePoint> frame_origin_pair_prev = *(it++);
213 for (; it != frame_origins.end(); ++it) {
216 I_pose, frame_origin_pair_prev.second, (*it).second,
218 frame_origin_pair_prev = *it;
232 std::cerr <<
"RealSense error " << e.
what() << std::endl;
234 catch (
const std::exception &e) {
235 std::cerr << e.what() << std::endl;
243 #if !defined(VISP_HAVE_REALSENSE2)
244 std::cout <<
"You do not realsense2 SDK functionality enabled..." << std::endl;
245 std::cout <<
"Tip:" << std::endl;
246 std::cout <<
"- Install librealsense2, configure again ViSP using cmake and build again this example" << std::endl;
248 #elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
249 std::cout <<
"You don't have X11 or GDI display capabilities" << std::endl;
250 #elif !(RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
251 std::cout <<
"Install librealsense version > 2.31.0" << std::endl;
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
static const vpColor none
static const vpColor yellow
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
void setDownScalingFactor(unsigned int scale)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
const char * what() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Implementation of a rotation vector as quaternion angle minimal representation.
bool open(const rs2::config &cfg=rs2::config())
rs2_intrinsics getIntrinsics(const rs2_stream &stream, int index=-1) const
Class that consider the case of a translation vector.