Home > Software engineering >  Convert raw YUV422 image to RGB
Convert raw YUV422 image to RGB

Time:10-02

I have a raw image in a yuv422 encoding that I extracted from a csi_camera on my Jetson Nano and I want to convert it to RGB encoding to use for machine learning. How would I go about it? I've tried using different cvtColor codes in OpenCV but resulting images were still a mess. Is there a way to turn this image to a "normal" color?

Here is the image: csi_image

CodePudding user response:

So I finally figured out how to convert the image with the following code:

for (rosbag::MessageInstance const m : rosbag::View(bag)) {
// Read only the input topic
if(m.getTopic() == topic) {
  // Create an image pointer to the bag file image messages
  sensor_msgs::ImageConstPtr imgPtr = m.instantiate<sensor_msgs::Image>();
  // Extract the image frame with yuv422 encoding
  image = cv_bridge::toCvCopy(imgPtr, "yuv422")->image;
  // Convert the image frame to a BGR format image
  cvtColor( image, newimage, COLOR_YUV2BGRA_YUY2 );

  // Write the new image to the out path
imwrite(final_path, newimage);
  count  ;
}
}

I had to add the toCvCopy(imgPtr, “yuv422”)-> to specify the incoming encoding first, then convert to using the YUY2 enum.

  • Related