test_serializers.py 文件源码

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

项目:ros-interop 作者: mcgill-robotics 项目源码 文件源码
def test_object_image_serializer(self):
        """Tests object image serializer can be deserialized."""
        # Create random 40 x 30 RGB image.
        width = 40
        height = 30
        nparr = np.random.randint(0, 256, (width, height, 3)).astype(np.uint8)

        # Convert to ROS Image.
        bridge = CvBridge()
        msg = bridge.cv2_to_imgmsg(nparr)

        # Serialize.
        png = serializers.ObjectImageSerializer.from_msg(msg)

        # Deserialize.
        converted_msg = serializers.ObjectImageSerializer.from_raw(png)

        # Convert to array.
        converted_img = bridge.imgmsg_to_cv2(converted_msg)
        converted_arr = np.asarray(converted_img)

        # Test if we get the original image.
        self.assertTrue((converted_arr == nparr).all())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号