39 #include <visp3/core/vpImageConvert.h>
40 #include <visp3/sensor/vpRealSense.h>
42 #if defined(VISP_HAVE_REALSENSE) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
44 #include "vpRealSense_impl.h"
51 : m_context(), m_device(nullptr), m_num_devices(0), m_serial_no(), m_intrinsics(), m_max_Z(8), m_enableStreams(),
52 m_useStreamPresets(), m_streamPresets(), m_streamParams(), m_invalidDepthValue(0.0f)
103 std::vector<rs::device *> detected_devices;
107 std::string serial_no = device->get_serial();
111 detected_devices.push_back(device);
118 "RealSense Camera - Multiple cameras detected (%d) but "
119 "no input serial number specified. Exiting!",
126 "RealSense Camera - No camera detected with input "
127 "serial_no \"%s\" Exiting!",
137 std::cout <<
"RealSense Camera - Connecting to camera with Serial No: " <<
m_serial_no << std::endl;
141 ?
m_device->supports(rs::capabilities::infrared2)
148 for (
int j = 0; j < 4; j++) {
149 auto s = (rs::stream)j;
150 auto capabilities = (rs::capabilities)j;
206 for (
int i = 0; i < 4; ++i) {
207 auto stream = rs::stream(i);
208 if (!
m_device->is_stream_enabled(stream))
210 auto intrin =
m_device->get_stream_intrinsics(stream);
217 m_intrinsics[rs::stream::rectified_color] =
m_device->get_stream_intrinsics(rs::stream::rectified_color);
221 m_device->get_stream_intrinsics(rs::stream::color_aligned_to_depth);
223 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_color);
224 m_intrinsics[rs::stream::depth_aligned_to_rectified_color] =
225 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_rectified_color);
231 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_infrared2);
233 m_device->get_stream_intrinsics(rs::stream::infrared2_aligned_to_depth);
276 "RealSense Camera - Multiple cameras detected (%d) but "
277 "no input serial number specified. Exiting!",
299 double u0 = intrinsics.ppx;
300 double v0 = intrinsics.ppy;
301 double px = intrinsics.fx;
302 double py = intrinsics.fy;
304 double kdu = intrinsics.coeffs[0];
323 "retrieve intrinsics. Exiting!");
326 return m_device->get_stream_intrinsics(stream);
340 "retrieve extrinsics. Exiting!");
342 if (!
m_device->is_stream_enabled(from)) {
344 "RealSense Camera - stream (%d) is not enabled to "
345 "retrieve extrinsics. Exiting!",
348 if (!
m_device->is_stream_enabled(to)) {
350 "RealSense Camera - stream (%d) is not enabled to "
351 "retrieve extrinsics. Exiting!",
354 return m_device->get_extrinsics(from, to);
369 for (
unsigned int i = 0; i < 3; i++) {
370 t[i] = extrinsics.translation[i];
371 for (
unsigned int j = 0; j < 3; j++)
372 R[i][j] = extrinsics.rotation[j * 3 + i];
472 std::vector<vpColVector> &pointcloud)
506 std::vector<vpColVector> &pointcloud)
573 std::vector<vpColVector> *
const data_pointCloud,
unsigned char *
const data_infrared,
574 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
575 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
576 const rs::stream &stream_infrared2)
588 if (data_image !=
nullptr) {
589 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
592 if (data_depth !=
nullptr) {
593 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
595 if (data_pointCloud !=
nullptr) {
600 if (data_infrared !=
nullptr) {
601 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
604 if (data_infrared2 !=
nullptr) {
605 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
686 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
779 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud)
811 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud)
843 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud)
875 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud)
919 std::vector<vpColVector> *
const data_pointCloud,
920 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
unsigned char *
const data_infrared,
921 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
922 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
923 const rs::stream &stream_infrared2)
935 if (data_image !=
nullptr) {
936 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
939 if (data_depth !=
nullptr) {
940 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
943 if (data_pointCloud !=
nullptr) {
947 if (pointcloud !=
nullptr) {
951 if (data_infrared !=
nullptr) {
952 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
955 if (data_infrared2 !=
nullptr) {
956 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
979 std::vector<vpColVector> *
const data_pointCloud,
980 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud,
unsigned char *
const data_infrared,
981 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
982 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
983 const rs::stream &stream_infrared2)
995 if (data_image !=
nullptr) {
996 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
999 if (data_depth !=
nullptr) {
1000 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
1003 if (data_pointCloud !=
nullptr) {
1007 if (pointcloud !=
nullptr) {
1012 if (data_infrared !=
nullptr) {
1013 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
1016 if (data_infrared2 !=
nullptr) {
1017 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
1048 os <<
"Device name: " << rs.
getHandler()->get_name() << std::endl;
1049 std::streamsize ss = std::cout.precision();
1050 for (
int i = 0; i < 4; ++i) {
1051 auto stream = rs::stream(i);
1052 if (!rs.
getHandler()->is_stream_enabled(stream))
1054 auto intrin = rs.
getHandler()->get_stream_intrinsics(stream);
1055 std::cout <<
"Capturing " << stream <<
" at " << intrin.width <<
" x " << intrin.height;
1056 std::cout << std::setprecision(1) << std::fixed <<
", fov = " << intrin.hfov() <<
" x " << intrin.vfov()
1057 <<
", distortion = " << intrin.model() << std::endl;
1059 std::cout.precision(ss);
1064 #elif !defined(VISP_BUILD_SHARED_LIBS)
1066 void dummy_vpRealSense() { };
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
vpCameraParametersProjType
@ perspectiveProjWithDistortion
Perspective projection with distortion model.
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setDeviceBySerialNumber(const std::string &serial_no)
void setStreamSettings(const rs::stream &stream, const rs::preset &preset)
std::map< rs::stream, bool > m_enableStreams
rs::device * getHandler() const
Get access to device handler.
rs::extrinsics getExtrinsics(const rs::stream &from, const rs::stream &to) const
vpCameraParameters getCameraParameters(const rs::stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion) const
void acquire(std::vector< vpColVector > &pointcloud)
std::map< rs::stream, bool > m_useStreamPresets
vpHomogeneousMatrix getTransformation(const rs::stream &from, const rs::stream &to) const
void setEnableStream(const rs::stream &stream, bool status)
std::map< rs::stream, rs::intrinsics > m_intrinsics
std::map< rs::stream, rs::preset > m_streamPresets
float m_invalidDepthValue
rs::intrinsics getIntrinsics(const rs::stream &stream) const
std::map< rs::stream, vpRsStreamParams > m_streamParams
float m_max_Z
Maximal Z depth in meter.
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.