ROS_interface_helper_functions.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2010, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 
00028 #  \author Martin Schuster (Healthcare Robotics Lab, Georgia Tech.)
00029 
00030 from laser_camera_segmentation.srv._Segmentation import *
00031 import sensor_msgs
00032 
00033 import numpy as np
00034 
00035 import opencv as cv
00036 import hrl_lib.util as ut
00037 import opencv.highgui as highgui
00038 
00039 from labeling.label_object import label_object
00040 
00041 def convert_pointcloud_to_ROS(pts3d, intensities = None, labels = None):
00042     ROS_pointcloud = sensor_msgs.msg.PointCloud()
00043     ROS_pointcloud.points = []
00044     for point in np.asarray(pts3d.T):
00045         ROS_pointcloud.points += [geometry_msgs.msg.Point32(point[0],point[1],point[2])]
00046         
00047     intensity_channel = sensor_msgs.msg.ChannelFloat32()
00048     intensity_channel.name = 'intensities'
00049     if intensities != None:
00050         for value in intensities:
00051             intensity_channel.values += [value]
00052         
00053     label_channel = sensor_msgs.msg.ChannelFloat32()   
00054     label_channel.name = 'labels' 
00055     if labels != None:
00056         for value in labels:
00057             label_channel.values += [value]    
00058     
00059     
00060     ROS_pointcloud.channels = [intensity_channel, label_channel]
00061     return ROS_pointcloud
00062 
00063 def convert_ROS_pointcloud_to_pointcloud(ROS_pointcloud):
00064     intensities = []
00065     labels = []
00066     pts3d = []
00067     for point in ROS_pointcloud.points:
00068         pts3d += [[point.x, point.y, point.z]]
00069     pts3d = np.array(pts3d).T
00070     #print pts3d
00071     
00072     for value in ROS_pointcloud.channels[0].values:
00073         intensities += [value]
00074     intensities = np.array(intensities)  
00075     
00076     for value in ROS_pointcloud.channels[1].values:
00077         labels += [value]
00078     labels = np.array(labels)  
00079     
00080     return pts3d, intensities, labels
00081 
00082 
00083 def convert_cvimage_to_ROS(image):
00084     imgTmp = cv.cvCloneImage(image)
00085     imNP = ut.cv2np(imgTmp,format='BGR')
00086     ROS_image = np.reshape(imNP,(1,-1))[0]
00087 
00088     return ROS_image
00089 
00090 def convert_ROS_image_to_cvimage(ROS_image, width, height):
00091     ROS_image = np.array(ROS_image, dtype='uint8')
00092     imNP = np.reshape(ROS_image,(height,width, 3))
00093     cvimage = ut.np2cv(imNP)
00094 
00095     return cvimage
00096 
00097 
00098 #convert label_object to ROS geometry_msgs.msg.Polygon
00099 def convert_polygon_to_ROS(polygon):
00100     ROS_polygon = geometry_msgs.msg.Polygon()
00101     ROS_polygon.points = []
00102     for point in polygon.get_points():
00103         ROS_polygon.points += [geometry_msgs.msg.Point32(point[0], point[1], 0.)]
00104     return ROS_polygon
00105 
00106 
00107 def convert_ROS_polygon_to_polygon(ROS_polygon):
00108     polygon = label_object() 
00109     for point in ROS_polygon.points:
00110         polygon.add_point((point.x,point.y))
00111     return polygon


laser_camera_segmentation
Author(s): Martin Schuster, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:56:44