Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is cv::imread able to load huge files?

Hi,

I'm using cv::imread to read a 10GB PGM file, but I'm getting the following error:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Is cv::imread unable to load images this size? Is there an alternative in the OpenCV library?

Is cv::imread able to load huge files?

Hi,

I'm using cv::imread to read a 10GB PGM file, but I'm getting the following error:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

The machine running this has 64GB RAM, most of it currently free. The ulimit -a yelds the following output.

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 515986
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 515986
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Here's the program I wrote.

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char* args[])
{
    if (argc != 2)
    {
        return 1;
    }

    cv::Mat img = cv::imread(args[1], cv::IMREAD_GRAYSCALE);
    if (img.data == 0)
    {
        return 2;
    }

    std::cout << img.rows << " - " << img.cols;

    return 0;
}

Is cv::imread unable to load images this size? Is there an alternative in the OpenCV library?