Skip to content

Commit

Permalink
default to encoding in the image message (#921)
Browse files Browse the repository at this point in the history
My camera is publishing rgb8 encoding - the existing code throws an
error that 8UC3 is not a valid encoding, but if we pass rgb8 from the
message then things work fine. The encoding in the image should always
be more descriptive than just the bit and channel size.

If encoding is not filled in, the existing behavior is used as a
fallback
  • Loading branch information
mikeferguson authored Jan 31, 2024
1 parent db8fc17 commit 9b2468d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions image_view/scripts/extract_images_sync
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ Typical command-line usage:
bridge = cv_bridge.CvBridge()
for i, imgmsg in enumerate(imgmsgs):
img = bridge.imgmsg_to_cv2(imgmsg)
channels = img.shape[2] if img.ndim == 3 else 1
encoding_in = bridge.dtype_with_channels_to_cvtype2(
img.dtype, channels)
# Default to the encoding in the image message
encoding_in = imgmsg.encoding
if not encoding_in:
# Encoding is not specified, try to automatically determine
channels = img.shape[2] if img.ndim == 3 else 1
encoding_in = bridge.dtype_with_channels_to_cvtype2(
img.dtype, channels)
img = cv_bridge.cvtColorForDisplay(
img, encoding_in=encoding_in, encoding_out='',
do_dynamic_scaling=self.do_dynamic_scaling)
Expand Down

0 comments on commit 9b2468d

Please sign in to comment.