call custom service in python [closed]
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
rospy.wait_for_service('/ros_matching/FR_srv')
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(<perception_core.srv._fr.fr object="" at="" 0x7f24681ffd50="">,)
Any thoughts or suggestions on what to try next would be greatly appreciated.
What is the dtype for x_data?
x_data is the output of img.flatten(), so it should be a 1D numpy array.
Right, but containing what size of data? What does
x_data.dtype
give you?Type and size: