Ask Your Question
0

How to read image from a buffer of YUV422

asked 2016-12-06 21:50:51 -0600

nistar gravatar image

I have some image data, its format is yuyv(YUV422), and only have its buffer.
I use Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)
and write cv::Mat img = cv::Mat(cv::Size(640,480), CV_8UC2, imgBuffer);
the step is AUTO_STEP, is it correct?

Then I try to change a zone to black ( 0,44,64 en YUV )

for (int i=0; i<50; i++)
{
    for (int j=0; j<50; j++)
    {
        img.at<cv::Vec2b>(j,i)[0]=0;
        if(j%2==0)
            img.at<cv::Vec2b>(j,i)[1]=44;
        else
            img.at<cv::Vec2b>(j,i)[1]=62;
    }
}

But the output color is green, I don't know why? Please, help me

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-07 01:20:35 -0600

pi-null-mezon gravatar image

Seems that AUTO_STEP is right (YUV422 is 16 bit per pixel depth, so CV_8UC2 is the right choice). To operate with image it will be simpler to convert image to RGB colorspace, so I suggest you to make cv::cvtColor( img, rgbimg, COLOR_YUV2RGB_UYVY)

edit flag offensive delete link more

Comments

Hi mezon, I think your answer is correct, at least it helped me. Thank you first. But i still have some confused i don't understand why 16bit per pixel should use CV_8UC2? Why don't use CV_16UC1? Thanks again.

Eric.Dafran gravatar imageEric.Dafran ( 2018-10-10 04:06:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-06 21:50:51 -0600

Seen: 9,384 times

Last updated: Dec 07 '16

Related questions