Base for all image transport codecs. All codecs have to extend class ImageTransportCodec
and implement the pure virtual methods std::string getTransportName() const
, encode(const sensor_msgs::Image&, const dynamic_reconfigure::Config&) const
and decode(const topic_tools::ShapeShifter&, const dynamic_reconfigure::Config&) const
. There are other convenience methods provided, but all of them are based on these implementations.
More...
#include <image_transport_codec.h>
|
virtual DecodeResult | decode (const topic_tools::ShapeShifter &compressed, const dynamic_reconfigure::Config &config) const =0 |
| Decode the given compressed image into a raw image. More...
|
|
DecodeResult | decode (const topic_tools::ShapeShifter &compressed) const |
| Decode the given compressed image into a raw image using the default decompression parameters. More...
|
|
DecodeResult | decode (const topic_tools::ShapeShifter &compressed, const XmlRpc::XmlRpcValue &config) const |
| Decode the given compressed image into a raw image. More...
|
|
DecodeResult | decode (const topic_tools::ShapeShifter &compressed, const ros::NodeHandle &nh, const std::string ¶m) const |
| Decode the given compressed image into a raw image. More...
|
|
template<typename Config > |
DecodeResult | decode (const topic_tools::ShapeShifter &compressed, const Config &config) const |
| Decode the given compressed image into a raw image. More...
|
|
virtual EncodeResult | encode (const sensor_msgs::Image &raw, const dynamic_reconfigure::Config &config) const =0 |
| Encode the given raw image into the given shapeshifter object. More...
|
|
EncodeResult | encode (const sensor_msgs::Image &raw) const |
| Encode the given raw image into the given shapeshifter object using the default compression parameters. More...
|
|
EncodeResult | encode (const sensor_msgs::Image &raw, const XmlRpc::XmlRpcValue &config) const |
| Encode the given raw image into the given shapeshifter object. More...
|
|
EncodeResult | encode (const sensor_msgs::Image &raw, const ros::NodeHandle &nh, const std::string ¶m) const |
| Encode the given raw image into the given shapeshifter object. More...
|
|
template<typename Config > |
EncodeResult | encode (const sensor_msgs::Image &raw, const Config &config) const |
| Encode the given raw image into the given shapeshifter object. More...
|
|
virtual GetCompressedContentResult | getCompressedImageContent (const topic_tools::ShapeShifter &compressed, const std::string &matchFormat) const =0 |
| Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned. More...
|
|
GetCompressedContentResult | getCompressedImageContent (const topic_tools::ShapeShifter &compressed) const |
| Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned. More...
|
|
virtual std::string | getTransportName () const =0 |
| Get the name of the codec/transport (used e.g. as topic suffix). More...
|
|
| ImageTransportCodec (const cras::LogHelperPtr &logHelper) |
| Create an instance of the codec. More...
|
|
virtual | ~ImageTransportCodec () |
|
::cras::LogHelperConstPtr | getCrasLogger () const |
|
| HasLogger (const ::cras::LogHelperPtr &log) |
|
void | setCrasLogger (const ::cras::LogHelperPtr &log) |
|
Base for all image transport codecs. All codecs have to extend class ImageTransportCodec
and implement the pure virtual methods std::string getTransportName() const
, encode(const sensor_msgs::Image&, const dynamic_reconfigure::Config&) const
and decode(const topic_tools::ShapeShifter&, const dynamic_reconfigure::Config&) const
. There are other convenience methods provided, but all of them are based on these implementations.
Each codec should be implemented as a standalone library for direct use, and also as a plugin inheriting from ImageTransportCodecPlugin
for generic use via ImageTransportCodecs
.
- Note
- As there is no common superclass for ROS messages and each codec can output compressed messages of different type, the generic interface for the compressed messages is
ShapeShifter
. The good thing is it offers a really generic way of working with messages. The bad thing is that it does that through (de)serialization of the messages, which might become a bottleneck in high-performance applications. Therefore, if you know the codec in advance, you should directly use the concrete codec and not this generic interface.
- Note
- The
EncodeResult
and DecodeResult
types used for outputs of the API functions make use of cras::expected
, which is an implementation of the proposed std::expected
template. Generally, expected
can either hold the result (in the expected case), or an error (in the unexpected case). So after getting the encoding/decoding result, you always first have to check it for validity (if (!result) return false
). On a valid result, you can call cras::expected::value()
to get the expected object. On an invalid result, you can call cras::expected::error()
to get the error message.
- Note
- Throughout this interface, you will see usages of
cras::ShapeShifter
instead of topic_tools::ShapeShifter
. These two are the same API-wise, but cras::ShapeShifter
contains a super-important bugfix without which your programs would quickly segfault. Generally, it is not safe to make copies of topic_tools::ShapeShifter
(not even returning it from functions!). cras::ShapeShifter
makes copying possible. Note that it is safe to pass around references to topic_tools::ShapeShifter
(but you can never copy the objects).
Definition at line 81 of file image_transport_codec.h.
◆ ConstPtr
◆ DecodeResult
Result of image decoding. Either a sensor_msgs::Image
holding the raw message, or error message.
Definition at line 95 of file image_transport_codec.h.
◆ EncodeResult
Result of image encoding. Either a shapeshifter holding the compressed message, or error message.
Definition at line 92 of file image_transport_codec.h.
◆ GetCompressedContentResult
◆ Ptr
◆ ImageTransportCodec()
image_transport_codecs::ImageTransportCodec::ImageTransportCodec |
( |
const cras::LogHelperPtr & |
logHelper | ) |
|
|
explicit |
Create an instance of the codec.
- Parameters
-
[in] | logHelper | The logger to use for error messages not directly related to the currently processed image. |
◆ ~ImageTransportCodec()
virtual image_transport_codecs::ImageTransportCodec::~ImageTransportCodec |
( |
| ) |
|
|
virtual |
◆ decode() [1/5]
◆ decode() [2/5]
Decode the given compressed image into a raw image using the default decompression parameters.
- Parameters
-
[in] | compressed | The shapeshifter of the compressed image to be decoded. |
- Returns
- The decoded raw image (if decoding succeeds), or an error message.
◆ decode() [3/5]
Decode the given compressed image into a raw image.
- Parameters
-
[in] | compressed | The shapeshifter of the compressed image to be decoded. |
[in] | config | Config of the decompression (if it has any parameters). Pass a XmlRpc dict. |
- Returns
- The decoded raw image (if decoding succeeds), or an error message.
◆ decode() [4/5]
Decode the given compressed image into a raw image.
- Parameters
-
[in] | compressed | The shapeshifter of the compressed image to be decoded. |
[in] | nh | Node handle to get parameters from. |
[in] | param | Name of the parameter from which config of the decompression can be read (if it has any parameters). |
- Returns
- The decoded raw image (if decoding succeeds), or an error message.
◆ decode() [5/5]
template<typename Config >
Decode the given compressed image into a raw image.
- Template Parameters
-
Config | Type of the config object. This should be the generated dynamic_reconfigure interface of the corresponding image_transport subscriber. |
- Parameters
-
[in] | compressed | The shapeshifter of the compressed image to be decoded. |
[in] | config | Config of the decompression (if it has any parameters). |
- Returns
- The decoded raw image (if decoding succeeds), or an error message.
Definition at line 230 of file image_transport_codec.h.
◆ encode() [1/5]
virtual EncodeResult image_transport_codecs::ImageTransportCodec::encode |
( |
const sensor_msgs::Image & |
raw, |
|
|
const dynamic_reconfigure::Config & |
config |
|
) |
| const |
|
pure virtual |
◆ encode() [2/5]
EncodeResult image_transport_codecs::ImageTransportCodec::encode |
( |
const sensor_msgs::Image & |
raw | ) |
const |
Encode the given raw image into the given shapeshifter object using the default compression parameters.
- Parameters
-
[in] | raw | The input raw image. |
- Returns
- The output shapeshifter holding the compressed image message (if encoding succeeds), or an error message.
◆ encode() [3/5]
Encode the given raw image into the given shapeshifter object.
- Parameters
-
[in] | raw | The input raw image. |
[in] | config | Config of the compression (if it has any parameters). Pass a XmlRpc dict. |
- Returns
- The output shapeshifter holding the compressed image message (if encoding succeeds), or an error message.
◆ encode() [4/5]
EncodeResult image_transport_codecs::ImageTransportCodec::encode |
( |
const sensor_msgs::Image & |
raw, |
|
|
const ros::NodeHandle & |
nh, |
|
|
const std::string & |
param |
|
) |
| const |
Encode the given raw image into the given shapeshifter object.
- Parameters
-
[in] | raw | The input raw image. |
[in] | nh | Node handle to get parameters from. |
[in] | param | Name of the parameter from which config of the compression can be read (if it has any parameters). |
- Returns
- The output shapeshifter holding the compressed image message (if encoding succeeds), or an error message.
◆ encode() [5/5]
template<typename Config >
EncodeResult image_transport_codecs::ImageTransportCodec::encode |
( |
const sensor_msgs::Image & |
raw, |
|
|
const Config & |
config |
|
) |
| const |
|
inline |
Encode the given raw image into the given shapeshifter object.
- Template Parameters
-
Config | Type of the config object. This should be the generated dynamic_reconfigure interface of the corresponding image_transport publisher. |
- Parameters
-
[in] | raw | The input raw image. |
[in] | config | Config of the compression (if it has any parameters). |
- Returns
- The output shapeshifter holding the compressed image message (if encoding succeeds), or an error message.
Definition at line 214 of file image_transport_codec.h.
◆ getCompressedImageContent() [1/2]
Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned.
- Parameters
-
[in] | compressed | The compressed image. |
[in] | matchFormat | If nonempty, the image data is only returned if their format field would match the given one. The matching should be case-insensitive. |
- Returns
- If it makes sense, the contained image bytes. If not, empty result. If an error occurred, it is reported as the unexpected result.
Implemented in image_transport_codecs::CompressedCodec, and image_transport_codecs::CompressedDepthCodec.
◆ getCompressedImageContent() [2/2]
Return the part of the encoded message that represents the actual image data (i.e. the part that can be passed to external decoders or saved to a file). If the codec messages have no such meaning, empty result is returned.
- Parameters
-
[in] | compressed | The compressed image. |
- Returns
- If it makes sense, the contained image bytes. If not, empty result. If an error occurred, it is reported as the unexpected result.
◆ getTransportName()
virtual std::string image_transport_codecs::ImageTransportCodec::getTransportName |
( |
| ) |
const |
|
pure virtual |
The documentation for this class was generated from the following file: