ROS CV_Bridge库

参考:

[1]. cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages - ROS Wiki

本文只是翻译一下。

 1. CvBridge

主要用于ROS图像数据和opencv图像数据的转换,一个桥梁的作用。

2. Converting ROS image messages to OpenCV images

CvBridge defines a CvImage type containing an OpenCV image, its encoding and a ROS header. CvImage contains exactly the information sensor_msgs/Image does, so we can convert either representation to the other. CvImage class format:

CvBridge定义了一个CvImage类型,其中包含OpenCV图像,其编码和ROS标头。CvImage 包含的信息与 sensor_msgs/Image 完全相同,因此我们可以将任一表示转换为另一种表示。CvImage 类格式:

When converting a ROS sensor_msgs/Image message into a CvImage, CvBridge recognizes two distinct use cases:

将 ROS sensor_msgs/Image 消息转换为 CvImage 时,CvBridge 可以识别两种不同的用例:

  • We want to modify the data in-place. We have to make a copy of the ROS message data.

我们希望就地修改数据。我们必须复制 ROS 消息数据。

  • We won't modify the data. We can safely share the data owned by the ROS message instead of copying.

我们不会修改数据。我们可以安全地共享 ROS 消息拥有的数据,而不是复制。

CvBridge provides the following functions for converting to CvImage:

CvBridge提供了以下转换为CvImage的功能:

The input is the image message pointer, as well as an optional encoding argument. The encoding refers to the destination CvImage.

输入是图像消息指针,以及可选的编码参数。编码是指目标 CvImage。

toCvCopy creates a copy of the image data from the ROS message, even when the source and destination encodings match. However, you are free to modify the returned CvImage.

toCvCopy 从 ROS 消息创建图像数据的副本,即使源和目标编码匹配也是如此。但是,您可以自由修改返回的 CvImage。

toCvShare will point the returned cv::Mat at the ROS message data, avoiding a copy, if the source and destination encodings match. As long as you hold a copy of the returned CvImage, the ROS message data will not be freed. If the encodings do not match, it will allocate a new buffer and perform the conversion. You are not permitted to modify the returned CvImage, as it may share data with the ROS image message, which in turn may be shared with other callbacks. Note: the second overload of toCvShare is more convenient when you have a pointer to some other message type (e.g. stereo_msgs/DisparityImage) that contains a sensor_msgs/Image you want to convert.

toCvShare 会将返回的 cv::Mat 指向 ROS 消息数据,如果源和目标编码匹配,则避免复制。只要您持有返回的 CvImage 的副本,就不会释放 ROS 消息数据。如果编码不匹配,它将分配一个新的缓冲区并执行转换。您不能修改返回的 CvImage,因为它可能会与 ROS 镜像消息共享数据,而 ROS 镜像消息又可能与其他回调共享。注意:当您有一个指向包含要转换的sensor_msgs/图像的其他消息类型(例如 stereo_msgs/DisparityImage)的指针时,toCvShare 的第二次重载更方便。

If no encoding (or rather, the empty string) is given, the destination image encoding will be the same as the image message encoding. In this case toCvShare is guaranteed to not copy the image data. Image encodings can be any one of the following OpenCV image encodings:

如果未给出编码(或者更确切地说,空字符串),则目标图像编码将与图像消息编码相同。在这种情况下,toCvShare保证不会复制图像数据。图像编码可以是以下任何一种 OpenCV 图像编码:

For popular image encodings, CvBridge will optionally do color or pixel depth conversions as necessary. To use this feature, specify the encoding to be one of the following strings:

对于流行的图像编码,CvBridge 将根据需要选择性地进行颜色或像素深度转换。若要使用此功能,请将编码指定为以下字符串之一:

Note that mono8 and bgr8 are the two image encodings expected by most OpenCV functions.

请注意,mono8 和 bgr8 是大多数 OpenCV 函数所期望的两种图像编码。

 Finally, CvBridge will recognize Bayer pattern encodings as having OpenCV type 8UC1 (8-bit unsigned, one channel). It will not perform conversions to or from Bayer pattern; in a typical ROS system, this is done instead by image_proc. CvBridge recognizes the following Bayer encodings:

最后,CvBridge将识别拜耳模式编码为具有OpenCV类型8UC1(8位无符号,一个通道)。它不会执行与拜耳模式之间的转换;在典型的 ROS 系统中,这是由 image_proc 完成的。CvBridge认可以下拜耳编码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值