convert_pcd_to_image.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id: surface_convex_hull.cpp 34612 2010-12-08 01:06:27Z rusu $
35  *
36  */
37 
49 #include <ros/ros.h>
50 #include <sensor_msgs/Image.h>
51 #include <sensor_msgs/PointCloud2.h>
53 
54 /* ---[ */
55 int
56 main (int argc, char **argv)
57 {
58  ros::init (argc, argv, "image_publisher");
59  ros::NodeHandle nh;
60  ros::Publisher image_pub = nh.advertise <sensor_msgs::Image> ("output", 1);
61 
62  if (argc != 2)
63  {
64  std::cout << "usage:\n" << argv[0] << " cloud.pcd" << std::endl;
65  return 1;
66  }
67 
68  sensor_msgs::Image image;
69  sensor_msgs::PointCloud2 cloud;
70  pcl::io::loadPCDFile (std::string (argv[1]), cloud);
71 
72  try
73  {
74  pcl::toROSMsg (cloud, image); //convert the cloud
75  }
76  catch (std::runtime_error &e)
77  {
78  ROS_ERROR_STREAM("Error in converting cloud to image message: "
79  << e.what());
80  return 1; //fail!
81  }
82  ros::Rate loop_rate (5);
83  while (nh.ok ())
84  {
85  image_pub.publish (image);
86  ros::spinOnce ();
87  loop_rate.sleep ();
88  }
89 
90  return (0);
91 }
92 
93 /* ]--- */
ros::Publisher
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::spinOnce
ROSCPP_DECL void spinOnce()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
main
int main(int argc, char **argv)
Definition: convert_pcd_to_image.cpp:56
pcl::io::loadPCDFile
int loadPCDFile(const std::string &file_name, sensor_msgs::PointCloud2 &cloud)
ros::Rate::sleep
bool sleep()
ros::NodeHandle::ok
bool ok() const
pcl::toROSMsg
void toROSMsg(const pcl::PointCloud< T > &cloud, sensor_msgs::Image &msg)
ros::Rate
ros::NodeHandle
pcl_conversions.h


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Fri Jul 12 2024 02:54:40