使用 imgmsg_to_cv2 [python] 在 ROS 中获取灰度深度图像

Get Depth image in grayscale in ROS with imgmsg_to_cv2 [python]

我正在使用 Kinect v1,我想从 ROS 中的通道 "/camera/depth_registered/image" 获取灰度模式的深度图像。正如我发现 here,我可以使用函数 imgmsg_to_cv2 来完成。我的深度消息的默认 desired_encoding 是“32FC1”,我保留了它。问题是,当我使用 cv2.imshow() 函数来显示它时,我得到的是二进制图像...当我对 RGB 图像执行相同操作时,一切都显示得很好...

感谢任何帮助!

所以我终于找到了解决办法,你可以在这里看到:

def Depthcallback(self,msg_depth): # TODO still too noisy!
try:
  # The depth image is a single-channel float32 image
  # the values is the distance in mm in z axis
  cv_image = self.bridge.imgmsg_to_cv2(msg_depth, "32FC1")
  # Convert the depth image to a Numpy array since most cv2 functions
  # require Numpy arrays.
  cv_image_array = np.array(cv_image, dtype = np.dtype('f8'))
  # Normalize the depth image to fall between 0 (black) and 1 (white)
  # http://docs.ros.org/electric/api/rosbag_video/html/bag__to__video_8cpp_source.html lines 95-125
  cv_image_norm = cv2.normalize(cv_image_array, cv_image_array, 0, 1, cv2.NORM_MINMAX)
  # Resize to the desired size
  cv_image_resized = cv2.resize(cv_image_norm, self.desired_shape, interpolation = cv2.INTER_CUBIC)
  self.depthimg = cv_image_resized
  cv2.imshow("Image from my node", self.depthimg)
  cv2.waitKey(1)
except CvBridgeError as e:
  print(e)

不过,虽然没有我在ROS的image_view节点得到的那么完美,但还是可以接受的!