Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
00054
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
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()