From d8958d1b07cb2df83519f705f2acbc9aeb854cb3 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Wed, 31 Jan 2024 16:36:27 -0500 Subject: [PATCH] default to encoding in the image message --- image_view/scripts/extract_images_sync | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/image_view/scripts/extract_images_sync b/image_view/scripts/extract_images_sync index ec28c9667..f499bf418 100755 --- a/image_view/scripts/extract_images_sync +++ b/image_view/scripts/extract_images_sync @@ -84,9 +84,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)