0

I recorded an uncompressed / un-encoded video in yuv format using camera of my raspberry pi. I want to read each frame as an image and also count the total number of frames of the video.

I found this answer : How to read a frame from YUV file in OpenCV? But it looks old and doesn't seem to work.

Do I have to convert yuv video to some other format first to read each frame. How should I go about it?
Which tool will be better for this, OpenCV or Matlab or some other?

Community
  • 1
  • 1
Coderaemon
  • 3,619
  • 6
  • 27
  • 50
  • If it does not work, please explain the issue. It might be a minor issue simple to fix. Matlab file exchange (http://www.mathworks.com/matlabcentral/fileexchange) contains several submissions regarding YUV. – Daniel Feb 24 '15 at 08:52

1 Answers1

1

I think OpenCV can read YUV frames from a video file, because the underlying media handler layer (i.e. FFmpeg) does the job.

Furthermore, OpenCV also supports the conversion between YUV and BGR through cv::cvtColor() with CV_YCrCb2RGB or CV_RGBYCrCb.

Does the following code work for your videos?

cv::VideoCapture cap("PATH_TO_YUV");
if (!cap.isOpened())
{
    std::cout << "Failed to open file: " << "PATH_TO_YUV" << std::endl;
    return -1;
}

cv::Mat frame;
while(true)
{
    cap >> frame;

    if (frame.empty())             
        break;

    cv::imshow("YUV frame", frame);
    cv::waitKey(1);
}
Community
  • 1
  • 1
Kornel
  • 5,264
  • 2
  • 21
  • 28