【发布时间】:2016-12-23 03:14:36
【问题描述】:
我正在尝试在 RViz 中发送不同颜色的标记,以便我可以看到我的程序是否在相应地工作。我现在只能发送对象点的坐标值。我的问题是我无法为这些点设置颜色。这是我的代码:
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <visualization_msgs/Marker.h>
#include "std_msgs/String.h"
#include "std_msgs/Float32.h"
#include "std_msgs/Int32.h"
#include "rosbag/bag.h"
#include <rosbag/view.h>
#include <vector>
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
ros::Publisher pub;
ros::Publisher marker_pub;
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
pcl::PointCloud<pcl::PointXYZRGB> output;
pcl::fromROSMsg(*input,output);
visualization_msgs::Marker points;
points.header.frame_id = "/camera_link";
points.header.stamp = ros::Time::now();
points.ns = "lines";
points.action = visualization_msgs::Marker::ADD;
points.pose.orientation.w = 1.0;
points.type = visualization_msgs::Marker::POINTS;
points.scale.x = 0.003;
points.scale.y = 0.003;
points.id = 0;
points.color.r=1; points.color.a=1;
geometry_msgs::Point p;
for(int i=0;i<ac1.size();i++) {
if(i%10==0 && !isnan(ac1.at(i)) && !isnan(bc1.at(i)) && !isnan(cc1.at(i)) && cc1.at(i)!=0) {
points.id=i; points.color.r=xc.at(i)/255; points.color.g=yc.at(i)/255; points.color.b=zc.at(i)/255;
p.x=ac1.at(i); p.y=bc1.at(i); p.z=cc1.at(i); points.points.push_back(p);
marker_pub.publish(points); }
}
cout<<"finish"<<endl;
}
int
main(int argc, char** argv)
{
ROS_INFO("main");
ros::init(argc, argv,"obj_rec");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe ("/camera/depth/points", 1, cloud_cb);
pub = nh.advertise<sensor_msgs::PointCloud2>("output",1);
marker_pub = nh.advertise<visualization_msgs::Marker> ("out",1);
ros::spin();
}
这里ac1、bc1和cc1向量包含对象的坐标,xc、yc和zc向量包含对应点的RGB值。我没有放完整的代码,因为它太长了,运行这个单一的 ROS 节点需要其他 C++ 程序。
【问题讨论】:
-
如果您想直接发布彩色点云,请使用示例代码查看此答案stackoverflow.com/a/39128333/1563315
标签: ros