Imread fails on a large (1GB) PGM file

asked 2015-01-13 08:09:35 -0500

Josh gravatar image

I'm trying to load some large images into OpenCV, I have a ~gigapixel image taken from the HiRISE project. The files are in JP2 format which open fine in OS X Preview, but seem to crash both Jasper and OpenJPEG - and hence also crash OpenCV.

I've managed to convert them to PGM using Kakadu (see above, every other package crashes), but then I get an assertion failure (the file begins loading as I can see RAM usage going through the roof):

Assertion failed: (isOpened() && pos >= 0), function setPos, file /tmp/opencv-LZGjtm/opencv-2.4.9/modules/highgui/src/bitstrm.cpp, line 167

I assume the file is being opened, due to the RAM usage, so it looks like pos is the thing that's failing?

An example:

Is this likely to be a malformed image or something like lack of RAM? The link above contains a representative image so it should be possible to verify this (ideally on a machine with 8GB+ RAM).

edit retag flag offensive close merge delete


opencv is not really good at handling xxxl images.

pos is an int, i guess, you simply overflow 31 bits there (and end up with a negative value).

berak gravatar imageberak ( 2015-01-13 08:37:35 -0500 )edit

Ok, that makes sense - I know OpenCV is capable of outputting quite large images so I did wonder. Though it's only around 1.3GPx so that shouldn't overflow 31 bits?

Any suggestion on a library which I could use (aside from simply writing a handler for pgm as it's not complicated)?

Josh gravatar imageJosh ( 2015-01-13 10:43:06 -0500 )edit