gramaziokohler / roslibpy

Python ROS Bridge library
MIT License
273 stars 56 forks source link

Received image by base64 can not be decode by opencv #115

Open Wangxinhui-bot opened 1 year ago

Wangxinhui-bot commented 1 year ago

Description

I send an image at 640480 from ros, then recieved the image using code from roslibpy tutorial, though I successfully decode the data into numpy array with size 921600(which is 640480*3), I used opencv to decode and get none return. To Reproduce My callback function is

def receive_image(msg):

log.info('Received image seq=%d', msg['header']['seq'])

base64_bytes = msg['data'].encode('ascii')
image_data = base64.b64decode(base64_bytes)
img_array = np.fromstring(image_data, np.uint8)
img = cv2.imdecode(img_array, cv2.COLOR_RGB2BGR)
cv2.imshow('image', img)
cv2.waitKey(0)