Ask Your Question

Revision history [back]

Does SparseMat accept large indices?

I did:

FileStorage fsp("sparse.yml", FileStorage::WRITE);

fsp << "image";

fsp << sparse_mat;

and have got the file content:

%YAML:1.0

image: !!opencv-sparse-matrix

sizes: [ 10000, 729000 ]

dt: u

data: [ 145, 0, 1, 45, 1, -1, 245, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 39, 1, 40, 1, 41, 1, 42, 1, 43, 1, 44, 1, 45, 1, 46, 1, 47, 1, 48, 1, 49, 1, 50, 1, 84, 1, 85, 1, 86, 1, 87, 1, 88, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 1, 94, 1, 95, 1, 129, 1, 130, 1, 131, 1, 132, 1, 133, 1, 134, 1, 135, 1, 136, 1, 137, 1, 138, 1, 139, 1, 140, 1, -1, 246, 135, 1, 136, 1, 137, 1, 138, 1, 139, 1, 140, 1, 174, 1, 175, 1, 176, 1, 177, 1, 178, 1, 179, 1, 180, 1, 181, 1, 182, 1, ...

The matrix contains only 1 in some elements (unsigned char format). So far as I understand, the file should be filled by triplets: 2 indices + value. 145, 0, 1 looks fine. Further - complete nonsense. In any case -1 shouldn't be here. I blame large indices (see 'sizes:'). Mat simply crashes with such numbers. The program aborts at start. SparseMat works, but this way. May it be the reason and what is the limit for sizes?