convert big yml data

前端 未结 1 2012
孤城傲影
孤城傲影 2021-01-28 17:11

There is any other way/trick to store the depth map in the database? Basically, we are trying to store 300000 double values. If it helps we can convert the array into a NSMutabl

相关标签:
1条回答
  • 2021-01-28 17:41

    You can save a lot of memory by storing the raw binary data in a BLOB.

    If you don't have fixed rows and cols of your matrix, you can put at the beginning of the file two integers for rows and cols.

    I'll add a simple example on how to save and load the data of matrix, preceded by rows and cols.

    #include <opencv2/opencv.hpp>
    #include <fstream>
    
    using namespace cv;
    using namespace std;
    
    int main()
    {
        Mat1d m = (Mat1d(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
        Mat1d n;
    
        {
            ofstream ofs("test.bin", fstream::binary);
            ofs.write((char*)&m.rows, sizeof(int)); // Save rows
            ofs.write((char*)&m.cols, sizeof(int)); // Save cols
            ofs.write((char*)m.data, m.total()*sizeof(double)); // Save data
        }
    
        {
            ifstream ifs("test.bin", fstream::binary);
            int rows, cols;
            ifs.read((char*)&rows, sizeof(int)); // Load rows
            ifs.read((char*)&cols, sizeof(int)); // Load cols
    
            n = Mat1d(rows, cols); // Resize the matrix according to rows, cols
            ifs.read((char*)n.data, rows*cols*sizeof(double)); // Load data
        }
    
        // Now m and n are equal
        return 0;
    }
    

    If you need further compression you can read and write the stream using gzstream

    0 讨论(0)
提交回复
热议问题