Mat写入txt文件
void saveMat(Mat I, string path)
{
ofstream matFile;
matFile.open(path, ios::out);
if (!matFile.fail())
{
for (int i = 0; i < I.rows; i++)
{
for (int j = 0; j < I.cols; j++)
{
matFile << I.at<double>(i, j) << "\t";
}
matFile << std::endl;
}
}
matFile.close();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
从txt文件读入Mat
Mat readMat(string path)
{
ifstream fin(path);
Mat gray(333, 65, CV_64FC1);
for (int i = 0; i < gray.rows; i++)
{
for (int j = 0; j < gray.cols; j++)
{
double a;
fin >> a;
gray.at<double>(i, j) = a;
}
}
return gray;
}