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 /* ]--- */
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void publish(const boost::shared_ptr< M > &message) const
int loadPCDFile(const std::string &file_name, sensor_msgs::PointCloud2 &cloud)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
int main(int argc, char **argv)
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
bool ok() const


pcl_ros
Author(s): Open Perception, Julius Kammerl , William Woodall
autogenerated on Thu Feb 16 2023 03:08:02