publish or subscribe depth image with python cv2

asked 2017-02-17 04:06:15 -0500

wsAndy gravatar image

updated 2017-02-17 04:07:18 -0500

Hello everyone!

I don not know how to publish or subscribe depth image with cv2 module.

For example, if I want to publish depth image, I load a .png depth image in the computer. and the codes are below.

depth_image = cv2.imread(os.path.join(self.path,depth_image_name))

d_image = np.array(depth_image)

send_depth = Image()

send_depth.encoding = '32FC1'

...

But when I use rqt_image_view to check the published image, it cannot show the image and occurs warns ImageView.callback_image() while trying to convert image from '32FC1' to 'rgb8' an exception was thrown (Image is wrongly formed: height * step != size or 480 * 2560 != 921600)

I add cv2.CV_LOAD_IMAGE_UNCHANGED in cv2.imread(), but the problem is still here.

And when I want to subscribe the depth image with python, which type should I set in cvimage = self.bridge.imgmsg_to_cv2(data,"32FC1")(here is 32FC1)

Thanks first!

edit retag flag offensive close merge delete