Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

call custom service in python

I am using Indigo, and having trouble calling a service from python.

I have defined a service for sending images and receiving a message:

#***** perception_core::FR.srv ******
# image size
int16 rows
int16 cols
int16 step
# copy of Mat data structure
int8[] image_data
int8[] bbox
float likelihood

The server side operation is implemented in C++, and works just fine. I use it regularly with other C++ programs. However, when calling it from python I am struggling:

from perception_core.srv import FR
FR_srv = rospy.ServiceProxy('/ros_matching/FR_srv', FR)
img_in = imread('...')
img = np.array(img_in)
x_data = img.flatten()
bbox,likelihood = FR_srv(img.shape[0],img.shape[1],img.shape[1],x_data.tolist())

And I get the following error: * SerializationError: field image_data[] exceeds specified width [int8]

I've also tried initializing the array beforehand:

request = FR()
request.rows = img.shape[0]
request.cols = img.shape[1]
request.step = img.shape[1]
request.image_data = x_data.tolist()
bbox,likelihood = FR_srv(request)

But this generates a different error:

* TypeError: Invalid number of arguments, args should be ['rows', 'cols', 'step', 'image_data'] args are(< object="" at="" 0x7f24681ffd50="">,)

Any thoughts or suggestions on what to try next would be greatly appreciated.