python: reading messages very slow

asked 2015-05-08 11:20:24 -0600

ebeowulf gravatar image

I'm new to using python - and have hit a giant speed bump trying to integrate a python library into ROS indigo. I created a node in c++ that processes a point cloud, and transmits segments using the following two messages:

Segmented BlobArray.msg

Header header
int16 full_image_rows
int16 full_image_cols
SegmentedBlob[] blobs


int64  id
int16[]  bbox
std_msgs/Int16MultiArray pt_list

On the python side, I have to rebuild each segment within the image:

for pp in range(0,data.blobs[Bid].pt_list.layout.dim[0].size):
    row = data.blobs[Bid][3*pp+1]-ymin;
    col = data.blobs[Bid][3*pp]-xmin;
    cv_image[row,col] = data.blobs[Bid][3*pp+2]

The process works, but the transfer is extremely slow. The for loop itself is not the issue. Adding random numbers to cv_image for the same number of times is still quick. Only once I access the ROS message does it get slow ( 4 sec delay). The same process in C++ has a <10msec delay.

Are their python tricks for accessing these types of messages? Or maybe there are easy ways of transmitting multiple segments in an image?

edit retag flag offensive close merge delete