0

我正在使用从图像计算 SIFT 描述符的代码。我必须处理视频中的每一帧并存储每个计算描述符的序列。对于每个图像,描述符由两个数组组成:

Frames = (double*)realloc(Frames, 4 * sizeof(double)* nframes); 
Descr = (vl_uint8*)realloc(Descr, 128 * sizeof(vl_uint8)* nframes);

如何将这两个数组的序列保存在文件中,然后从文件中恢复这些数据(对于视频的每一帧)?

4

2 回答 2

2

您可以使用ofstream写入文件。下面的代码可能无法直接使用,应该指向正确的方向。

#include <fstream>
#include <iterator>
#include <algorithm>

void writeDescriptors() {

    std::ofstream output( "C:\\descriptors.txt", std::ios::binary );
    for ( int i = 1 ; i < Frames.size(); i++ )
    {
        out << ",  " << Frames[i];
    }
}

为了读回描述符,只需使用 ifstream 并反转算法

于 2015-01-27T19:49:28.647 回答
0

尝试寻找 fwrite 和 fread。

如果您有可变数量的帧 (nframes),则使用文件中的前 2*4 字节存储文件包含的确切帧数可能会有所帮助。

编辑: http ://www.cplusplus.com/reference/cstdio/fwrite/

于 2015-01-27T16:45:06.830 回答