2
votes

I recently started using OpenCV for a project involving reading videos. I followed tutorials online for video's reading and the video seems to be read with no problems. However, when I display any frame from the video, the far right column appears to be corrupted. Here is the code I used for reading and displaying the first frame.

VideoCapture cap("6.avi");
Mat frame;
cap>>frame;
imshow("test",frame);
waitKey(0);

This resulted in a frame that looks good for the most part except the far right column. See here.

I am making no modifications to the video or frames before displaying it. Can anyone help figure out why this is happening?

Note: I'm running Ubuntu 14.04, OpenCV version 2.4.8

Full video can be found here.

1
You'll need to at least attach a sample video which reproduces the problem. Also, provide more details on version of OpenCV and OS this is happening with. - Dan Mašek
There's definitely something wonky. Can't open it with OpenCV here, but if I export the second frame using VLC, it matches yours -- except for those 6 columns on the right hand side, which I see correctly. Interesting observation: Codec is MJPEG, which uses 8x8 blocks; video is 150x100 -- 150 is not divisible by 8, but 144 is. Looks like a bug in a codec with decoding frames with width not multiple of 8. If you had OpenCV 3.x, I'd say try different VideoIO backend, but I don't think that's available in 2.4.x - Dan Mašek

1 Answers

1
votes

Your code looks fine to me. Are you certain the frame is corrupted? Resize, maximize, minimize the "test" GUI window to see if the right edge is still corrupted. Sometimes while displaying really small images, I've seen the right edge of the GUI window display incorrectly even though the frame is correct. You could also try imwrite("test.png",frame) to see if the saved image is still corrupted.

If this doesn't help, it would seem like a codec problem. Ensure you have the latest version of opencv, ffmpeg.

If this still doesn't help, the video itself may be corrupted. You could try converting it into another format using ffmpeg