Ask Your Question
1

Unsupported format or combination of formats (Invalid matrix type)

asked 2013-02-15 04:22:33 -0600

snikolenko gravatar image

updated 2013-02-15 04:23:30 -0600

I'm trying to use the boosting library from openCV for a relatively large dataset (30M rows, 30 cols). When creating the matrix, I get the following error:

OpenCV Error: Unsupported format or combination of formats (Invalid matrix type) in cvCreateMatHeader, file /home/snikolenko/distr/OpenCV-2.4.3/modules/core/src/array.cpp, line 117

I've looked into array.cpp and added a debug output there:

int min_step = CV_ELEM_SIZE(type)*cols;
std::cout << "\tcvCreateMatHeader: type=" << type << "\tcols=" << cols << "\tmin_step=" << min_step << std::endl;

Turned out that the min_step variable was overflowing:

    cvCreateMatHeader: type=0   cols=17 min_step=17
    cvCreateMatHeader: type=4   cols=19 min_step=76
    cvCreateMatHeader: type=4   cols=600000000  min_step=-1894967296
OpenCV Error: Unsupported format or combination of formats (Invalid matrix type) in cvCreateMatHeader, file /home/snikolenko/distr/OpenCV-2.4.3/modules/core/src/array.cpp, line 119
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/snikolenko/distr/OpenCV-2.4.3/modules/core/src/array.cpp:119: error: (-210) Invalid matrix type in function cvCreateMatHeader

(note the strange number of columns -- my dataset has 30M rows but the matrix wants to get 600M cols)

I've tried to change int to uint64_t, hoping to simply avoid overflows but got the following very strange behaviour:

    cvCreateMatHeader: type=0   cols=17 min_step=17
    cvCreateMatHeader: type=4   cols=19 min_step=76
    cvCreateMatHeader: type=4   cols=600000000  min_step=18446744071814584320
OpenCV Error: Insufficient memory (Failed to allocate 18446744069919617044 bytes) in OutOfMemoryError, file /home/snikolenko/distr/OpenCV-2.4.3/modules/core/src/alloc.cpp, line 52
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/snikolenko/distr/OpenCV-2.4.3/modules/core/src/alloc.cpp:52: error: (-4) Failed to allocate 18446744069919617044 bytes in function OutOfMemoryError

Now this I really don't understand since 600M times 4 is only 2.4G, which surely should fit into uint64_t.

What am I doing wrong? I can post my boosting code, but it does work correctly for smaller datasets.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-02-17 13:28:16 -0600

Guanta gravatar image

I came to the same limitation once and I still don't know why it happened. Obviously OpenCV has problems with very large matrices.

A solution which solved my problem: Creating the space by yourself:

float data = new float[rows*cols]

and creat a new matrix-header on top of the float array:

cv::Mat1f blub(rows, cols, data)
edit flag offensive delete link more
0

answered 2013-02-17 13:35:18 -0600

berak gravatar image

sounds like it's related to this:

http://code.opencv.org/issues/2004#note-6

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-02-15 04:22:33 -0600

Seen: 5,181 times

Last updated: Feb 17 '13