Ask Your Question

YUV422(16bit) to RGB(24bit) conversion

asked 2020-07-07 03:37:39 -0500

AibohphobiA gravatar image

updated 2020-07-07 03:56:21 -0500

supra56 gravatar image

Hi All, I am trying to convert a yuv422(16 bit) image to RGB(or BGR, 24 bit), with little success so far. My code is as follows:

cv::Mat rgb(input->Height(), input->Width(), CV_8UC2, (char*)input->GetData());
cv::Mat webimg(workingImage->Height(), workingImage->Width(), CV_8UC3, workingImage->GetData());
cv::cvtColor(rgb, webimg, CV_YUV2RGB_UYVY);

The coloring I am getting is way off(mostly green and purple like one of those old MTV clips) C:\fakepath\Capture.JPG

Any help would be appreciated.

edit retag flag offensive close merge delete

4 answers

Sort by » oldest newest most voted

answered 2020-07-12 01:28:57 -0500

AibohphobiA gravatar image

After battling with the conversion(and trying to do it manually) I decided to try a few other types out. Eventually, cv::cvtColor(rgb, webimg, CV_YUV2BGR_YUY2); provided me with a successful conversion.

Hope this helps anyone in the future.

edit flag offensive delete link more

answered 2020-07-12 19:47:15 -0500

Based on what you described, I think your YUV422 image is of YUV2 format, that’s why the CV_YUV2RGB_UYVY didn’t work. There are two different formats of YUV422, you can get more details here:

edit flag offensive delete link more

answered 2020-07-14 07:59:38 -0500

I decided to try out a couple of other types. Finally, cv::cvtColor(rgb, webimg, CV YUV2BGR YUY2); supported a good conversion for me;

edit flag offensive delete link more

answered 2020-07-07 08:14:53 -0500

berak gravatar image

opencv uses BGR pixel ordering, not RGB. so you would need



edit flag offensive delete link more


please also do not use outdated CV_XXX constants, but one of those

berak gravatar imageberak ( 2020-07-07 08:17:28 -0500 )edit

Hi berak, thanks for your answer. Unfortunately, it didn't change the image much - I am still getting wrong colors.

AibohphobiA gravatar imageAibohphobiA ( 2020-07-08 02:21:01 -0500 )edit

Question Tools

1 follower


Asked: 2020-07-07 03:37:39 -0500

Seen: 635 times

Last updated: Jul 12 '20