Data in Opencvcv::mat is written in TXT file

Source: Internet
Author: User
This article mainly introduces the data in Opencvcv::mat to write TXT file by row and column, the need for friends can refer to the following

In the process of using OPENCV for image processing, it is often involved in reading the data in the file into the Cv::mat, or writing the data in the Cv::mat to a TXT file.

Here is a list of the methods I used to write the data in Cv::mat to a TXT file, as shown in the code:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.