ROS_segmentation_server.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright (c) 2010, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 
00029 #  \author Martin Schuster (Healthcare Robotics Lab, Georgia Tech.)
00030 
00031 import roslib; roslib.load_manifest('laser_camera_segmentation')
00032 
00033 import rospy
00034 
00035 from laser_camera_segmentation.srv._Segmentation import *
00036 import sensor_msgs
00037 
00038 from laser_camera_segmentation.ROS_interface_helper_functions import *
00039 
00040 import laser_camera_segmentation.processor as processor
00041 import laser_camera_segmentation.configuration as configuration
00042 
00043 from labeling.scan_dataset import scan_dataset
00044 
00045 def segment_pointcloud(request):
00046     #convert data from ROS
00047     pts3d, intensities, labels = convert_ROS_pointcloud_to_pointcloud(request.pointcloud)
00048     cvimage = convert_ROS_image_to_cvimage(request.image, request.imageWidth, request.imageHeight)
00049     polygon = convert_ROS_polygon_to_polygon(request.regionOfInterest2D)
00050     polygon.set_label('surface')
00051     print polygon, polygon.get_points()
00052     
00053     #create processor and configuration
00054     #cfg = configuration.configuration('/home/martin/robot1_data/usr/martin/ROS_server_test', 'codyRobot')
00055     cfg = configuration.configuration('../data/ROS_server', 'dummyScanner')
00056     pc = processor.processor(cfg)
00057     
00058     pc.scan_dataset = scan_dataset()
00059     pc.scan_dataset.image_artag_filename = ''
00060     pc.scan_dataset.table_plane_translation = np.matrix([0,0,0]).T
00061 
00062     pc.scan_dataset.ground_plane_translation = np.matrix([0,0,request.laserHeightAboveGround]).T 
00063     pc.scan_dataset.ground_plane_rotation = ''
00064     #pc.scan_dataset.is_test_set = True
00065     pc.scan_dataset.is_labeled = True
00066     pc.scan_dataset.id = 'ROStest'
00067     
00068     pc.img = cvimage
00069     pc.image_angle = request.imageAngle
00070     pc.pts3d = pts3d
00071     pc.intensities = intensities
00072     pc.scan_indices = np.zeros(len(intensities))
00073     
00074     pc.scan_dataset.polygons.append(polygon)
00075     pc.do_all_point_cloud()
00076     pc.do_polygon_mapping()
00077     
00078     pc.scan_dataset.ground_plane_normal = np.matrix([0.,0.,1.]).T
00079     
00080     if request.numberOfPointsToClassify == -1:
00081         n = 999999999999
00082     else:
00083         n = request.numberOfPointsToClassify
00084     feature_data = pc.generate_features(n, False, True)
00085     labels, testresults = pc.load_classifier_and_test_on_dataset('all_post', feature_data)
00086 
00087     response = SegmentationResponse()
00088     response.pointcloud = convert_pointcloud_to_ROS(pc.pts3d_bound, pc.intensities_bound, labels)
00089     return response
00090 
00091 
00092 def segmentation_server():
00093     rospy.init_node('segmentation_server')
00094     s = rospy.Service('segment_pointcloud', Segmentation, segment_pointcloud)
00095     print "Ready to segment pointclouds!"
00096     rospy.spin()
00097 
00098 if __name__ == "__main__":
00099     segmentation_server()


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