Skip to content
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

yuv422_yuy2 support #170

Open
TomoyukiaW opened this issue Oct 3, 2024 · 0 comments
Open

yuv422_yuy2 support #170

TomoyukiaW opened this issue Oct 3, 2024 · 0 comments

Comments

@TomoyukiaW
Copy link

I'm using the YUYV format output camera and usb_cam package as a driver. usb_cam uses image_transport::CameraPublisher to publish the image. Published raw_image encoding was "encoding: yuv422_yuy2" and raw_image/compressed format was "format: yuv422_yuy2; jpeg compressed mono8".
raw_image could be shown in RViz2. But raw_image/compressed couldn't shown in RViz2, and we got some errors in some image conversion processes (e.g. compressing with ffmpeg). It seems that the compression process for yuv image has a problem.

Then, the following modification worked in my environment. How about this?
cv_bridge supports to convert yuv422_yuy2 and yuv422 format image to cv Mat. For compressed_subscriber.cpp, I couldn't find the suitable conversion pattern and I thought probably most application don't use yuv format in its processing.

--- a/compressed_image_transport/src/compressed_publisher.cpp
+++ b/compressed_image_transport/src/compressed_publisher.cpp
@@ -201,7 +201,7 @@ void CompressedPublisher::publish(
       {
         // Target image format
         std::string targetFormat;
-        if (enc::isColor(message.encoding))
+        if (enc::isColor(message.encoding) || message.encoding == enc::YUV422 || message.encoding == enc::YUV422_YUY2)
         {
           // convert color images to BGR8 format
           targetFormat = "bgr8";

--- a/compressed_image_transport/src/compressed_subscriber.cpp
+++ b/compressed_image_transport/src/compressed_subscriber.cpp
@@ -143,7 +143,7 @@ void CompressedSubscriber::internalCallback(const CompressedImage::ConstSharedPt
 
       cv_ptr->encoding = image_encoding;
 
-      if ( enc::isColor(image_encoding))
+      if ( enc::isColor(image_encoding) || image_encoding == enc::YUV422 || image_encoding == enc::YUV422_YUY2)
       {
         std::string compressed_encoding = message->format.substr(split_pos);
         bool compressed_bgr_image = (compressed_encoding.find("compressed bgr") != std::string::npos);
@@ -160,6 +160,9 @@ void CompressedSubscriber::internalCallback(const CompressedImage::ConstSharedPt
 
           if ((image_encoding == enc::BGRA8) || (image_encoding == enc::BGRA16))
             cv::cvtColor(cv_ptr->image, cv_ptr->image, CV_BGR2BGRA);
+
+          if ((image_encoding == enc::YUV422) || (image_encoding == enc::YUV422_YUY2))
+            cv_ptr->encoding = enc::BGR8;
         } else
         {
           // if necessary convert colors from rgb to bgr
@@ -171,6 +174,9 @@ void CompressedSubscriber::internalCallback(const CompressedImage::ConstSharedPt
 
           if ((image_encoding == enc::RGBA8) || (image_encoding == enc::RGBA16))
             cv::cvtColor(cv_ptr->image, cv_ptr->image, CV_RGB2RGBA);
+
+          if ((image_encoding == enc::YUV422) || (image_encoding == enc::YUV422_YUY2))
+            cv_ptr->encoding = enc::RGB8;
         }
       }
       if (message->format.find("jpeg") != std::string::npos && enc::bitDepth(image_encoding) == 16) {
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

No branches or pull requests

1 participant