serializers.py 文件源码

python
阅读 42 收藏 0 点赞 0 评论 0

项目:ros-interop 作者: mcgill-robotics 项目源码 文件源码
def from_raw(cls, raw, compress=False):
        """Deserializes binary-encoded image data into a ROS Image message.

        Args:
            raw: Binary encoded image data.
            compress: Whether to return a compressed image or not.

        Returns:
            ROS Image or CompressedImage message.

        Raises:
            CvBridgeError: On image conversion error.
        """
        # Convert to OpenCV image.
        nparr = np.fromstring(raw, np.uint8)
        img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

        # Convert to ROS message.
        bridge = CvBridge()
        msg = bridge.cv2_to_imgmsg(img)

        if compress:
            data = cls.from_msg(msg)
            msg = CompressedImage()
            msg.format = "png"
            msg.data = data

        return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号