1

I was trying to write YUV420 buffer to jpg image by the code snippet below:

cv::Mat yuvImg;

yuvImg.create(dec.GetHeight() * 3 / 2, dec.GetWidth(), CV_8UC3);
memcpy(yuvImg.data, yuvBuf, dec.GetHeight() * 3 / 2 * dec.GetWidth() * sizeof(unsigned char));
cv::Mat rgbImg;
cv::cvtColor(yuvImg, rgbImg, CV_YUV2BGR_I420);

char img_path[100];
sprintf(img_path, "decoded_imgs/%d.jpg", frame_cnt++);
cv::imwrite(img_path, rgbImg);

But the resultant images are apparently not correct:

enter image description here

I would appreciate it very much if any advice could be provided!!

Jiang Wenbo
  • 469
  • 2
  • 9
  • 20

0 Answers0