8 #include <image_transport/image_transport.h> 9 #include <pluginlib/class_list_macros.h> 10 #include <sensor_msgs/Image.h> 11 #include <cv_bridge/cv_bridge.h> 12 #include <opencv2/imgproc/imgproc.hpp> 13 #include <sensor_msgs/point_cloud2_iterator.h> 14 #include <opencv2/core/ocl.hpp> 15 #include <ros/package.h> 26 NODELET_DEBUG(
"Initializing pointcloud XYZ nodelet...");
28 ros::NodeHandle& private_nh = getPrivateNodeHandle();
29 ros::NodeHandle& nh = getNodeHandle();
33 it_.reset(
new image_transport::ImageTransport(nh));
38 private_nh.param<std::string>(
"tf_frame",
tf_frame_,
"kinect2_link");
40 ros::package::getPath(
"pses_kinect_utilities") +
41 "/ocl_kernel/ocl_kernel.cl");
44 ros::SubscriberStatusCallback connect_cb =
56 NODELET_INFO(
"Stopping conversion from depth image to XYZ pointcloud...");
61 NODELET_INFO(
"Running conversion from depth image to XYZ pointcloud...");
62 image_transport::TransportHints hints(
"raw", ros::TransportHints(),
63 getPrivateNodeHandle());
70 const sensor_msgs::ImageConstPtr& depth_msg,
71 const sensor_msgs::CameraInfoConstPtr& info_msg)
73 cv_bridge::CvImagePtr cv_ptr;
77 cv_ptr = cv_bridge::toCvCopy(*depth_msg, depth_msg->encoding);
79 catch (cv_bridge::Exception& e)
81 NODELET_ERROR(
"cv_bridge exception: %s", e.what());
85 if (cv::ocl::haveOpenCL())
94 md.
width = (cl_uint)depth_msg->width;
95 md.
height = (cl_uint)depth_msg->height;
96 md.
n_pixels = (cl_uint)depth_msg->width * depth_msg->height;
100 md.
NaN = std::numeric_limits<float>::quiet_NaN();
117 catch (std::exception& e)
119 NODELET_ERROR_STREAM(
"An error occured during OCL setup! " << e.what());
128 pc->is_dense =
false;
129 pc->height = depth_msg->height;
130 pc->width = depth_msg->width;
134 catch (std::exception& e)
136 NODELET_ERROR_STREAM(
"An error occured during depth to pcl conversion! " 144 NODELET_ERROR(
"GPU has no OpenCL support!");
PointCloudMsg::Ptr current_cloud_
image_geometry::PinholeCameraModel camera_model_
boost::mutex connect_mutex_
Class of the PointCloudXYZNodelet nodelet, which converts a depth image into a point cloud containing...
virtual void onInit()
This function is called by the initialization of the nodelet and acts as a constructor.
image_transport::CameraSubscriber sub_depth_
void depthCb(const sensor_msgs::ImageConstPtr &depth_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
Callback function that is called whenever a new depth image is received.
DepthConvPtr pcl_conversion_
Class that make the implementation of the PointCloudXYZNodelet nodelet cleaner.
std::string cl_file_path_
PointCloud::Ptr PointCloudPtr
Shortcut for a pointer of a XYZ Point cloud of the pcl library.
ros::Publisher pub_cloud_
void connectCb()
Callback function that is called whenever anyone is subscribed to the output point cloud...
boost::shared_ptr< image_transport::ImageTransport > it_
sensor_msgs::PointCloud2 PointCloudMsg
Shortcut for a PointCloud2 ROS message.
This namespace is used by the nodelets inside our package pses_kinect_utilities.
pcl::PointCloud< pcl::PointXYZ > PointCloud
Shortcut for a XYZ Point cloud of the pcl library.
PLUGINLIB_EXPORT_CLASS(pses_kinect_utilities::PointCloudXYZNodelet, nodelet::Nodelet)