7 #include <sensor_msgs/Image.h> 21 PointCloud::ConstPtr
const& pointCloud)
23 auto texturedPointCloud = boost::make_shared<TexturedPointCloud>();
25 if (static_cast<int>(pointCloud->width) != image.cols ||
static_cast<int>(pointCloud->height) != image.rows)
27 ROS_ERROR(
"The point cloud does not have the same format as the rectified " 29 return texturedPointCloud;
32 texturedPointCloud->header.frame_id = pointCloud->header.frame_id;
33 texturedPointCloud->header.stamp = pointCloud->header.stamp;
35 texturedPointCloud->is_dense = pointCloud->is_dense;
36 texturedPointCloud->width = pointCloud->width;
37 texturedPointCloud->height = pointCloud->height;
38 texturedPointCloud->points.resize(texturedPointCloud->width * texturedPointCloud->height);
40 for (
size_t x = 0;
x < pointCloud->width;
x++)
42 for (
size_t y = 0;
y < pointCloud->height;
y++)
44 auto& point = texturedPointCloud->at(
x,
y);
46 point.x = pointCloud->at(
x,
y).x;
47 point.y = pointCloud->at(
x,
y).y;
48 point.z = pointCloud->at(
x,
y).z;
50 if (image.channels() == 3)
52 cv::Vec3b color = image.at<cv::Vec3b>(
y,
x);
53 point.b = color.val[0];
54 point.g = color.val[1];
55 point.r = color.val[2];
59 uchar color = image.at<uchar>(
y,
x);
67 return texturedPointCloud;
98 std::lock_guard<std::mutex> lock(mutex);
105 std::lock_guard<std::mutex> lock(mutex);
107 latestPointCloud = pointCloud;
113 if (!latestImage.get() || !latestPointCloud.get())
123 ROS_ERROR(
"cv_bridge exception: %s", e.what());
126 TexturedPointCloud::Ptr texturedPointCloud;
129 texturedPointCloudPublisher.
publish(texturedPointCloud);
133 int main(
int argc,
char** argv)
135 ros::init(argc, argv,
"texture_point_cloud");
sensor_msgs::ImageConstPtr latestImage
PointCloud::ConstPtr latestPointCloud
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
image_transport::Subscriber imageSubscriber
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
sensor_msgs::PointCloud2 PointCloud
TFSIMD_FORCE_INLINE const tfScalar & y() const
geometry_msgs::TransformStamped t
ros::Subscriber pointCloudSubscriber
ROSCPP_DECL void spin(Spinner &spinner)
void onImageReceived(sensor_msgs::ImageConstPtr const &image)
pcl::PointCloud< pcl::PointXYZRGB > TexturedPointCloud
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void onPointCloudReceived(PointCloud::ConstPtr const &pointCloud)
TexturedPointCloud::Ptr texturePointCloudFromRectifiedImage(cv::Mat const &image, PointCloud::ConstPtr const &pointCloud)
ros::NodeHandle nodeHandle
ros::Publisher texturedPointCloudPublisher