这篇文章主要介绍了opencvcv::mat中的数据按行列写入txt文件中,需要的朋友可以参考下
在使用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(); 
}
相关推荐:
opencv cv.mat与.txt文件数据的读写操作
以上就是opencvcv::mat中的数据写入txt文件中的详细内容。
   
 
   