Home > Article > Backend Development > The data in OpenCVcv::Mat is written to the txt file
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(); }
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!