Ask Your Question
0

YUYV422 to BGR

asked 2016-02-08 23:55:16 -0500

Bilityuk gravatar image

updated 2016-02-09 00:19:05 -0500

Good morning! Can anybody help me to convert between YUYV422 and BGR pixel formats?

1) This way i load the pixel data: cv::Mat cameraFrame = cv::Mat(h, w,CV_8UC3,(char*)YUYV422_data); 
2) i need to convert cv::Mat YUYV422  to cv::Mat BGR 
3) after processing i need to convert cv::Mat BGR to (char*)YUYV422_data.

Thank you!

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
4

answered 2016-02-09 04:10:02 -0500

See the function cvtColor with the following (undocumented) flag: COLOR_YUV2RGB_Y422 which is the same as COLOR_YUV2RGB_UYVY. If you need other flags, don't hesitate to have a look at imgproc.hpp which shows all of them.

// Convert from yuv to rgb
cv::cvtColor( yuv, rgb, COLOR_YUV2RGB_UYVY );
// Convert from rgb to yuv
cv::cvtColor( rgb, yuv, COLOR_RGB2YUV );
edit flag offensive delete link more

Comments

Thank you it works for me

Bilityuk gravatar imageBilityuk ( 2016-02-09 21:28:29 -0500 )edit
1

answered 2018-11-06 13:23:01 -0500

To build on Mathieu Barnachon's earlier answer, looking through opencv2/imgproc.hpp is key. When using webcams, a common format is YUYV 4:2:2. (Apparently in the Windows world that format is known as YUY2.) To convert that format to BGR which can then be used natively in OpenCV, you want to use the ColorConversionCodes enum COLOR_YUV2BGR_YUYV which is actually an alias for COLOR_YUV2BGR_YUY2.

cv::Mat bgr_mat;
cv::cvtColor(camera_mat, bgr_mat, cv::COLOR_YUV2BGR_YUYV);

If you plan on using the mat in OpenCV, remember to convert to BGR, not RGB.

For additional details on the format, look up fourcc YUYVor see https://www.linuxtv.org/downloads/v4l...

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-02-08 23:55:16 -0500

Seen: 2,613 times

Last updated: Nov 06