Skip to content

fix: ROSBag keeps the BGR color order of a CompressedImage unless told otherwise - #315

Open
petercorke wants to merge 2 commits into
mainfrom
bug/rosbag-compressed-colororder
Open

petercorke wants to merge 2 commits into
mainfrom
bug/rosbag-compressed-colororder

Conversation

@petercorke

Copy link
Copy Markdown
Owner

ROSBag labelled every sensor_msgs/CompressedImage as R:G:B, although OpenCV decodes the image as BGR. So a pure red JPEG came out as pure blue by default. The code worked out the right order (bgr, bgra or none for greyscale) and then replaced it with the colororder argument, which is None unless given. A per-topic dict also dropped the order of the topics it did not list.

The color order of a compressed image is now what the decoder gave, unless colororder is a string (used for every topic) or a dict with an entry for that topic. Passing colororder="bgr" already worked around it.

I found it by checking with an independent encoder: the new tests encode with Pillow, not OpenCV, so they do not depend on the decoder they check. 7 new tests in tests/test_ros_compressed_colororder.py; 4 of them fail without the fix. The 446 ROS tests pass and mypy is clean.

Behavior change to be aware of: compressed images from a bag now come out as B:G:R, so code that relied on the old (wrong) R:G:B label will see the planes the other way round. They were swapped before.

An AI assistant (Claude Code) wrote this change.

🤖 Generated with Claude Code

petercorke and others added 2 commits November 26, 2026 10:29
…d otherwise

A compressed image is decoded by OpenCV as BGR, but the code replaced the color
order it had worked out with the colororder argument, which is None by default, so
the image was labelled R:G:B and a pure red JPEG read back as blue.  A per-topic
dict also dropped the order of the topics it did not list.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 20 complexity · 0 duplication

Metric Results
Complexity 20
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
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.

1 participant