1.写入:opencv mat(float型)存为bin
std::ofstream fout1("E:/data/flowu_2486x1856.bin", std::ios::binary | std::ios::trunc);
Mat flowU = Mat::zeros(2486, 1856, CV_32FC1);
for (int i = 0; i < flowU.h; i++)
{
for (int j = 0; j < flowU.w; j++)
{
fout1.write(reinterpret_cast<char*>(&flowU.at<float>(i, j)), sizeof(float));
}
}
fout1.close();
2.读取bin到opencv mat(float型)中
FILE* fp = fopen("E:/data/flowu_2486x1856.bin", "rb");
Mat flowU = Mat::zeros(2486, 1856, CV_32FC1);
for (int i = 0; i < 1856; i++)
{
for (int j = 0; j < 2486; j++)
{
fread(&flowU.at<float>(i, j), 1, sizeof(float), fp);
}
}
fclose(fp);
fp = NULL;
|