def mkgray(self, msg):
"""
Convert a message into a 8-bit 1 channel monochrome OpenCV image
"""
# as cv_bridge automatically scales, we need to remove that behavior
# TODO: get a Python API in cv_bridge to check for the image depth.
if self.br.encoding_to_dtype_with_channels(msg.encoding)[0] in ['uint16', 'int16']:
mono16 = self.br.imgmsg_to_cv2(msg, '16UC1')
mono8 = np.array(np.clip(mono16, 0, 255), dtype=np.uint8)
return mono8
elif 'FC1' in msg.encoding:
# floating point image handling
img = self.br.imgmsg_to_cv2(msg, "passthrough")
_, max_val, _, _ = cv2.minMaxLoc(img)
if max_val > 0:
scale = 255.0 / max_val
mono_img = (img * scale).astype(np.uint8)
else:
mono_img = img.astype(np.uint8)
return mono_img
else:
return self.br.imgmsg_to_cv2(msg, "mono8")
get_extrinsics.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录