Hello, I'm trying to publish a pointcloud that contains the narfkeypoints extracted from a range image with the following code:
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/CameraInfo.h>
// PCL specific includes
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/narf.h>
#include <pcl/keypoints/narf_keypoint.h>
#include <pcl/range_image/range_image.h>
#include <pcl/features/range_image_border_extractor.h>
#include <pcl/range_image/range_image_planar.h>
typedef pcl::PointCloud<pcl::PointCloud<int> > PointCloud;
typedef pcl::PointXYZ PointType;
ros::Publisher pub;
pcl::PointCloud<int> keypoint_indices;
pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_ptr (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>& keypoints = *keypoints_ptr;
float angular_resolution_;
float support_size_ =0.2f;//-0.1f
void depthimage_cb(const sensor_msgs::ImageConstPtr &depth_msg)
{
const uint16_t* depthImage = reinterpret_cast<const uint16_t*>(&depth_msg->data[0]);
pcl::RangeImagePlanar range_image_;
pcl::RangeImageBorderExtractor range_image_border_extractor_;
// convert the depth-image to a pcl::rangeImage
angular_resolution_ = (float)(-1);
range_image_.setDepthImage(depthImage,depth_msg->width, depth_msg->height, (depth_msg->width)/2, (depth_msg->height)/2, 600.0, 600.0, angular_resolution_);
range_image_.setUnseenToMaxRange();
pcl::NarfKeypoint keypoint_det;
// extract the indices of the NARF-Keypoints
keypoint_det.getParameters ().support_size = support_size_;
keypoint_det.setRangeImageBorderExtractor (&range_image_border_extractor_);
keypoint_det.setRangeImage (&range_image_);
keypoint_det.compute (keypoint_indices);
keypoints.points.resize (keypoint_indices.points.size ());
for (size_t i=0; i<keypoint_indices.points.size (); ++i)
keypoints.points[i].getVector3fMap () = range_image_.points[keypoint_indices.points[i]].getVector3fMap ();
// pub.publish (keypoints);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "keypointsplanar");
ros::NodeHandle nh1;
ros::NodeHandle nh2;
// Create a ROS subscriber for the input point cloud
ros::Subscriber sub2 = nh1.subscribe ("/camera/depth/image", 1, depthimage_cb);
// Create a ROS publisher for the output point cloud
//pub = nh2.advertise<pcl::PointCloud<pcl::PointXYZ>& keypoints> ("keypoints", 1);
// Spin
ros::spin ();
}
If I comment the pub.publish (keypoints); and the pub = nh2.advertisepcl::PointCloud<pcl::PointXYZ& keypoints> ("keypoints", 1); lines the code compiles with no problems or warnings, however, if I uncomment them I keep getting these errors:
{-------------------------------------------------------------------------------[ rosmake ] [ make ] [ tesis: 11.3 sec ] [ 1 Active 29/30 Complete ]
from /home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:1:
/opt/ros/fuerte/include/ros/message_traits.h: In static member function ‘static const char* ros::message_traits::MD5Sum::value(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’:
/opt/ros/fuerte/include/ros/message_traits.h:255:104: instantiated from ‘const char* ros::message_traits::md5sum(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’
/opt/ros/fuerte/include/ros/publisher.h:112:7: instantiated from ‘void ros::Publisher::publish(const M&) const [with M = pcl::PointCloudpcl::PointXYZ]’
/home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:57:27: instantiated from here
/opt/ros/fuerte/include/ros/message_traits.h:126:34: error: ‘const class pcl::PointCloudpcl::PointXYZ’ has no member named ‘__getMD5Sum’
/opt/ros/fuerte/include/ros/message_traits.h: In static member function ‘static const char* ros::message_traits::DataType::value(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’:
/opt/ros/fuerte/include/ros/message_traits.h:264:106: instantiated from ‘const char* ros::message_traits::datatype(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’
/opt/ros/fuerte/include/ros/publisher.h:112:7: instantiated from ‘void ros::Publisher::publish(const M&) const [with M = pcl::PointCloudpcl::PointXYZ]’
/home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:57:27: instantiated from here
/opt/ros/fuerte/include/ros/message_traits.h:143:36: error: ‘const class pcl::PointCloudpcl::PointXYZ’ has no member named ‘__getDataType’
In file included from /opt/ros/fuerte/include/ros/publisher.h:34:0,
from /opt/ros/fuerte/include/ros/node_handle.h:32,
from /opt/ros/fuerte/include/ros/ros.h:45,
from /home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:1:
/opt/ros/fuerte/include/ros/serialization.h: In static member function ‘static uint32_t ros::serialization::Serializer::serializedLength(typename boost::call_traits::param_type) [with T = pcl::PointCloudpcl::PointXYZ, uint32_t = unsigned int, typename boost::call_traits::param_type = const pcl::PointCloudpcl::PointXYZ&]’:
/opt/ros/fuerte/include/ros/serialization.h:170:43: instantiated from ‘uint32_t ros::serialization::serializationLength(const T&) [with T = pcl::PointCloudpcl::PointXYZ, uint32_t = unsigned int]’
/opt/ros/fuerte/include/ros/serialization.h:805:45: instantiated from ‘ros::SerializedMessage ros::serialization::serializeMessage(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’
/opt/ros/fuerte/include/ros/publisher.h:118:7: instantiated from ‘void ros::Publisher::publish(const M&) const [with M = pcl::PointCloudpcl::PointXYZ]’
/home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:57:27: instantiated from here
/opt/ros/fuerte/include/ros/serialization.h:142:34: error: ‘const class pcl::PointCloudpcl::PointXYZ’ has no member named ‘serializationLength’
/opt/ros/fuerte/include/ros/serialization.h: In static member function ‘static void ros::serialization::Serializer::write(Stream&, typename boost::call_traits::param_type) [with Stream = ros::serialization::OStream, T = pcl::PointCloudpcl::PointXYZ, typename boost::call_traits::param_type = const pcl::PointCloudpcl::PointXYZ&]’:
/opt/ros/fuerte/include/ros/serialization.h:152:3: instantiated from ‘void ros::serialization::serialize(Stream&, const T&) [with T = pcl::PointCloudpcl::PointXYZ, Stream = ros::serialization::OStream]’
/opt/ros/fuerte/include/ros/serialization.h:812:3: instantiated from ‘ros::SerializedMessage ros::serialization::serializeMessage(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’
/opt/ros/fuerte/include/ros/publisher.h:118:7: instantiated from ‘void ros::Publisher::publish(const M&) const [with M = pcl::PointCloudpcl::PointXYZ]’
/home/jumpei/fuerte_workspace/tesis/src/keypointsplanar.cpp:57:27: instantiated from here
/opt/ros/fuerte/include/ros/serialization.h:125:5: error: ‘const class pcl::PointCloudpcl::PointXYZ’ has no member named ‘serialize’
/opt/ros/fuerte/include/ros/message_traits.h: In static member function ‘static const char* ros::message_traits::MD5Sum::value(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’:
/opt/ros/fuerte/include/ros/message_traits.h:127:3: warning: control reaches end of non-void function [-Wreturn-type]
/opt/ros/fuerte/include/ros/message_traits.h: In static member function ‘static const char* ros::message_traits::DataType::value(const M&) [with M = pcl::PointCloudpcl::PointXYZ]’:
/opt/ros/fuerte/include/ros/message_traits.h:144:3: warning: control reaches end of non-void function [-Wreturn-type]
/opt/ros/fuerte/include/ros/serialization.h: In static member function ‘static uint32_t ros::serialization::Serializer::serializedLength(typename boost::call_traits::param_type) [with T = pcl::PointCloudpcl::PointXYZ, uint32_t = unsigned int, typename boost::call_traits::param_type = const pcl::PointCloudpcl::PointXYZ&]’:
/opt/ros/fuerte/include/ros/serialization.h:143:3: warning: control reaches end of non-void function [-Wreturn-type]
make[3]: *** [CMakeFiles/keypointsplanar.dir/src/keypointsplanar.o] Error 1
make[3]: Leaving directory /home/jumpei/fuerte_workspace/tesis/build' make[2]: *** [CMakeFiles/keypointsplanar.dir/all] Error 2 make[2]: Leaving directory
/home/jumpei/fuerte_workspace/tesis/build'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/jumpei/fuerte_workspace/tesis/build'
I have no idea what to make out of these errors
Originally posted by David Bravo on ROS Answers with karma: 1 on 2012-08-17
Post score: 0
Original comments
Comment by jbohren on 2012-08-18:
What versions of ROS and PCL are you using, and what OS are you on?
Comment by David Bravo on 2012-08-20:
Thank you Allenh, I wasn't including pcl_ros/point_cloud.h. Now I feel stupid. I'm using ROS Fuerte and the ros-fuerte-perception-pcl-fuerte-unstable package because I need the NARF keypoints. Now the topic is published but I can't see it in RVIZ because I get a "No message received" error.
Comment by David Bravo on 2012-08-20:
I made another question here: http://answers.ros.org/question/41862/no-message-received-in-rviz/