kinect_freq_mod.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
34 #include <stdio.h>
35 #include <ros/ros.h>
36 #include <visualization_msgs/Marker.h>
37 #include <sensor_msgs/LaserScan.h>
38 #include <sensor_msgs/PointCloud2.h>
39 #include <tf/transform_listener.h>
40 #include <pcl_ros/transforms.h>
41 #include <pcl/conversions.h>
42 #include <pcl/point_cloud.h>
43 #include <pcl/point_types.h>
44 #include <pcl/segmentation/extract_polygonal_prism_data.h>
45 #include <pcl/filters/extract_indices.h>
46 #include <pcl/filters/project_inliers.h>
47 #include <pcl/filters/voxel_grid.h>
48 #include <points_from_volume/points_from_volume.h>
49 #define PFLN printf("FILE %s LINE %d\n",__FILE__, __LINE__);
50 
51 // Namespaces
52 using namespace std;
53 
54 // Global vars
56 ros::NodeHandle* p_n;
57 
64 void conversion (const sensor_msgs::PointCloud2ConstPtr & pcmsg_in)
65 {
66  pcl::PointCloud<pcl::PointXYZ> pc_cut;
67  pcl::PointCloud<pcl::PointXYZ> processed_pc;
68  sensor_msgs::PointCloud2 pcmsg_out;
69 
70  pcl::fromROSMsg(*pcmsg_in,pc_cut);
71  pc_cut.header.frame_id=pcmsg_in->header.frame_id;
72 
73  for (int i=0;i<(int)pc_cut.points.size();i++)
74  {
75  if (pc_cut.points[i].z>0.75 && pc_cut.points[i].z<1.5)
76  {
77  processed_pc.push_back(pc_cut.points[i]);
78  }
79  }
80  processed_pc.header.frame_id=pc_cut.header.frame_id;
81  pcl::toROSMsg(processed_pc,pcmsg_out);
82 
83  pcmsg_out.header.stamp=pcmsg_in->header.stamp;
84  cloud_pub.publish(pcmsg_out);
85 }
86 
87 
88 
95 int main(int argc, char **argv)
96 {
97  ros::init(argc, argv, "kinect_freq_mod");
98  ros::NodeHandle n;
99  ros::Rate loop_rate(10);
100  p_n=&n;
101 
102  // Subscribe of the Kinect point cloud message
103  ros::Subscriber sub = n.subscribe ("/point_cloud_from_kinect", 1, conversion);
104 
105  // Advertise of the resutant point cloud
106  cloud_pub = n.advertise<sensor_msgs::PointCloud2>("/point_cloud_input", 1);
107 
108  while(ros::ok())
109  {
110  ros::spinOnce();
111  loop_rate.sleep();
112  }
113  return 0;
114 }
ros::Publisher cloud_pub
ros::NodeHandle * p_n
ros::Publisher Publisher
void conversion(const sensor_msgs::PointCloud2ConstPtr &pcmsg_in)
Point cloud treatment.
int main(int argc, char **argv)
Publish messages at a certain loop rate.


parking_detection
Author(s): Joel Pereira
autogenerated on Mon Mar 2 2015 01:32:31