The data in OpenCVcv::Mat is written to the txt file

不言
Release: 2018-05-03 13:56:53
Original
2689 people have browsed it

This article mainly introduces how the data in OpenCVcv::Mat is written into a txt file in rows and columns. Friends who need it can refer to it

In the process of using opencv for image processing, it is often involved Read the data in the file into cv::Mat, or write the data in cv::Mat into a txt file.

The following is a method I commonly use to write data in cv::Mat into a txt file. See the code for details:

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(); 
}
Copy after login

Related recommendations:

OpenCV cv.Mat and .txt file data reading and writing operations

The above is the detailed content of The data in OpenCVcv::Mat is written to the txt file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template