Ask Your Question

How should I read MPO Multi-jpeg files?

asked 2013-08-12 16:17:23 -0500

xaffeine gravatar image

updated 2013-08-13 13:31:40 -0500

I have a 3D digital camera that produces image pairs in the .mpo file format. Each file contains essentially a pair of standard jpeg images, one after another. I know I can manually convert these into separate jpeg files, but that would be cumbersome for large numbers of images.

Since OpenCV contains jpeg-reading code, can anyone suggest a reasonable c++ approach for reading an MPO file and producing two cv::Mat objects?

I've stepped into the imread code and I see that an fopen happens in the private _imread function in loadsave.cpp. That function uses an ImageDecoder object that happens to be a JpegDecoder in my instance.

It looks like I should design to the IJG API or else rely on the ImageDecoder interface which I assume may change in future versions of OpenCV. Is this correct?

edit retag flag offensive close merge delete



That's an interesting problem, and I think it need an extension of VideoCapture to take MPO, not imread. There is some code on Internet to cut MPO into two JPG. By the way, and I know it's not a real solution, but OpenCV opens MPO, only the first image, as the codec detector find it's JPG. I'm interesting to add it to OpenCV, let me know your opinion on the best way to do this.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-08-12 17:04:51 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-08-15 13:24:11 -0500

xaffeine gravatar image

I don't have a good answer, but I have a workaround that should work (until something breaks it).

I wrote my own ReadMpoFIle function loosely based on the logic in the imread_ implementation. To make it work, I had to make a modified version of JpegDecoder, because the released version (2.4.6) of JpegDecoder::readData() calls close. That made it hard to get the decoder into position to decode the second image.

It would be nice to see a more stream-friendly version of the ImageDecoder/JpegDecoder suite. To be stream-friendly, I would say a decoder's core function should take its compressed input from an input iterator.

In fairness of course, OpenCV is a vision library, and not expected to be a comprehensive image file I/O library.

edit flag offensive delete link more

Question Tools


Asked: 2013-08-12 16:17:23 -0500

Seen: 791 times

Last updated: Aug 15 '13