Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for passing parameters to cv::imencode through "toCompressedImageMsg" function. #521

Open
wants to merge 1 commit into
base: humble
Choose a base branch
from

Conversation

emrekuru97
Copy link

@emrekuru97 emrekuru97 commented Mar 1, 2024

Support for passing parameters to cv::imencode through toCompressedImageMsg function, i need this functionality so that the compression quality can be passed through toCompressedImageMsg function, other pepople can pass other options too. Tried to keep current functionality and generated possible other signatures for the function toCompressedImageMsg. Could not find a formatter in the repo so did not formatting, the default ros formatter changed a lot so i let it.

const Format dst_format =
JPG) const;
const Format dst_format = JPG,
const std::vector<int> &params=std::vector<int>()) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There need to be spaces around = to follow the style in the rest of the code. I also suggest using the curly braces initialiser ({}) in place of the explicit constructor for easier readability.

Adding a new parameter to a function breaks the ABI, meaning that the new library can not be replaced without recompiling all packages that link it. For backward compatibility, you have to keep a function with the old signature that calls your new function with an empty params.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed feedback. I'll let a function with the original signature. I thought since the parameter is default it will not alter the other packages i did not thought of compiling.

@@ -464,15 +464,21 @@ CvImagePtr cvtColor(

/////////////////////////////////////// CompressedImage ///////////////////////////////////////////

sensor_msgs::msg::CompressedImage::SharedPtr CvImage::toCompressedImageMsg(const Format dst_format)
sensor_msgs::msg::CompressedImage::SharedPtr CvImage::toCompressedImageMsg(const Format dst_format,const std::vector<int> &params)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space between the end of a parameter and the start of a new one. See the style in other parts of the code.

Comment on lines +136 to +137
sensor_msgs::msg::CompressedImage::SharedPtr toCompressedImageMsg(
const std::vector<int> &params=std::vector<int>(), const Format dst_format = JPG) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a second function of the same name with swapped parameter order?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of this like, may be i want only provide parameters for the cv::imencode. Otherwise the dest_format need to be explicitly specified in each call we want provide params to cv::imencode.

*/
void toCompressedImageMsg(
sensor_msgs::msg::CompressedImage & ros_image,
const Format dst_format = JPG) const;
const Format dst_format = JPG, const std::vector<int> &params=std::vector<int>()) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the curly braces initialiser ({}).

Comment on lines +476 to +481
sensor_msgs::msg::CompressedImage::SharedPtr CvImage::toCompressedImageMsg(const std::vector<int> &params, const Format dst_format)
const
{
return toCompressedImageMsg(dst_format, params);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function actually doing? It just swaps the parameters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's only the implementation for providing parameters to cv::imencode without explicitly providing the format.

Comment on lines +169 to +171
void toCompressedImageMsg(
sensor_msgs::msg::CompressedImage & ros_image,
const std::vector<int> &params=std::vector<int>(), const Format dst_format = JPG) const;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too. Why do we need the same function with swapped parameters?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same reason like the other function. If this is not neccessary i can remove it (swapping the parameters) and only provide cv::imencode params alongside with dst_format.

@emrekuru97
Copy link
Author

emrekuru97 commented Mar 9, 2024

Hello again,
How should i proceed? With swapping(support for passing cv::imencode params without explicitly specifying dst_format) or without?
Best regards

@ijnek
Copy link
Member

ijnek commented Mar 15, 2024

Hey @emrekuru97, thanks for opening this PR, and thanks for reviewing @christianrauch!

Despite the method "toCompressedImageMsg" existing in this package, moving forward, I don't think we should be extending cv_bridge's capability to compress images. cv_bridge's responsibility is to convert ROS Image msg <-> OpenCV image.

The thing that immediately came to mind when I read this was the compressed transport plugin, which is used to transport compressed image messages over a topic. In that plugin, the conversion takes place, and then the compression is called afterwards. Would this work for your use case? (or could you just use the compressed publisher?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants