Go to the documentation of this file.00001 #include <iostream>
00002 #include "ros/ros.h"
00003 #include "pcl_ros/io/bag_io.h"
00004 #include "pcl/point_types.h"
00005 #include "pcl/io/pcd_io.h"
00006 #include <pcl/features/normal_3d.h>
00007 #include <pcl/ros/conversions.h>
00008 #include <sensor_msgs/Image.h>
00009 #include <pcl/features/integral_image_normal.h>
00010
00011 using pcl::PointCloud;
00012 using pcl::PointXYZRGB;
00013 using pcl::Normal;
00014 using pcl::PointXYZRGBNormal;
00015 using pcl::NormalEstimation;
00016 using pcl::KdTreeFLANN;
00017
00018
00019
00020 class normals_computer
00021 {
00022 ros::Publisher pub;
00023 ros::Publisher pub2;
00024 ros::NodeHandle *nh;
00025
00026 ros::Subscriber sub;
00027 sensor_msgs::Image ima;
00028
00029
00030 pcl::IntegralImageNormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne;
00031
00032 PointCloud<PointXYZRGBNormal> cloud_normals;
00033 PointCloud<Normal> normals;
00034
00035 public:
00036 normals_computer(ros::NodeHandle *nn):nh(nn){
00037 sub = nh->subscribe("/get_normals/input_pointcloud", 1, &normals_computer::normals_callback, this);
00038 pub = nh->advertise<sensor_msgs::PointCloud2>("/camera/rgb/points/normals", 1);
00039 pub2 = nh->advertise<sensor_msgs::Image>("/camera/gray/image", 1);
00040 cloud_normals=PointCloud<PointXYZRGBNormal> ();
00041 cloud_normals.header.frame_id = std::string ("/myframe");
00042 ima = sensor_msgs::Image();
00043 ima.header.frame_id = std::string ("/myframe");
00044 ima.width = 640;
00045 ima.height = 480;
00046 ima.data.resize(ima.width*ima.height);
00047 ima.encoding="8UC1";
00048 ROS_INFO("Normals computer node started");
00049 }
00050
00051 ~normals_computer(){}
00052
00053 void normals_callback(const sensor_msgs::PointCloud2ConstPtr& msg){
00054
00055 ROS_INFO("callback!");
00056
00057
00058 PointCloud<PointXYZRGB>::Ptr cloud (new PointCloud<PointXYZRGB> ());
00059
00060 pcl::fromROSMsg(*msg, *cloud);
00061 ne.setInputCloud (boost::make_shared<PointCloud<PointXYZRGB> > (*cloud));
00062
00063
00064
00065 ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);
00066 ne.setMaxDepthChangeFactor(0.02f);
00067 ne.setNormalSmoothingSize(10.0f);
00068 ne.compute (normals);
00069 std::cout<<normals.width<<std::endl;
00070 pcl::concatenateFields (*cloud, normals, cloud_normals);
00071 cloud_normals.header.stamp=msg->header.stamp;
00072
00073 pcl::PointCloud<pcl::PointXYZRGB>::iterator pt_iter = cloud->begin ();
00074 if(cloud->width!=ima.width || cloud->height!=ima.width){
00075 ima.width = cloud->width;
00076 ima.height = cloud->height;
00077 ima.data.resize(ima.width*ima.height);
00078 }
00079 ima.header.stamp=msg->header.stamp;
00080 for(uint i=0; i<cloud->width*cloud->height; i++, pt_iter++){
00081 int red = (*reinterpret_cast<int*>(&(pt_iter->rgb)) & 0xff0000) >> 16;
00082 int green = (*reinterpret_cast<int*>(&(pt_iter->rgb)) & 0xff00) >> 8;
00083 int blue = *reinterpret_cast<int*>(&(pt_iter->rgb)) & 0xff;
00084 ima.data[i]= (uint8_t) ((float)red*0.30+(float)green*0.59+(float)blue*0.11);
00085 }
00086
00087 pub2.publish(ima);
00088 pub.publish(cloud_normals);
00089 }
00090
00091 };
00092
00093
00094 int
00095 main (int argc, char** argv)
00096 {
00097 ros::init(argc, argv, "get_normals");
00098 ros::NodeHandle n;
00099 normals_computer nc(&n);
00100 ros::spin();
00101
00102 return 0;
00103 }
00104
00105
00106
00107