YUYV -> RGB conversion

Hello,

I have image frames incoming from a camera in the YUYV color space, and want to convert these frames to RGB. I’m currently using the color conversion code enum cv::COLOR_YUV2RGB_YUYV to do the conversion. However, the red and blue channels in the resulting image are switched for me, meaning a red object in the scene is appearing as blue and vice versa. It seems the data buffer in the converted image is laid out as B1 G1 R1 B2 G2 R2 B3 G3 R3, etc, where Ri, Gi, Bi are the RGB values for the ith pixel.

It seems I need to use cv::COLOR_YUV2BGR_YUYV to get the buffer layout in Ri, Gi, Bi order. That’s what I see others also do to make the YUYV->RGB conversion work:

I wondered if this has something to do with OpenCV storing RGB images in BGR layout, so I tried feeding BayerRG8 images from the camera to my application, and used the cv::COLOR_BayerRG2RGB conversion code. This time, the converted image was indeed in the RGB layout, meaning the pixels were laid out in the data buffer of the converted Mat object in Ri, Gi, Bi order.

Is this a bug in OpenCV w.r.t. the YUYV->RGB conversion, or am I missing something?

Thanks.