Reputation: 1
I have to export matrices from Matlab to OpenCV. I use the yaml format and then read the file in OpenCV with cv::FileStorage modelFile
, and store the data in cv::Mat
variables. For normal 2D Matrices, it works fine. But, for one of my big 4D Matrix, I get errors that the string is too long. The Matrix has the size of 16|16|70409|8.
Does someone know a good way to store it? Maybe it is only a format problem.
The code is:
for i = 1:matrixSize(1)
for j=1:matrixSize(2)
fprintf( file, ' - [');
for a = 1:matrixSize(3)
for b = 1:matrixSize(4)
fprintf( file, '%.6f', A(i,j,a,b));
if(a ~= matrixSize(3))
fprintf( file, ',');
end
end
end
fprintf( file, ']\n');
end
end
Thanks
Upvotes: 0
Views: 467
Reputation: 1
my solution is to use instead of yaml, save the model in binary format and then read it with the normal fread functions. Of course you have to know the size of each matrices.
fileID = fopen(BinModel,'w');
fwrite(fileID,[size(model.nSegs),0,0],'uint32'); % size of the matrix
fwrite(fileID,model.nSegs,'uint8'); % matrix data
The file shrinks from 1.4 GB to 200 MB.
Saludo
Upvotes: 0