Skip to content

Commit

Permalink
Fix final confusion between format and encoding.
Browse files Browse the repository at this point in the history
Format is file format like jpg, bmp and more,
encoding is color encoding like bgr8, rgb8 and more.
  • Loading branch information
talregev committed May 10, 2019
1 parent 33f59e5 commit f72d1f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cv_bridge/include/cv_bridge/cv_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct CvtColorForDisplayOptions {
* encoding image is passed.
* - if the output encoding is not empty, it must have sensor_msgs::image_encodings::isColor and
* isMono return true. It must also be 8 bit in depth
* - if the input encoding is an OpenCV format (e.g. 8UC1), and if we have 1,3 or 4 channels, it is
* - if the input encoding is an OpenCV encoding (e.g. 8UC1), and if we have 1,3 or 4 channels, it is
* respectively converted to mono, BGR or BGRA.
* - if the input encoding is 32SC1, this estimate that image as label image and will convert it as
* bgr image with different colors for each label.
Expand Down
4 changes: 2 additions & 2 deletions cv_bridge/python/cv_bridge/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def compressed_imgmsg_to_cv2(self, cmprs_img_msg, desired_encoding = "passthroug
:rtype: :cpp:type:`cv::Mat`
:raises CvBridgeError: when conversion is not possible.
If desired_encoding is ``"passthrough"``, then the returned image has the same format as img_msg.
If desired_encoding is ``"passthrough"``, then the returned image has the same encoding as img_msg.
Otherwise desired_encoding must be one of the standard image encodings
This function returns an OpenCV :cpp:type:`cv::Mat` message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
Expand Down Expand Up @@ -151,7 +151,7 @@ def imgmsg_to_cv2(self, img_msg, desired_encoding = "passthrough"):
:rtype: :cpp:type:`cv::Mat`
:raises CvBridgeError: when conversion is not possible.
If desired_encoding is ``"passthrough"``, then the returned image has the same format as img_msg.
If desired_encoding is ``"passthrough"``, then the returned image has the same encoding as img_msg.
Otherwise desired_encoding must be one of the standard image encodings
This function returns an OpenCV :cpp:type:`cv::Mat` message on success, or raises :exc:`cv_bridge.CvBridgeError` on failure.
Expand Down
16 changes: 8 additions & 8 deletions cv_bridge/src/cv_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ const std::vector<int> getConversionCode(std::string src_encoding, std::string d
{
Encoding src_encod = getEncoding(src_encoding);
Encoding dst_encod = getEncoding(dst_encoding);
bool is_src_color_format = enc::isColor(src_encoding) || enc::isMono(src_encoding) ||
bool is_src_color_encoding = enc::isColor(src_encoding) || enc::isMono(src_encoding) ||
enc::isBayer(src_encoding) || (src_encoding == enc::YUV422);
bool is_dst_color_format = enc::isColor(dst_encoding) || enc::isMono(dst_encoding) ||
bool is_dst_color_encoding = enc::isColor(dst_encoding) || enc::isMono(dst_encoding) ||
enc::isBayer(dst_encoding) || (dst_encoding == enc::YUV422);
bool is_num_channels_the_same = (enc::numChannels(src_encoding) == enc::numChannels(dst_encoding));

// If we have no color info in the source, we can only convert to the same format which
// If we have no color info in the source, we can only convert to the same encoding which
// was resolved in the previous condition. Otherwise, fail
if (!is_src_color_format) {
if (is_dst_color_format)
throw Exception("[" + src_encoding + "] is not a color format. but [" + dst_encoding +
if (!is_src_color_encoding) {
if (is_dst_color_encoding)
throw Exception("[" + src_encoding + "] is not a color encoding. but [" + dst_encoding +
"] is. The conversion does not make sense");
if (!is_num_channels_the_same)
throw Exception("[" + src_encoding + "] and [" + dst_encoding + "] do not have the same number of channel");
Expand All @@ -219,9 +219,9 @@ const std::vector<int> getConversionCode(std::string src_encoding, std::string d

// If we are converting from a color type to a non color type, we can only do so if we stick
// to the number of channels
if (!is_dst_color_format) {
if (!is_dst_color_encoding) {
if (!is_num_channels_the_same)
throw Exception("[" + src_encoding + "] is a color format but [" + dst_encoding + "] " +
throw Exception("[" + src_encoding + "] is a color encoding but [" + dst_encoding + "] " +
"is not so they must have the same OpenCV type, CV_8UC3, CV16UC1 ....");
return std::vector<int>(1, SAME_FORMAT);
}
Expand Down

0 comments on commit f72d1f4

Please sign in to comment.