OpenCV中的cv::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; ifor (int j = 0; jfout << m.at(i, j) << \"\\"; }fout << std::endl; }
fout.close(); }
以上所述是⼩编给⼤家的OpenCVcv::Mat中的数据按⾏列写⼊txt⽂件中实例代码,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,在此也⾮常感谢⼤家对⽹站的⽀持!