您的位置:首页 > 运维架构

【OpenCV3】cv::Mat中的数据按行列写入txt文件中

2017-05-11 16:29 573 查看
在使用opencv进行图像处理的过程中,经常会涉及到将文件中的数据读入到cv::Mat中,或者将cv::Mat中的数据写入到txt文件中。

下面就介绍一种我常用的将cv::Mat中的数据写入到txt文件中的方法,具体见代码:

void writeMatToFile(cv::Mat& m, const char* filename)
{
std::ofstream fout(filename);

if (!fout)
{
std::cout << "File Not Opened" << std::endl;
return;
}

for (int i = 0; i<m.rows; i++)
{
for (int j = 0; j<m.cols; j++)
{
fout << m.at<float>(i, j) << "\t";
}
fout << std::endl;
}

fout.close();
}


2017.05.11
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencv txt文件读写