Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在文件中保存/读取数据数组(C+;+;)_C++_Arrays_Pointers_Opencv_Writefile - Fatal编程技术网

C++ 如何在文件中保存/读取数据数组(C+;+;)

C++ 如何在文件中保存/读取数据数组(C+;+;),c++,arrays,pointers,opencv,writefile,C++,Arrays,Pointers,Opencv,Writefile,我正在使用一个代码,从图像中计算SIFT描述符。我必须处理视频中的每一帧,并存储每个计算描述符的序列。对于每个图像,描述符由两个数组组成: Frames = (double*)realloc(Frames, 4 * sizeof(double)* nframes); Descr = (vl_uint8*)realloc(Descr, 128 * sizeof(vl_uint8)* nframes); 如何将这两个数组的序列保存到文件中,然后从文件中恢复这些数据(视频的每一帧)?尝试查找fwr

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

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

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

尝试查找fwrite和frad

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

编辑:

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

#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];
    }
}
#包括
#包括
#包括
void writeDescriptors(){
流输出的std::of(“C:\\descriptors.txt”,std::ios::binary);
对于(int i=1;i在Google中搜索“C/C++中的二进制IO”。在web上搜索“C++序列化图像”可能存在重复@Mgetz OP要求的是,您必须将多个图像存储为文件,而不是单个图像,因此我不会将其称为重复。Thomas对序列化有很好的想法。@marol OP要求的基本内容是将二进制数据保存到文件中。这是一个重复文件。写入应该有效,而读取呢?只是“反向”而已算法,比如std::ifstream?对我来说很好,+1。用这句话编辑答案怎么样?