differencing_node.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import numpy as np, math
00004 import scipy.ndimage as ni
00005 
00006 import roslib; roslib.load_manifest('point_cloud_ros')
00007 import rospy
00008 
00009 import hrl_lib.util as ut
00010 import point_cloud_ros.occupancy_grid as pog
00011 import point_cloud_ros.ros_occupancy_grid as rog
00012 
00013 from point_cloud_ros.msg import OccupancyGrid
00014 
00015 
00016 def og_cb(og_msg, param_list):
00017     global occupancy_difference_threshold, connected_comonents_size_threshold
00018     rospy.loginfo('og_cb called')
00019     diff_og = param_list[0]
00020     curr_og = rog.og_msg_to_og3d(og_msg, to_binary = False)
00021 
00022     if diff_og == None:
00023         param_list[0] = curr_og
00024         return
00025 
00026     pog.subtract(diff_og, curr_og)
00027     param_list[0] = curr_og
00028 
00029     diff_og.to_binary(occupancy_difference_threshold)
00030     # filter the noise
00031     connect_structure = np.zeros((3,3,3), dtype=int)
00032     connect_structure[1,1,:] = 1
00033 #    connect_structure[1,1,0] = 0
00034     diff_og.grid = ni.binary_opening(diff_og.grid, connect_structure,
00035                                      iterations = 1)
00036     #    diff_og.grid, n_labels = diff_og.connected_comonents(connected_comonents_size_threshold)
00037 
00038     print 'np.all(diff_og == 0)', np.all(diff_og.grid == 0)
00039     diff_og_msg = rog.og3d_to_og_msg(diff_og)
00040     diff_og_msg.header.frame_id = og_msg.header.frame_id
00041     diff_og_msg.header.stamp = og_msg.header.stamp
00042     param_list[1].publish(diff_og_msg)
00043 
00044 
00045 #------ arbitrarily set paramters -------
00046 occupancy_difference_threshold = 5
00047 connected_comonents_size_threshold = 10
00048 
00049 if __name__ == '__main__':
00050     rospy.init_node('pc_difference_node')
00051 
00052     pub = rospy.Publisher('difference_occupancy_grid', OccupancyGrid)
00053     param_list = [None, pub]
00054     rospy.Subscriber('occupancy_grid', OccupancyGrid, og_cb, param_list)
00055     rospy.logout('Ready')
00056 
00057     rospy.spin()
00058 
00059 


point_cloud_ros
Author(s): Advait Jain (Healthcare Robotics Lab, Georgia Tech)
autogenerated on Wed Nov 27 2013 12:16:42