Unsupported format or combination of formats (Invalid matrix type)
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.