34 #include <arpa/inet.h>
36 #include <turbojpeg.h>
38 #include <Eigen/Geometry>
39 #include <opencv2/opencv.hpp>
46 #include <multisense_lib/MultiSenseChannel.hh>
48 #include <multisense_ros/RawCamConfig.h>
49 #include <multisense_ros/RawCamCal.h>
50 #include <multisense_ros/DeviceInfo.h>
51 #include <multisense_ros/Histogram.h>
94 {
reinterpret_cast<Camera*
>(userDataP)->monoCallback(header); }
96 {
reinterpret_cast<Camera*
>(userDataP)->rectCallback(header); }
98 {
reinterpret_cast<Camera*
>(userDataP)->depthCallback(header); }
100 {
reinterpret_cast<Camera*
>(userDataP)->pointCloudCallback(header); }
102 {
reinterpret_cast<Camera*
>(userDataP)->rawCamDataCallback(header); }
104 {
reinterpret_cast<Camera*
>(userDataP)->colorImageCallback(header); }
106 {
reinterpret_cast<Camera*
>(userDataP)->disparityImageCallback(header); }
108 {
reinterpret_cast<Camera*
>(userDataP)->jpegImageCallback(header); }
110 {
reinterpret_cast<Camera*
>(userDataP)->histogramCallback(header); }
111 void colorizeCB(
const image::Header& header,
void* userDataP)
112 {
reinterpret_cast<Camera*
>(userDataP)->colorizeCallback(header); }
113 void groundSurfaceCB(
const image::Header& header,
void* userDataP)
114 {
reinterpret_cast<Camera*
>(userDataP)->groundSurfaceCallback(header); }
116 {
reinterpret_cast<Camera*
>(userDataP)->groundSurfaceSplineCallback(header); }
123 constexpr
char Camera::LEFT[];
124 constexpr
char Camera::RIGHT[];
125 constexpr
char Camera::AUX[];
126 constexpr
char Camera::CALIBRATION[];
127 constexpr
char Camera::GROUND_SURFACE[];
129 constexpr
char Camera::ORIGIN_FRAME[];
130 constexpr
char Camera::HEAD_FRAME[];
131 constexpr
char Camera::LEFT_CAMERA_FRAME[];
132 constexpr
char Camera::RIGHT_CAMERA_FRAME[];
133 constexpr
char Camera::LEFT_RECTIFIED_FRAME[];
134 constexpr
char Camera::RIGHT_RECTIFIED_FRAME[];
135 constexpr
char Camera::AUX_CAMERA_FRAME[];
136 constexpr
char Camera::AUX_RECTIFIED_FRAME[];
138 constexpr
char Camera::DEVICE_INFO_TOPIC[];
139 constexpr
char Camera::RAW_CAM_CAL_TOPIC[];
140 constexpr
char Camera::RAW_CAM_CONFIG_TOPIC[];
141 constexpr
char Camera::RAW_CAM_DATA_TOPIC[];
142 constexpr
char Camera::HISTOGRAM_TOPIC[];
143 constexpr
char Camera::MONO_TOPIC[];
144 constexpr
char Camera::RECT_TOPIC[];
145 constexpr
char Camera::DISPARITY_TOPIC[];
146 constexpr
char Camera::DISPARITY_IMAGE_TOPIC[];
147 constexpr
char Camera::DEPTH_TOPIC[];
148 constexpr
char Camera::OPENNI_DEPTH_TOPIC[];
149 constexpr
char Camera::COST_TOPIC[];
150 constexpr
char Camera::COLOR_TOPIC[];
151 constexpr
char Camera::RECT_COLOR_TOPIC[];
152 constexpr
char Camera::POINTCLOUD_TOPIC[];
153 constexpr
char Camera::COLOR_POINTCLOUD_TOPIC[];
154 constexpr
char Camera::ORGANIZED_POINTCLOUD_TOPIC[];
155 constexpr
char Camera::COLOR_ORGANIZED_POINTCLOUD_TOPIC[];
156 constexpr
char Camera::MONO_CAMERA_INFO_TOPIC[];
157 constexpr
char Camera::RECT_CAMERA_INFO_TOPIC[];
158 constexpr
char Camera::COLOR_CAMERA_INFO_TOPIC[];
159 constexpr
char Camera::RECT_COLOR_CAMERA_INFO_TOPIC[];
160 constexpr
char Camera::DEPTH_CAMERA_INFO_TOPIC[];
161 constexpr
char Camera::DISPARITY_CAMERA_INFO_TOPIC[];
162 constexpr
char Camera::COST_CAMERA_INFO_TOPIC[];
163 constexpr
char Camera::GROUND_SURFACE_IMAGE_TOPIC[];
164 constexpr
char Camera::GROUND_SURFACE_INFO_TOPIC[];
165 constexpr
char Camera::GROUND_SURFACE_POINT_SPLINE_TOPIC[];
167 Camera::Camera(
Channel* driver,
const std::string& tf_prefix) :
170 left_nh_(device_nh_, LEFT),
171 right_nh_(device_nh_, RIGHT),
172 aux_nh_(device_nh_, AUX),
173 calibration_nh_(device_nh_, CALIBRATION),
174 ground_surface_nh_(device_nh_, GROUND_SURFACE),
175 left_mono_transport_(left_nh_),
176 right_mono_transport_(right_nh_),
177 left_rect_transport_(left_nh_),
178 right_rect_transport_(right_nh_),
179 left_rgb_transport_(left_nh_),
180 left_rgb_rect_transport_(left_nh_),
181 depth_transport_(device_nh_),
182 ni_depth_transport_(device_nh_),
183 disparity_left_transport_(left_nh_),
184 disparity_right_transport_(right_nh_),
185 disparity_cost_transport_(left_nh_),
186 aux_mono_transport_(aux_nh_),
187 aux_rgb_transport_(aux_nh_),
188 aux_rect_transport_(aux_nh_),
189 aux_rgb_rect_transport_(aux_nh_),
190 ground_surface_transport_(ground_surface_nh_),
191 stereo_calibration_manager_(nullptr),
192 frame_id_origin_(tf_prefix + ORIGIN_FRAME),
193 frame_id_head_(tf_prefix + HEAD_FRAME),
194 frame_id_left_(tf_prefix + LEFT_CAMERA_FRAME),
195 frame_id_right_(tf_prefix + RIGHT_CAMERA_FRAME),
196 frame_id_aux_(tf_prefix + AUX_CAMERA_FRAME),
197 frame_id_rectified_left_(tf_prefix + LEFT_RECTIFIED_FRAME),
198 frame_id_rectified_right_(tf_prefix + RIGHT_RECTIFIED_FRAME),
199 frame_id_rectified_aux_(tf_prefix + AUX_RECTIFIED_FRAME),
200 static_tf_broadcaster_(),
201 pointcloud_max_range_(15.0),
204 border_clip_value_(0.0)
210 if (Status_Ok != status) {
211 ROS_ERROR(
"Camera: failed to query version info: %s", Channel::statusString(status));
216 if (Status_Ok != status) {
217 ROS_ERROR(
"Camera: failed to query device info: %s", Channel::statusString(status));
226 if (Status_Ok != status) {
227 ROS_ERROR(
"Camera: failed to query sensor configuration: %s", Channel::statusString(status));
417 const auto point_cloud_color_topics =
has_aux_camera_ ? Source_Luma_Rectified_Aux | Source_Chroma_Rectified_Aux :
418 Source_Luma_Left | Source_Chroma_Left;
422 Source_Disparity | point_cloud_color_topics),
424 Source_Disparity | point_cloud_color_topics));
428 Source_Disparity | point_cloud_color_topics),
430 Source_Disparity | point_cloud_color_topics));
488 multisense_ros::DeviceInfo
msg;
497 msg.pcbSerialNumbers.push_back(pcb.revision);
498 msg.pcbNames.push_back(pcb.name);
539 if (Status_Ok != status) {
540 ROS_ERROR(
"Camera: failed to query image calibration: %s",
541 Channel::statusString(status));
547 multisense_ros::RawCamCal cal;
550 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
M[0][0]));
551 for(uint32_t i=0; i<9; i++) cal.left_M[i] = cP[i];
552 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
D[0]));
553 for(uint32_t i=0; i<8; i++) cal.left_D[i] = cP[i];
554 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
R[0][0]));
555 for(uint32_t i=0; i<9; i++) cal.left_R[i] = cP[i];
556 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
P[0][0]));
557 for(uint32_t i=0; i<12; i++) cal.left_P[i] = cP[i];
562 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
M[0][0]));
563 for(uint32_t i=0; i<9; i++) cal.right_M[i] = cP[i];
564 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
D[0]));
565 for(uint32_t i=0; i<8; i++) cal.right_D[i] = cP[i];
566 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
R[0][0]));
567 for(uint32_t i=0; i<9; i++) cal.right_R[i] = cP[i];
568 cP =
reinterpret_cast<const float *
>(&(image_calibration.
left.
P[0][0]));
569 for(uint32_t i=0; i<12; i++) cal.right_P[i] = cP[i];
573 cP =
reinterpret_cast<const float *
>(&(image_calibration.
right.
M[0][0]));
574 for(uint32_t i=0; i<9; i++) cal.right_M[i] = cP[i];
575 cP =
reinterpret_cast<const float *
>(&(image_calibration.
right.
D[0]));
576 for(uint32_t i=0; i<8; i++) cal.right_D[i] = cP[i];
577 cP =
reinterpret_cast<const float *
>(&(image_calibration.
right.
R[0][0]));
578 for(uint32_t i=0; i<9; i++) cal.right_R[i] = cP[i];
579 cP =
reinterpret_cast<const float *
>(&(image_calibration.
right.
P[0][0]));
580 for(uint32_t i=0; i<12; i++) cal.right_P[i] = cP[i];
590 ROS_WARN(
"Camera: invalid aux camera calibration");
600 std::vector<geometry_msgs::TransformStamped> stamped_transforms{};
602 stamped_transforms.emplace_back();
603 tf2::Transform rectified_left_T_left{toRotation(image_calibration.
left.
R), tf2::Vector3{0., 0., 0.}};
607 stamped_transforms.back().transform =
tf2::toMsg(rectified_left_T_left);
609 if (has_right_extrinsics)
611 stamped_transforms.emplace_back();
617 stamped_transforms.back().transform =
tf2::toMsg(rectified_right_T_rectified_left.inverse());
619 stamped_transforms.emplace_back();
620 tf2::Transform rectified_right_T_right{toRotation(image_calibration.
right.
R), tf2::Vector3{0., 0., 0.}};
624 stamped_transforms.back().transform =
tf2::toMsg(rectified_right_T_right);
627 if (has_aux_extrinsics)
631 stamped_transforms.emplace_back();
633 tf2::Vector3{aux_T(0), aux_T(1), aux_T(2)}};
637 stamped_transforms.back().transform =
tf2::toMsg(rectified_aux_T_rectified_left.inverse());
639 stamped_transforms.emplace_back();
640 tf2::Transform rectified_aux_T_aux{toRotation(image_calibration.
aux.
R), tf2::Vector3{0., 0., 0.}};
644 stamped_transforms.back().transform =
tf2::toMsg(rectified_aux_T_aux);
678 driver_->
addIsolatedCallback(rectCB, Source_Luma_Rectified_Left | Source_Luma_Rectified_Right | Source_Luma_Rectified_Aux,
this);
683 Source_Luma_Left | Source_Luma_Rectified_Left,
this);
714 const char *pcColorFrameSyncEnvStringP = getenv(
"MULTISENSE_ROS_PC_COLOR_FRAME_SYNC_OFF");
715 if (NULL != pcColorFrameSyncEnvStringP) {
716 ROS_INFO(
"color point cloud frame sync is disabled");
787 Eigen::Matrix<float, 3, 3> eigen_rot =
788 (Eigen::AngleAxis<float>(extrinsics.
yaw, Eigen::Matrix<float, 3, 1>(0, 0, 1))
789 * Eigen::AngleAxis<float>(extrinsics.
pitch, Eigen::Matrix<float, 3, 1>(0, 1, 0))
790 * Eigen::AngleAxis<float>(extrinsics.
roll, Eigen::Matrix<float, 3, 1>(1, 0, 0))).matrix();
803 std::vector<geometry_msgs::TransformStamped> extrinsic_transforms_(1);
805 tf2::Transform multisense_head_T_origin{tf2_rot, tf2::Vector3{extrinsics.
x, extrinsics.
y, extrinsics.
z}};
809 extrinsic_transforms_[0].transform =
tf2::toMsg(multisense_head_T_origin);
828 multisense_ros::Histogram rh;
832 if (Status_Ok == status) {
833 rh.frame_count =
header.frameId;
836 rh.height =
header.height;
838 case Source_Chroma_Left:
839 case Source_Chroma_Right:
844 rh.exposure_time =
header.exposure;
846 rh.fps =
header.framesPerSecond;
857 if (Source_Jpeg_Left !=
header.source) {
865 throw std::runtime_error(
"Uninitialized stereo calibration manager");
868 const uint32_t height =
header.height;
869 const uint32_t width =
header.width;
870 const uint32_t rgbLength = height * width * 3;
882 tjhandle jpegDecompressor = tjInitDecompress();
883 tjDecompress2(jpegDecompressor,
884 reinterpret_cast<unsigned char*
>(
const_cast<void*
>(
header.imageDataP)),
887 width, 0, height, TJPF_RGB, 0);
888 tjDestroy(jpegDecompressor);
901 const cv::Mat rgb_image(height, width, CV_8UC3, &(
left_rgb_image_.data[0]));
906 cv::remap(rgb_image, rect_rgb_image, left_remap->map1, left_remap->map2, cv::INTER_LINEAR);
922 if (!((Source_Disparity ==
header.source &&
924 (Source_Disparity_Right ==
header.source &&
926 (Source_Disparity_Cost ==
header.source &&
928 (Source_Disparity ==
header.source &&
930 (Source_Disparity_Right ==
header.source &&
940 throw std::runtime_error(
"Uninitialized stereo calibration manager");
944 case Source_Disparity:
945 case Source_Disparity_Right:
947 sensor_msgs::Image *imageP = NULL;
949 sensor_msgs::CameraInfo camInfo;
952 stereo_msgs::DisparityImage *stereoDisparityImageP = NULL;
955 if (Source_Disparity ==
header.source) {
977 imageP->data.resize(imageSize);
978 memcpy(&imageP->data[0],
header.imageDataP, imageSize);
980 imageP->header.stamp =
t;
981 imageP->height =
header.height;
982 imageP->width =
header.width;
983 imageP->is_bigendian = (htonl(1) == 1);
985 switch(
header.bitsPerPixel) {
988 imageP->step =
header.width;
992 imageP->step =
header.width * 2;
1003 throw std::runtime_error(
"Stereo calibration manager missing right calibration");
1011 if (camInfo.P[0] != camInfo.P[5])
1013 std::stringstream warning;
1014 warning <<
"Current camera configuration has non-square pixels (fx != fy).";
1015 warning <<
"The stereo_msgs/DisparityImage does not account for";
1016 warning <<
" this. Be careful when reprojecting to a pointcloud.";
1017 ROS_WARN(
"%s", warning.str().c_str());
1024 uint32_t floatingPointImageSize =
header.width *
header.height * 4;
1025 stereoDisparityImageP->image.data.resize(floatingPointImageSize);
1027 stereoDisparityImageP->header.stamp =
t;
1029 stereoDisparityImageP->image.height =
header.height;
1030 stereoDisparityImageP->image.width =
header.width;
1031 stereoDisparityImageP->image.is_bigendian = (htonl(1) == 1);
1032 stereoDisparityImageP->image.header.stamp =
t;
1033 stereoDisparityImageP->image.header.frame_id = stereoDisparityImageP->header.frame_id;
1035 stereoDisparityImageP->image.step = 4 *
header.width;
1041 stereoDisparityImageP->f = camInfo.P[0];
1048 stereoDisparityImageP->min_disparity = 0;
1050 stereoDisparityImageP->delta_d = 1./16.;
1058 cv::Mat_<uint16_t> tmpImage(
header.height,
1060 reinterpret_cast<uint16_t*
>(
1061 const_cast<void*
>(
header.imageDataP)));
1066 cv::Mat_<float> floatingPointImage(
header.height,
1068 reinterpret_cast<float*
>(&stereoDisparityImageP->image.data[0]));
1074 floatingPointImage = tmpImage / 16.0;
1076 stereoDisparityPubP->
publish(*stereoDisparityImageP);
1079 camInfoPubP->
publish(camInfo);
1083 case Source_Disparity_Cost:
1107 if (Source_Luma_Left !=
header.source &&
1108 Source_Luma_Right !=
header.source &&
1109 Source_Luma_Aux !=
header.source) {
1111 ROS_ERROR(
"Camera: unexpected mono image source: 0x%lx",
header.source);
1119 throw std::runtime_error(
"Uninitialized stereo calibration manager");
1123 case Source_Luma_Left:
1134 switch(
header.bitsPerPixel) {
1155 case Source_Luma_Right:
1165 switch(
header.bitsPerPixel) {
1185 case Source_Luma_Aux:
1195 switch(
header.bitsPerPixel) {
1219 if (Source_Luma_Rectified_Left !=
header.source &&
1220 Source_Luma_Rectified_Right !=
header.source &&
1221 Source_Luma_Rectified_Aux !=
header.source) {
1223 ROS_ERROR(
"Camera: unexpected rectified image source: 0x%lx",
header.source);
1231 throw std::runtime_error(
"Uninitialized stereo calibration manager");
1235 case Source_Luma_Rectified_Left:
1246 switch(
header.bitsPerPixel) {
1273 case Source_Luma_Rectified_Right:
1284 switch(
header.bitsPerPixel) {
1309 case Source_Luma_Rectified_Aux:
1320 switch(
header.bitsPerPixel) {
1350 if (Source_Disparity !=
header.source) {
1352 ROS_ERROR(
"Camera: unexpected depth image source: 0x%lx",
header.source);
1359 if (0 == niDepthSubscribers && 0 == depthSubscribers)
1368 throw std::runtime_error(
"Uninitialized stereo calibration manager");
1371 const float bad_point = std::numeric_limits<float>::quiet_NaN();
1373 const uint32_t niDepthSize =
header.height *
header.width *
sizeof(uint16_t);
1374 const uint32_t imageSize =
header.width *
header.height;
1393 float *depthImageP =
reinterpret_cast<float*
>(&
depth_image_.data[0]);
1394 uint16_t *niDepthImageP =
reinterpret_cast<uint16_t*
>(&
ni_depth_image_.data[0]);
1396 const uint16_t min_ni_depth = std::numeric_limits<uint16_t>::lowest();
1397 const uint16_t max_ni_depth = std::numeric_limits<uint16_t>::max();
1402 throw std::runtime_error(
"Stereo calibration manager missing right calibration");
1408 if (32 ==
header.bitsPerPixel) {
1421 const float *disparityImageP =
reinterpret_cast<const float*
>(
header.imageDataP);
1423 for (uint32_t i = 0 ; i < imageSize ; ++i)
1425 if (0.0 >= disparityImageP[i])
1427 depthImageP[i] = bad_point;
1428 niDepthImageP[i] = 0;
1432 depthImageP[i] = scale / disparityImageP[i];
1433 niDepthImageP[i] =
static_cast<uint16_t
>(std::min(
static_cast<float>(max_ni_depth),
1434 std::max(
static_cast<float>(min_ni_depth),
1435 depthImageP[i] * 1000)));
1442 }
else if (16 ==
header.bitsPerPixel) {
1457 const uint16_t *disparityImageP =
reinterpret_cast<const uint16_t*
>(
header.imageDataP);
1459 for (uint32_t i = 0 ; i < imageSize ; ++i)
1461 if (0 == disparityImageP[i])
1463 depthImageP[i] = bad_point;
1464 niDepthImageP[i] = 0;
1468 depthImageP[i] = scale / disparityImageP[i];
1469 niDepthImageP[i] =
static_cast<uint16_t
>(std::min(
static_cast<float>(max_ni_depth),
1470 std::max(
static_cast<float>(min_ni_depth),
1471 depthImageP[i] * 1000)));
1476 ROS_ERROR(
"Camera: unsupported disparity bpp: %d",
header.bitsPerPixel);
1480 if (0 != niDepthSubscribers)
1485 if (0 != depthSubscribers)
1495 if (Source_Disparity !=
header.source) {
1497 ROS_ERROR(
"Camera: unexpected pointcloud image source: 0x%lx",
header.source);
1503 throw std::runtime_error(
"Uninitialized stereo calibration manager");
1509 std::shared_ptr<BufferWrapper<image::Header>> left_luma_rect =
nullptr;
1510 std::shared_ptr<BufferWrapper<image::Header>> left_luma =
nullptr;
1511 std::shared_ptr<BufferWrapper<image::Header>> left_chroma =
nullptr;
1512 std::shared_ptr<BufferWrapper<image::Header>> aux_luma_rectified =
nullptr;
1513 std::shared_ptr<BufferWrapper<image::Header>> aux_chroma_rectified =
nullptr;
1515 const auto left_rect_image =
image_buffers_.find(Source_Luma_Rectified_Left);
1516 if (left_rect_image != std::end(
image_buffers_) && left_rect_image->second->data().frameId ==
header.frameId) {
1517 left_luma_rect = left_rect_image->second;
1520 const auto left_luma_image =
image_buffers_.find(Source_Luma_Left);
1521 if (left_luma_image != std::end(
image_buffers_) && left_luma_image->second->data().frameId ==
header.frameId) {
1522 left_luma = left_luma_image->second;
1525 const auto chroma_image =
image_buffers_.find(Source_Chroma_Left);
1526 if (chroma_image != std::end(
image_buffers_) && chroma_image->second->data().frameId ==
header.frameId) {
1527 left_chroma = chroma_image->second;
1530 const auto aux_luma_rectified_image =
image_buffers_.find(Source_Luma_Rectified_Aux);
1531 if (aux_luma_rectified_image != std::end(
image_buffers_) && aux_luma_rectified_image->second->data().frameId ==
header.frameId) {
1532 aux_luma_rectified = aux_luma_rectified_image->second;
1535 const auto aux_chroma_rectified_image =
image_buffers_.find(Source_Chroma_Rectified_Aux);
1536 if (aux_chroma_rectified_image != std::end(
image_buffers_) && aux_chroma_rectified_image->second->data().frameId ==
header.frameId) {
1537 aux_chroma_rectified = aux_chroma_rectified_image->second;
1548 if (!(pub_pointcloud || pub_color_pointcloud || pub_organized_pointcloud || pub_color_organized_pointcloud))
1560 switch(left_luma_rect->data().bitsPerPixel)
1581 ROS_ERROR(
"Camera: unsupported luma rectified depth for pontcloud conversion: %d", left_luma_rect->data().bitsPerPixel);
1585 if (pub_color_pointcloud)
1596 if (pub_organized_pointcloud)
1598 switch(left_luma_rect->data().bitsPerPixel)
1619 ROS_ERROR(
"Camera: unsupported luma rectified depth for pontcloud conversion: %d", left_luma_rect->data().bitsPerPixel);
1623 if (pub_color_organized_pointcloud)
1634 const Eigen::Vector3f invalid_point(std::numeric_limits<float>::quiet_NaN(),
1635 std::numeric_limits<float>::quiet_NaN(),
1636 std::numeric_limits<float>::quiet_NaN());
1641 cv::Mat rectified_color;
1642 if (!
has_aux_camera_ && (pub_color_pointcloud || pub_color_organized_pointcloud))
1644 const auto &luma = left_luma->data();
1655 cv::remap(rgb_image, rect_rgb_image, left_remap->map1, left_remap->map2, cv::INTER_LINEAR);
1657 rectified_color = std::move(rect_rgb_image);
1659 else if(
has_aux_camera_ && (pub_color_pointcloud || pub_color_organized_pointcloud))
1661 const auto &luma = aux_luma_rectified->data();
1674 (
header.width != luma.width ||
header.height != luma.height))
1676 cv::Mat resized_rect_rgb_image;
1677 cv::resize(rect_rgb_image,
1678 resized_rect_rgb_image,
1679 cv::Size{
static_cast<int>(
header.width),
static_cast<int>(
header.height)},
1680 0, 0, cv::INTER_AREA);
1682 rect_rgb_image = std::move(resized_rect_rgb_image);
1685 rectified_color = std::move(rect_rgb_image);
1691 throw std::runtime_error(
"Stereo calibration manager missing right calibration");
1697 rectified_color.cols, rectified_color.rows);
1702 uint32_t packed_color = 0;
1706 size_t valid_points = 0;
1707 for (
size_t y = 0 ; y <
header.height ; ++y)
1709 for (
size_t x = 0 ; x <
header.width ; ++x)
1711 const size_t index = y *
header.width + x;
1713 float disparity = 0.0f;
1714 switch(
header.bitsPerPixel)
1718 disparity =
static_cast<float>(
reinterpret_cast<const uint16_t*
>(
header.imageDataP)[index]) / 16.0f;
1723 disparity =
static_cast<float>(
reinterpret_cast<const float*
>(
header.imageDataP)[index]);
1728 ROS_ERROR(
"Camera: unsupported disparity detph: %d",
header.bitsPerPixel);
1734 left_camera_info, right_camera_info);
1740 if (!rectified_color.empty())
1747 rectified_color.at<cv::Vec3b>(y, x);
1750 packed_color |= color_pixel[2] << 16 | color_pixel[1] << 8 | color_pixel[0];
1759 if (pub_organized_pointcloud)
1764 if (pub_color_organized_pointcloud)
1774 if (pub_pointcloud && valid)
1776 writePoint(
luma_point_cloud_, valid_points, point, index, left_luma_rect->data().bitsPerPixel, left_luma_rect->data().imageDataP);
1779 if(pub_color_pointcloud && valid)
1784 if (pub_organized_pointcloud)
1789 if (pub_color_organized_pointcloud)
1810 if (pub_color_pointcloud)
1819 if (pub_organized_pointcloud)
1824 if (pub_color_organized_pointcloud)
1837 if(Source_Disparity ==
header.source)
1839 const auto image =
image_buffers_.find(Source_Luma_Rectified_Left);
1842 const auto luma_ptr = image->second;
1843 const auto &left_luma_rect = luma_ptr->data();
1845 const uint32_t left_luma_image_size = left_luma_rect.width * left_luma_rect.height;
1847 raw_cam_data_.gray_scale_image.resize(left_luma_image_size);
1849 left_luma_rect.imageDataP,
1850 left_luma_image_size *
sizeof(uint8_t));
1852 raw_cam_data_.frames_per_second = left_luma_rect.framesPerSecond;
1860 const uint32_t disparity_size =
header.width *
header.height;
1865 disparity_size *
header.bitsPerPixel == 16 ?
sizeof(uint16_t) :
sizeof(uint32_t));
1877 if (Source_Chroma_Left !=
header.source &&
1878 Source_Chroma_Rectified_Aux !=
header.source &&
1879 Source_Chroma_Aux !=
header.source)
1881 ROS_WARN(
"Camera: unexpected color image source: 0x%lx",
header.source);
1889 throw std::runtime_error(
"Uninitialized stereo calibration manager");
1894 case Source_Chroma_Left:
1900 if (color_subscribers == 0 && color_rect_subscribers == 0)
1910 const auto luma_ptr = left_luma->second;
1912 if (
header.frameId == luma_ptr->data().frameId) {
1914 const uint32_t height = luma_ptr->data().height;
1915 const uint32_t width = luma_ptr->data().width;
1916 const uint32_t imageSize = 3 * height * width;
1936 if (color_subscribers != 0) {
1942 if (color_rect_subscribers > 0) {
1949 const cv::Mat rgb_image(height, width, CV_8UC3, &(
left_rgb_image_.data[0]));
1952 cv::remap(rgb_image, rect_rgb_image, remaps->map1, remaps->map2, cv::INTER_LINEAR);
1971 case Source_Chroma_Rectified_Aux:
1977 const auto aux_luma =
image_buffers_.find(Source_Luma_Rectified_Aux);
1982 const auto luma_ptr = aux_luma->second;
1984 if (
header.frameId == luma_ptr->data().frameId) {
1986 const uint32_t height = luma_ptr->data().height;
1987 const uint32_t width = luma_ptr->data().width;
1988 const uint32_t imageSize = 3 * height * width;
2015 case Source_Chroma_Aux:
2026 const auto luma_ptr = aux_luma->second;
2028 if (
header.frameId == luma_ptr->data().frameId) {
2029 const uint32_t height = luma_ptr->data().height;
2030 const uint32_t width = luma_ptr->data().width;
2031 const uint32_t imageSize = 3 * height * width;
2063 if (Source_Luma_Rectified_Aux !=
header.source &&
2064 Source_Chroma_Rectified_Aux !=
header.source &&
2065 Source_Luma_Aux !=
header.source &&
2066 Source_Luma_Left !=
header.source &&
2067 Source_Chroma_Left !=
header.source &&
2068 Source_Luma_Rectified_Left !=
header.source) {
2069 ROS_WARN(
"Camera: unexpected colorized image source: 0x%lx",
header.source);
2078 if (Source_Ground_Surface_Class_Image !=
header.source)
2080 ROS_WARN(
"Camera: unexpected image source: 0x%lx",
header.source);
2088 throw std::runtime_error(
"Uninitialized stereo calibration manager");
2093 case Source_Ground_Surface_Class_Image:
2097 if (ground_surface_subscribers == 0)
2100 const uint32_t height =
header.height;
2101 const uint32_t width =
header.width;
2102 const uint32_t imageSize = 3 * height * width;
2123 const size_t row_offset = y * rgb_stride;
2127 const uint8_t *imageP =
reinterpret_cast<const uint8_t*
>(
header.imageDataP);
2147 if (
header.controlPointsBitsPerPixel != 32)
2149 ROS_WARN(
"Expecting floats for spline control points, got %u bits per pixel instead",
header.controlPointsBitsPerPixel);
2155 ROS_WARN(
"Ground surface modelling failed, consider modifying camera extrinsics and/or algorithm parameters");
2161 throw std::runtime_error(
"Uninitialized stereo calibration manager");
2165 Eigen::Map<const Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> controlGrid(
2166 reinterpret_cast<const float*
>(
header.controlPointsImageDataP),
header.controlPointsHeight,
header.controlPointsWidth);
2171 float minMaxAzimuthAngle[2];
2172 minMaxAzimuthAngle[0] = M_PI_2 - atan(config.cx() / config.fx());
2173 minMaxAzimuthAngle[1] = M_PI_2 + atan((config.width() - config.cx()) / config.fx());
2193 auto time_stamp =
ros::Time(time_secs, 1000 * time_microsecs);
2206 throw std::runtime_error(
"Uninitialized stereo calibration manager");
2214 multisense_ros::RawCamConfig cfg;
2216 cfg.width = config.
width();
2217 cfg.height = config.
height();
2218 cfg.frames_per_second = config.
fps();
2219 cfg.gain = config.
gain();
2220 cfg.exposure_time = config.
exposure();
2222 cfg.fx = config.
fx();
2223 cfg.fy = config.
fy();
2224 cfg.cx = config.
cx();
2225 cfg.cy = config.
cy();
2226 cfg.tx = config.
tx();
2227 cfg.ty = config.
ty();
2228 cfg.tz = config.
tz();
2229 cfg.roll = config.
roll();
2230 cfg.pitch = config.
pitch();
2231 cfg.yaw = config.
yaw();
2250 stat.
add(
"pcb: " + pcb.name, pcb.revision);
2281 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"MultiSense Device Info");
2295 stat.
add(
"imu", statusMessage.
imuOk);
2307 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"MultiSense Status: OK");
2311 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"MultiSense Status: ERROR - Unable to retrieve status");
2322 stat.
add(
"grandmaster_offset_ns", ptpStatusMessage.
gm_offset);
2328 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"PTP Status: OK");
2332 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"PTP Status: Not Synchronized");
2337 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
" PTP Status: ERROR - Unable to retrieve PTP status");
2352 throw std::runtime_error(
"Uninitialized stereo calibration manager");
2438 if (Status_Ok != status)
2439 ROS_ERROR(
"Camera: failed to stop all streams: %s",
2440 Channel::statusString(status));
2449 for(uint32_t i=0; i<32; i++)
2450 if ((1<<i) & enableMask && 0 ==
stream_map_[(1<<i)]++)
2451 notStarted |= (1<<i);
2453 if (0 != notStarted) {
2456 if (Status_Ok != status)
2457 ROS_ERROR(
"Camera: failed to start streams 0x%lx: %s",
2458 notStarted, Channel::statusString(status));
2468 for(uint32_t i=0; i<32; i++)
2469 if ((1<<i) & disableMask && 0 == --
stream_map_[(1<<i)])
2470 notStopped |= (1<<i);
2472 if (0 != notStopped) {
2474 if (Status_Ok != status)
2475 ROS_ERROR(
"Camera: failed to stop streams 0x%lx: %s\n",
2476 notStopped, Channel::statusString(status));