blobs_2_3d.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('blob3d')
00003 import rospy
00004 from cmvision.msg import Blobs
00005 from sensor_msgs.msg import PointCloud2
00006 from projector_interface._point_cloud import read_points_np, create_cloud_np
00007 #from pr2_python.pointclouds import xyz_array_to_pointcloud2
00008 import numpy as np
00009 
00010 blobs = []
00011 cloud = None
00012 cloud_header = None
00013 fields = None
00014 
00015 def blob_cb(msg):
00016         global blobs
00017         blobs = msg
00018 
00019 def cloud_cb(msg):
00020         global cloud, cloud_header, fields
00021         cloud = read_points_np(msg)
00022         cloud_header = msg.header
00023         fields = msg.fields
00024 
00025 if __name__ == '__main__':
00026         rospy.init_node('blob_2_3d')
00027         rospy.Subscriber('/blobs', Blobs, blob_cb)
00028         rospy.Subscriber('cloud', PointCloud2, cloud_cb)
00029         cloud_pub = rospy.Publisher('blob_cloud', PointCloud2)
00030         while not rospy.is_shutdown():
00031                 if not blobs:
00032                         continue
00033                 if not cloud is not None:
00034                         continue
00035                 blob_pts = []
00036                 for blob in blobs.blobs:
00037                         point = cloud[blob.y, blob.x]
00038                         blob_pts.append(point)
00039                 
00040                 out_cloud = create_cloud_np(cloud_header, fields, np.array(blob_pts))
00041                 cloud_pub.publish(out_cloud)


blob3d
Author(s): robotics
autogenerated on Mon Oct 6 2014 10:21:51