Skip to content

Commit

Permalink
[ADD] flag for jpeg compression of bayer format
Browse files Browse the repository at this point in the history
  • Loading branch information
wodtko committed May 13, 2022
1 parent bb08603 commit 4c2a8a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CompressedPublisher : public image_transport::SimplePublisherPlugin<Compre
// JPEG Quality from 0 to 100 (higher is better quality).
// Default to OpenCV default of 95.
int jpeg_quality;
bool jpeg_compress_bayer;

// TIFF resolution unit
// Can be one of "none", "inch", "centimeter".
Expand Down
23 changes: 22 additions & 1 deletion compressed_image_transport/src/compressed_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
constexpr const char* kDefaultFormat = "jpeg";
constexpr int kDefaultPngLevel = 3;
constexpr int kDefaultJpegQuality = 95;
constexpr bool kDefaultJpegCompressBayer = false;

using namespace cv;
using namespace std;
Expand Down Expand Up @@ -121,6 +122,20 @@ void CompressedPublisher::advertiseImpl(
config_.jpeg_quality = node->get_parameter(jpeg_quality_param_name).get_value<int64_t>();
}

std::string jpeg_compress_bayer_param_name = param_base_name + ".jpeg_compress_bayer";
rcl_interfaces::msg::ParameterDescriptor jpeg_compress_bayer_description;
jpeg_compress_bayer_description.name = "jpeg_compress_bayer";
jpeg_compress_bayer_description.type = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL;
jpeg_compress_bayer_description.description = "Compress bayer format without converting to mono8 first";
jpeg_compress_bayer_description.read_only = false;
try {
config_.jpeg_compress_bayer = node->declare_parameter(
jpeg_compress_bayer_param_name, kDefaultJpegCompressBayer, jpeg_compress_bayer_description);
} catch (const rclcpp::exceptions::ParameterAlreadyDeclaredException &) {
RCLCPP_DEBUG(logger_, "%s was previously declared", jpeg_compress_bayer_param_name.c_str());
config_.jpeg_compress_bayer = node->get_parameter(jpeg_compress_bayer_param_name).get_value<bool>();
}

std::string tiff_res_unit_param_name = param_base_name + ".tiff.res_unit";
rcl_interfaces::msg::ParameterDescriptor tiff_res_unit_description;
tiff_res_unit_description.description = "tiff resolution unit";
Expand Down Expand Up @@ -206,7 +221,13 @@ void CompressedPublisher::publish(
// convert color images to BGR8 format
targetFormat = "bgr8";
compressed.format += targetFormat;
} else {
}
else if (enc::isBayer(message.encoding) and config_.jpeg_compress_bayer)
{
targetFormat = message.encoding;
compressed.format += targetFormat;
}
else {
// convert gray images to mono8 format
targetFormat = "mono8";
compressed.format += targetFormat;
Expand Down

0 comments on commit 4c2a8a5

Please sign in to comment.