我使用的是从图像计算SIFT描述符的代码。我必须处理视频中的每一帧,并存储每个计算出的描述符的序列。对于每个图像,描述符由两个数组组成:
Frames = (double*)realloc(Frames, 4 * sizeof(double)* nframes);
Descr = (vl_uint8*)realloc(Descr, 128 * sizeof(vl_uint8)* nframes);如何将这两个数组的序列保存到文件中,然后从文件中恢复这些数据(针对视频的每一帧)?
发布于 2015-01-28 03:49:29
您可以使用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-28 00:45:07
尝试查找fwrite和fread。
如果您有可变数量的帧(Nframe),使用文件中的前2*4字节来存储文件包含的确切数量的帧可能会有所帮助。
编辑:http://www.cplusplus.com/reference/cstdio/fwrite/
https://stackoverflow.com/questions/28175464
复制相似问题