我正在编写一个程序,该程序从两个单独文件中的两个表创建一个查找表。当我阅读第一张表格时,一切都被正确阅读。但是,当我阅读第二个文件时,fopen
似乎并没有打开整个文件。
我这样说是因为编译器实现了_iobuf
文件结构,并且_cnt
似乎_cnt = 530
比第一次初始化时( )低了很多( _cnt ~ 4096
),并且当我从文件中读取时它会减小。
这是我的代码片段:
int vertical,horizontal,channels,count;
FILE *fp;
fp = fopen(filename,"r");
if(fp==NULL){
cout << "File not found" << endl;
return Mat();
}else{
cout << "Opening and Reading " << filename << endl;
}
//Read header
fread(&count,4,1,fp);
cout << "ReadHistogram(): Count number is " << count;
if(count!= 5){
cout << "Header file reads: " << count << endl;
return Mat();
}
//Read size
fread(&vertical,4,1,fp);
//cout << "ReadHistogram(): Vertical size:" << vertical <<endl;
fread(&horizontal,4,1,fp);
//cout << "ReadHistogram(): Horizontal size:" << horizontal <<endl;
fread(&channels,4,1,fp);
//cout << "ReadHistogram(): Channel size:" << channels<<endl;
//Create Mat array
int size[] = {vertical, horizontal, channels};
Mat histogram(3,size,CV_64F,Scalar::all(0));
//Read in array
count = 0;
for(int i=0;i<vertical;i++){
for(int j=0;j<horizontal;j++){
for(int k=0;k<channels;k++){
double temp5;
fread(&temp5,8,1,fp);
histogram.at<double>(i,j,k) = temp5;
if(count <= 300){
cout << "Array(" << i+1 << "," << j+1 << "," << k+1 << ")" << "=" << histogram.at<double>(i,j,k) << endl;
cout << "Temp5 is " << temp5 << endl;
}
count++;
}
}
}
cout << "Done reading " << filename << endl;
fclose(fp);
return histogram;
PS:我一直在尝试查找结构_cnt
中的确切内容,但FILE
找不到任何类似的东西。我将不胜感激任何人都可以提供的任何指示。