42 #include <visp3/core/vpImageConvert.h> 43 #include <visp3/sensor/vpRealSense.h> 45 #if defined(VISP_HAVE_REALSENSE) && defined(VISP_HAVE_CPP11_COMPATIBILITY) 47 #include "vpRealSense_impl.h" 53 : m_context(), m_device(NULL), m_num_devices(0), m_serial_no(), m_intrinsics(), m_max_Z(8), m_enableStreams(),
54 m_useStreamPresets(), m_streamPresets(), m_streamParams(), m_invalidDepthValue(0.0f)
105 std::vector<rs::device *> detected_devices;
109 std::string serial_no = device->get_serial();
113 detected_devices.push_back(device);
118 if ((
m_serial_no.empty()) && (m_num_devices > 1)) {
120 "RealSense Camera - Multiple cameras detected (%d) but " 121 "no input serial number specified. Exiting!",
128 "RealSense Camera - No camera detected with input " 129 "serial_no \"%s\" Exiting!",
138 std::cout <<
"RealSense Camera - Connecting to camera with Serial No: " << m_device->get_serial() << std::endl;
142 ? m_device->supports(rs::capabilities::infrared2)
145 if (m_device->is_streaming()) {
149 for (
int j = 0; j < 4; j++) {
150 auto s = (rs::stream)j;
151 auto capabilities = (rs::capabilities)j;
152 if (m_device->supports(capabilities) && m_device->is_stream_enabled(s)) {
153 m_device->disable_stream(s);
159 m_device->enable_stream(rs::stream::color,
m_streamPresets[rs::stream::color]);
161 m_device->enable_stream(rs::stream::color,
m_streamParams[rs::stream::color].m_streamWidth,
170 m_device->enable_stream(rs::stream::depth,
m_streamPresets[rs::stream::depth]);
172 m_device->enable_stream(rs::stream::depth,
m_streamParams[rs::stream::depth].m_streamWidth,
181 m_device->enable_stream(rs::stream::infrared,
m_streamPresets[rs::stream::infrared]);
183 m_device->enable_stream(rs::stream::infrared,
m_streamParams[rs::stream::infrared].m_streamWidth,
192 m_device->enable_stream(rs::stream::infrared2,
m_streamPresets[rs::stream::infrared2]);
194 m_device->enable_stream(rs::stream::infrared2,
m_streamParams[rs::stream::infrared2].m_streamWidth,
203 for (
int i = 0; i < 4; ++i) {
204 auto stream = rs::stream(i);
205 if (!m_device->is_stream_enabled(stream))
207 auto intrin = m_device->get_stream_intrinsics(stream);
214 m_intrinsics[rs::stream::rectified_color] = m_device->get_stream_intrinsics(rs::stream::rectified_color);
218 m_device->get_stream_intrinsics(rs::stream::color_aligned_to_depth);
220 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_color);
221 m_intrinsics[rs::stream::depth_aligned_to_rectified_color] =
222 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_rectified_color);
228 m_device->get_stream_intrinsics(rs::stream::depth_aligned_to_infrared2);
230 m_device->get_stream_intrinsics(rs::stream::infrared2_aligned_to_depth);
269 "RealSense Camera - Multiple cameras detected (%d) but " 270 "no input serial number specified. Exiting!",
292 double u0 = intrinsics.ppx;
293 double v0 = intrinsics.ppy;
294 double px = intrinsics.fx;
295 double py = intrinsics.fy;
297 double kdu = intrinsics.coeffs[0];
315 "retrieve intrinsics. Exiting!");
317 if (!
m_device->is_stream_enabled(stream)) {
319 "RealSense Camera - stream (%d) is not enabled to " 320 "retrieve intrinsics. Exiting!",
324 std::map<rs::stream, rs::intrinsics>::const_iterator it_intrin =
m_intrinsics.find(stream);
326 return it_intrin->second;
329 return rs::intrinsics();
343 "retrieve extrinsics. Exiting!");
345 if (!
m_device->is_stream_enabled(from)) {
347 "RealSense Camera - stream (%d) is not enabled to " 348 "retrieve extrinsics. Exiting!",
351 if (!
m_device->is_stream_enabled(to)) {
353 "RealSense Camera - stream (%d) is not enabled to " 354 "retrieve extrinsics. Exiting!",
357 return m_device->get_extrinsics(from, to);
372 for (
unsigned int i = 0; i < 3; i++) {
373 t[i] = extrinsics.translation[i];
374 for (
unsigned int j = 0; j < 3; j++)
375 R[i][j] = extrinsics.rotation[i * 3 + j];
475 std::vector<vpColVector> &pointcloud)
509 std::vector<vpColVector> &pointcloud)
576 std::vector<vpColVector> *
const data_pointCloud,
unsigned char *
const data_infrared,
577 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
578 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
579 const rs::stream &stream_infrared2)
591 if (data_image != NULL) {
592 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
595 if (data_depth != NULL) {
596 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
598 if (data_pointCloud != NULL) {
603 if (data_infrared != NULL) {
604 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
607 if (data_infrared2 != NULL) {
608 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
774 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud)
806 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud)
838 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud)
870 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud)
914 std::vector<vpColVector> *
const data_pointCloud,
915 pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
unsigned char *
const data_infrared,
916 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
917 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
918 const rs::stream &stream_infrared2)
930 if (data_image != NULL) {
931 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
934 if (data_depth != NULL) {
935 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
938 if (data_pointCloud != NULL) {
942 if (pointcloud != NULL) {
946 if (data_infrared != NULL) {
947 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
950 if (data_infrared2 != NULL) {
951 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
974 std::vector<vpColVector> *
const data_pointCloud,
975 pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud,
unsigned char *
const data_infrared,
976 unsigned char *
const data_infrared2,
const rs::stream &stream_color,
977 const rs::stream &stream_depth,
const rs::stream &stream_infrared,
978 const rs::stream &stream_infrared2)
990 if (data_image != NULL) {
991 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::color, data_image, stream_color);
994 if (data_depth != NULL) {
995 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::depth, data_depth, stream_depth);
998 if (data_pointCloud != NULL) {
1002 if (pointcloud != NULL) {
1007 if (data_infrared != NULL) {
1008 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared, data_infrared, stream_infrared);
1011 if (data_infrared2 != NULL) {
1012 vp_rs_get_native_frame_data_impl(
m_device,
m_intrinsics, rs::stream::infrared2, data_infrared2, stream_infrared2);
1039 os <<
"Device name: " << rs.
getHandler()->get_name() << std::endl;
1040 std::streamsize ss = std::cout.precision();
1041 for (
int i = 0; i < 4; ++i) {
1042 auto stream = rs::stream(i);
1043 if (!rs.
getHandler()->is_stream_enabled(stream))
1045 auto intrin = rs.
getHandler()->get_stream_intrinsics(stream);
1046 std::cout <<
"Capturing " << stream <<
" at " << intrin.width <<
" x " << intrin.height;
1047 std::cout << std::setprecision(1) << std::fixed <<
", fov = " << intrin.hfov() <<
" x " << intrin.vfov()
1048 <<
", distortion = " << intrin.model() << std::endl;
1050 std::cout.precision(ss);
1055 #elif !defined(VISP_BUILD_SHARED_LIBS) 1058 void dummy_vpRealSense(){};
rs::device * getHandler() const
Get access to device handler.
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpRealSense &rs)
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
void acquire(std::vector< vpColVector > &pointcloud)
Implementation of a rotation matrix and operations on such kind of matrices.
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void setDeviceBySerialNumber(const std::string &serial_no)
std::map< rs::stream, vpRsStreamParams > m_streamParams
std::map< rs::stream, bool > m_useStreamPresets
rs::extrinsics getExtrinsics(const rs::stream &from, const rs::stream &to) const
vpCameraParametersProjType
Generic class defining intrinsic camera parameters.
std::map< rs::stream, rs::preset > m_streamPresets
void setStreamSettings(const rs::stream &stream, const rs::preset &preset)
void setEnableStream(const rs::stream &stream, const bool status)
vpCameraParameters getCameraParameters(const rs::stream &stream, vpCameraParameters::vpCameraParametersProjType type=vpCameraParameters::perspectiveProjWithDistortion) const
rs::intrinsics getIntrinsics(const rs::stream &stream) const
float m_invalidDepthValue
vpHomogeneousMatrix getTransformation(const rs::stream &from, const rs::stream &to) const
std::map< rs::stream, rs::intrinsics > m_intrinsics
std::map< rs::stream, bool > m_enableStreams
Class that consider the case of a translation vector.
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)
float m_max_Z
Maximal Z depth in meter.