Ask Your Question
0

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

asked Jul 7 '0

AibohphobiA gravatar image

updated Jul 7 '0

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.

Preview: (hide)

4 answers

Sort by » oldest newest most voted
2

answered Jul 12 '0

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.

Preview: (hide)
0

answered Jul 13 '0

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: https://docs.microsoft.com/en-us/wind...

Preview: (hide)
0

answered Jul 14 '0

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

Preview: (hide)
0

answered Jul 7 '0

berak gravatar image

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

COLOR_YUV2BGR_UYVY

instead

Preview: (hide)

Comments

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

berak gravatar imageberak (Jul 7 '0)edit

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

AibohphobiA gravatar imageAibohphobiA (Jul 8 '0)edit

Question Tools

1 follower

Stats

Asked: Jul 7 '0

Seen: 3,361 times

Last updated: Jul 12 '20