Ask Your Question
0

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

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

AibohphobiA gravatar image

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

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
2

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

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
0

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

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...

edit flag offensive delete link more
0

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

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
0

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

berak gravatar image

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

COLOR_YUV2BGR_UYVY

instead

edit flag offensive delete link more

Comments

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

berak gravatar imageberak ( 2020-07-07 08:17:28 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 2,371 times

Last updated: Jul 12 '20