Home > Mobile >  Convert YUV frames to RGB
Convert YUV frames to RGB

Time:11-07

I'm trying to convert YUV file(UYUV, YUV 422 Interleaved,BT709) to RGB with C . I've took the example from here: enter image description here

I was able to do the conversion using the following python code:

    with open(input_name, "rb") as src_file:
        raw_data = np.fromfile(src_file, dtype=np.uint8, count=img_width*img_height*2)
        im = raw_data.reshape(img_height, img_width, 2)

        rgb = cv2.cvtColor(im, cv2.COLOR_YUV2RGB_UYVY)

And this is the result: enter image description here

CodePudding user response:

The problem was that UYVY is 2 bytes, so I have to double the size of the image. Now with thelines

int iYUV_Size = iSize.width * iSize.height * 2; 
Mat mSrc_YUV420(cv::Size(iSize.width, iSize.height),CV_8UC2);

it works well.

Thanks, @micka for the help!

  • Related