3 #include <sensor_msgs/Image.h>
6 #include <sensor_msgs/CameraInfo.h>
24 bool isPublisherValid(
const T &publisher)
26 return (
void *)publisher == (
void *)1;
31 bool optionalParam(
const ros::NodeHandle &nh,
const std::string &key, boost::optional<T> &value)
51 value.
set(default_value);
61 bool optionalLiveParam(
const ros::NodeHandle &nh,
const std::string &key, boost::optional<
Parameter<T>> &value,
const T &default_value)
67 if (value) value->
set(default_value);
72 if (value) value->
set(raw);
86 , image_transport_(device_nh_)
87 , mut_(
std::make_unique<
boost::recursive_mutex>())
89 , publish_body_markers(false)
90 , publish_body_mask(true)
91 , publish_floor_mask(true)
92 , body_frame_id(
"/camera")
111 DeviceConfig dyn_config;
112 dyn_config.color_stream_running = color_stream && color_stream->running.get();
113 dyn_config.color_stream_mirrored = color_stream && color_stream->mirrored && color_stream->mirrored->get();
115 dyn_config.ir_stream_running = ir_stream && ir_stream->running.get();
116 dyn_config.ir_stream_mirrored = ir_stream && ir_stream->mirrored && ir_stream->mirrored->get();
118 dyn_config.depth_stream_running = depth_stream && depth_stream->running.get();
119 dyn_config.depth_stream_mirrored = depth_stream && depth_stream->mirrored && depth_stream->mirrored->get();
135 if (color_stream->mirrored)
152 if (ir_stream->mirrored)
158 if (ir_stream->exposure)
188 if (depth_stream->mirrored)
210 using namespace std::string_literals;
215 optionalParam(nh,
"uri", config.
uri);
223 liveParam(color_nh,
"running", color_stream.
running,
true);
224 optionalLiveParam(color_nh,
"mirrored", color_stream.
mirrored,
false);
235 liveParam(ir_nh,
"running", ir_stream.
running,
true);
236 optionalLiveParam(ir_nh,
"mirrored", ir_stream.
mirrored,
false);
247 liveParam(depth_nh,
"running", depth_stream.
running,
true);
248 optionalLiveParam(depth_nh,
"mirrored", depth_stream.
mirrored,
false);
250 optionalLiveParam(depth_nh,
"d2c_mode", depth_stream.
d2c_mode, 0);
251 optionalLiveParam(depth_nh,
"registration", depth_stream.
registration,
true);
262 liveParam(body_nh,
"running", body_stream.
running,
true);
263 optionalParam(body_nh,
"license", body_stream.
license);
274 liveParam(colorized_body_nh,
"running", colorized_body_stream.
running,
true);
285 liveParam(hand_nh,
"running", hand_stream.
running,
true);
296 liveParam(masked_color_nh,
"running", masked_color_stream.
running,
true);
307 liveParam(point_nh,
"running", point_stream.
running,
true);
320 boost::optional<sensor_msgs::Image> color_image;
321 boost::optional<sensor_msgs::Image> depth_image;
322 boost::optional<sensor_msgs::CameraInfo> color_camera_info;
342 sensor_msgs::CameraInfo camera_info;
343 camera_info.header.stamp = now;
345 camera_info.height = frame.
color->metadata.height;
346 camera_info.width = frame.
color->metadata.width;
347 camera_info.distortion_model =
"plumb_bob";
349 camera_info.D.resize(5, 0.0);
361 camera_info.K[8] = 1.0;
363 color_camera_info = camera_info;
405 sensor_msgs::CameraInfo camera_info;
406 camera_info.header.stamp = now;
408 camera_info.height = frame.
depth->metadata.height;
409 camera_info.width = frame.
depth->metadata.width;
412 camera_info.D.resize(5, 0.0);
423 camera_info.K[8] = 1.0;
482 BodyFrame body_frame;
484 body_frame.floor_detected = frame.
body->floor_info->floorDetected;
485 body_frame.floor_plane =
toRos(frame.
body->floor_info->floorPlane);
487 if (depth_image && color_image && color_camera_info)
489 const auto &body_mask = frame.
body->body_mask;
491 for (
auto &body : body_frame.bodies)
493 const std::uint8_t
id = body.id;
494 body.point_cloud =
toPointCloud(*color_image, *depth_image, *color_camera_info, [&] (
const std::size_t x,
const std::size_t y) ->
bool {
495 return x < body_mask.width && y < body_mask.height && body_mask.data[y * body_mask.width + x] == id;
513 std::vector<geometry_msgs::TransformStamped> transforms;
514 for (
const auto &body : body_frame.bodies)
555 if (depth_image && color_image && color_camera_info)
563 auto point_cloud =
toPointCloud(*color_image, *depth_image, *color_camera_info);
564 point_cloud.header.stamp = now;
578 auto &color_stream =
device_->getConfiguration().color_stream;
581 color_stream->running.set(config.color_stream_running);
583 if (color_stream->mirrored)
585 color_stream->mirrored->set(config.color_stream_mirrored);
589 auto &ir_stream =
device_->getConfiguration().ir_stream;
592 ir_stream->running.set(config.ir_stream_running);
594 if (ir_stream->mirrored)
596 ir_stream->mirrored->set(config.ir_stream_mirrored);
599 if (ir_stream->exposure)
601 ir_stream->exposure->set(config.ir_exposure);
605 auto &depth_stream =
device_->getConfiguration().depth_stream;
608 depth_stream->running.set(config.depth_stream_running);
610 if (depth_stream->mirrored)
612 depth_stream->mirrored->set(config.depth_stream_mirrored);
619 const auto chip_id =
device_->getChipId();
620 if (!chip_id)
return false;
621 res.chip_id = *chip_id;
627 const auto &depth_stream =
device_->getConfiguration().depth_stream;
628 if (!depth_stream)
return false;
630 const auto ®istration = depth_stream->registration;
631 if (!registration)
return false;
633 res.registration = **registration;
640 const auto &color_stream =
device_->getConfiguration().color_stream;
641 if (!color_stream)
return false;
643 const auto &mode = color_stream->mode;
644 if (!mode)
return false;
646 res.image_stream_mode =
toRos(**mode);
653 const auto &depth_stream =
device_->getConfiguration().depth_stream;
654 if (!depth_stream)
return false;
656 const auto &mode = depth_stream->mode;
657 if (!mode)
return false;
659 res.image_stream_mode =
toRos(**mode);
666 const auto &ir_stream =
device_->getConfiguration().ir_stream;
667 if (!ir_stream)
return false;
669 const auto &mode = ir_stream->mode;
670 if (!mode)
return false;
672 res.image_stream_mode =
toRos(**mode);
680 const auto image_stream_modes =
device_->getColorImageStreamModes();
681 if (!image_stream_modes)
return false;
683 res.image_stream_modes.reserve(image_stream_modes->size());
684 for (
const auto &image_stream_mode : *image_stream_modes)
686 res.image_stream_modes.push_back(
toRos(image_stream_mode));
694 const auto image_stream_modes =
device_->getDepthImageStreamModes();
695 if (!image_stream_modes)
return false;
697 res.image_stream_modes.reserve(image_stream_modes->size());
698 for (
const auto &image_stream_mode : *image_stream_modes)
700 res.image_stream_modes.push_back(
toRos(image_stream_mode));
708 const auto image_stream_modes =
device_->getIrImageStreamModes();
709 if (!image_stream_modes)
return false;
711 res.image_stream_modes.reserve(image_stream_modes->size());
712 for (
const auto &image_stream_mode : *image_stream_modes)
714 res.image_stream_modes.push_back(
toRos(image_stream_mode));
722 const auto &ir_stream =
device_->getConfiguration().ir_stream;
723 if (!ir_stream)
return false;
725 const auto &exposure = ir_stream->exposure;
726 if (!exposure)
return false;
728 res.exposure = **exposure;
735 const auto &ir_stream =
device_->getConfiguration().ir_stream;
736 if (!ir_stream)
return false;
738 const auto &gain = ir_stream->gain;
739 if (!gain)
return false;
748 const auto &color_stream =
device_->getConfiguration().color_stream;
749 if (!color_stream)
return false;
751 const auto &mirrored = color_stream->mirrored;
752 if (!mirrored)
return false;
754 res.mirrored = **mirrored;
761 const auto &depth_stream =
device_->getConfiguration().depth_stream;
762 if (!depth_stream)
return false;
764 const auto &mirrored = depth_stream->mirrored;
765 if (!mirrored)
return false;
767 res.mirrored = **mirrored;
774 const auto &ir_stream =
device_->getConfiguration().ir_stream;
775 if (!ir_stream)
return false;
777 const auto &mirrored = ir_stream->mirrored;
778 if (!mirrored)
return false;
780 res.mirrored = **mirrored;
787 const auto &color_stream =
device_->getConfiguration().color_stream;
788 if (!color_stream)
return false;
790 res.running = *color_stream->running;
796 const auto &depth_stream =
device_->getConfiguration().depth_stream;
797 if (!depth_stream)
return false;
799 res.running = *depth_stream->running;
805 const auto &ir_stream =
device_->getConfiguration().ir_stream;
806 if (!ir_stream)
return false;
808 res.running = *ir_stream->running;
814 const auto serial_number =
device_->getSerialNumber();
815 if (!serial_number)
return false;
816 res.serial = *serial_number;
822 const auto usb_info =
device_->getColorUsbInfo();
823 if (!usb_info)
return false;
824 res.usb_info.pid = usb_info->pid;
825 res.usb_info.vid = usb_info->vid;
831 const auto usb_info =
device_->getDepthUsbInfo();
832 if (!usb_info)
return false;
833 res.usb_info.pid = usb_info->pid;
834 res.usb_info.vid = usb_info->vid;
840 const auto usb_info =
device_->getIrUsbInfo();
841 if (!usb_info)
return false;
842 res.usb_info.pid = usb_info->pid;
843 res.usb_info.vid = usb_info->vid;
849 auto &depth_stream =
device_->getConfiguration().depth_stream;
850 if (!depth_stream)
return false;
852 auto ®istration = depth_stream->registration;
853 if (!registration)
return false;
855 registration->set(req.registration);
863 auto &color_stream =
device_->getConfiguration().color_stream;
864 if (!color_stream)
return false;
866 auto &mode = color_stream->mode;
867 if (!mode)
return false;
869 mode->set(
fromRos(req.image_stream_mode));
876 auto &depth_stream =
device_->getConfiguration().depth_stream;
877 if (!depth_stream)
return false;
879 auto &mode = depth_stream->mode;
880 if (!mode)
return false;
882 mode->set(
fromRos(req.image_stream_mode));
889 auto &ir_stream =
device_->getConfiguration().ir_stream;
890 if (!ir_stream)
return false;
892 auto &mode = ir_stream->mode;
893 if (!mode)
return false;
895 mode->set(
fromRos(req.image_stream_mode));
902 auto &ir_stream =
device_->getConfiguration().ir_stream;
903 if (!ir_stream)
return false;
905 auto &exposure = ir_stream->exposure;
906 if (!exposure)
return false;
908 return exposure->set(req.exposure);
913 auto &ir_stream =
device_->getConfiguration().ir_stream;
914 if (!ir_stream)
return false;
916 auto &gain = ir_stream->gain;
917 if (!gain)
return false;
919 return gain->set(req.gain);
924 auto &color_stream =
device_->getConfiguration().color_stream;
925 if (!color_stream)
return false;
927 auto &mirrored = color_stream->mirrored;
928 if (!mirrored)
return false;
930 return mirrored->set(req.mirrored);
935 auto &depth_stream =
device_->getConfiguration().depth_stream;
936 if (!depth_stream)
return false;
938 auto &mirrored = depth_stream->mirrored;
939 if (!mirrored)
return false;
941 return mirrored->set(req.mirrored);
946 auto &ir_stream =
device_->getConfiguration().ir_stream;
947 if (!ir_stream)
return false;
949 auto &mirrored = ir_stream->mirrored;
950 if (!mirrored)
return false;
952 return mirrored->set(req.mirrored);
957 auto &color_stream =
device_->getConfiguration().color_stream;
958 if (!color_stream)
return false;
960 return color_stream->running.set(req.running);
965 auto &depth_stream =
device_->getConfiguration().depth_stream;
966 if (!depth_stream)
return false;
968 return depth_stream->running.set(req.running);
973 auto &ir_stream =
device_->getConfiguration().ir_stream;
974 if (!ir_stream)
return false;
976 return ir_stream->running.set(req.running);