-
Notifications
You must be signed in to change notification settings - Fork 606
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
base: humble
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,10 +117,24 @@ class CV_BRIDGE_EXPORT CvImage | |
* can be: jpg, jp2, bmp, png, tif at the moment | ||
* support this format from opencv: | ||
* http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat imread(const string& filename, int flags) | ||
* params are the options for cv::imencode. | ||
* Default value is empty list. | ||
*/ | ||
sensor_msgs::msg::CompressedImage::SharedPtr toCompressedImageMsg( | ||
const Format dst_format = | ||
JPG) const; | ||
const Format dst_format = JPG, | ||
const std::vector<int> ¶ms=std::vector<int>()) const; | ||
|
||
/** | ||
* dst_format is compress the image to desire format. | ||
* Default value is empty string that will convert to jpg format. | ||
* can be: jpg, jp2, bmp, png, tif at the moment | ||
* support this format from opencv: | ||
* http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat imread(const string& filename, int flags) | ||
* params are the options for cv::imencode. | ||
* Default value is empty list. | ||
*/ | ||
sensor_msgs::msg::CompressedImage::SharedPtr toCompressedImageMsg( | ||
const std::vector<int> ¶ms=std::vector<int>(), const Format dst_format = JPG) const; | ||
Comment on lines
+136
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
/** | ||
* \brief Copy the message data to a ROS sensor_msgs::msg::Image message. | ||
|
@@ -136,11 +150,25 @@ class CV_BRIDGE_EXPORT CvImage | |
* can be: jpg, jp2, bmp, png, tif at the moment | ||
* support this format from opencv: | ||
* http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat imread(const string& filename, int flags) | ||
* params are the options for cv::imencode. | ||
* Default value is empty list. | ||
*/ | ||
void toCompressedImageMsg( | ||
sensor_msgs::msg::CompressedImage & ros_image, | ||
const Format dst_format = JPG) const; | ||
const Format dst_format = JPG, const std::vector<int> ¶ms=std::vector<int>()) const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the curly braces initialiser ( |
||
|
||
/** | ||
* dst_format is compress the image to desire format. | ||
* Default value is empty string that will convert to jpg format. | ||
* can be: jpg, jp2, bmp, png, tif at the moment | ||
* support this format from opencv: | ||
* http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat imread(const string& filename, int flags) | ||
* params are the options for cv::imencode. | ||
* Default value is empty list. | ||
*/ | ||
void toCompressedImageMsg( | ||
sensor_msgs::msg::CompressedImage & ros_image, | ||
const std::vector<int> ¶ms=std::vector<int>(), const Format dst_format = JPG) const; | ||
Comment on lines
+169
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. Why do we need the same function with swapped parameters? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
typedef std::shared_ptr<CvImage> Ptr; | ||
typedef std::shared_ptr<CvImage const> ConstPtr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> ¶ms) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const | ||
{ | ||
sensor_msgs::msg::CompressedImage::SharedPtr ptr = | ||
std::make_shared<sensor_msgs::msg::CompressedImage>(); | ||
toCompressedImageMsg(*ptr, dst_format); | ||
toCompressedImageMsg(*ptr, dst_format, params); | ||
return ptr; | ||
} | ||
|
||
sensor_msgs::msg::CompressedImage::SharedPtr CvImage::toCompressedImageMsg(const std::vector<int> ¶ms, const Format dst_format) | ||
const | ||
{ | ||
return toCompressedImageMsg(dst_format, params); | ||
} | ||
|
||
Comment on lines
+476
to
+481
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this function actually doing? It just swaps the parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
std::string getFormat(Format format) | ||
{ | ||
switch (format) { | ||
|
@@ -511,7 +517,14 @@ std::string getFormat(Format format) | |
|
||
void CvImage::toCompressedImageMsg( | ||
sensor_msgs::msg::CompressedImage & ros_image, | ||
const Format dst_format) const | ||
const std::vector<int> ¶ms, const Format dst_format) const | ||
{ | ||
toCompressedImageMsg(ros_image, dst_format, params); | ||
} | ||
|
||
void CvImage::toCompressedImageMsg( | ||
sensor_msgs::msg::CompressedImage & ros_image, | ||
const Format dst_format, const std::vector<int> ¶ms) const | ||
{ | ||
ros_image.header = header; | ||
cv::Mat image; | ||
|
@@ -531,7 +544,7 @@ void CvImage::toCompressedImageMsg( | |
|
||
std::string format = getFormat(dst_format); | ||
ros_image.format = format; | ||
cv::imencode("." + format, image, ros_image.data); | ||
cv::imencode("." + format, image, ros_image.data, params); | ||
} | ||
|
||
// Deep copy data, returnee is mutable | ||
|
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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.