0

I'm learning OpenCV, in C++ but Something got wrong..

I want to imshow yuv file, but I got an error on my code.

code :

Mat img = imread("myimage.yuv"); imshow("img", img);

Does anyone know what's wrong with my code and how can I fix it?

  • 1
    Does this answer your question? [How to read a frame from YUV file in OpenCV?](https://stackoverflow.com/questions/2231518/how-to-read-a-frame-from-yuv-file-in-opencv) – rayryeng Sep 16 '20 at 20:40

1 Answers1

0

You need to open the file first :

FILE *YUV_FILE = fopen( "YourPAth\\YourFileName.yuv", "rb" );

create a pointer :

char *databuffer = new char[ frameWidth*frameHeight*ChannelCount];

Then read data using fread to the pointer databuffer

Now you'll be able to create an opencv Mat using :

 cv::Mat OpencvImage(Size(frameWidth, frameHeight), CV_8UC3, databuffer, Mat::AUTO_STEP);
Ziri
  • 718
  • 7
  • 16