直接上代码,研究了好几个小时
FILE *fs = NULL;
int iRet = fopen_s(&fs,"test_yuv420p_320x180.yuv", "rb");
if (0 != iRet)
{
return;
}
unsigned char pSrc[320 * 90 * 3] = { 0 };
int iLen = fread(pSrc, 1, 320 * 90 * 3, fs);
int pixel_h = 180;
int pixel_w = 320;
Mat yuv;
Mat m_color;
yuv.create(pixel_h * 3 / 2, pixel_w, CV_8UC1);
memcpy(yuv.data, pSrc, pixel_w * pixel_h * 3 / 2 * sizeof(unsigned char));
cvtColor(yuv, m_color, cv::COLOR_YUV2RGB_I420);
imshow("image", m_color);