OpenCV中将Mat,vector类型存为txt格式

C++: FileStorage::FileStorage(const string& source, int flags, const string& encoding=string())

Parameters:
  • source – Name of the file to open or the text string to read the data from. Extension of the file (.xml or .yml/.yaml) determines its format (XML or YAML respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml.yml etc.).你要创建的文件的名字和类型
  • flags –

    Mode of operation. Possible values are:

    • FileStorage::READ Open the file for reading.
    • FileStorage::WRITE Open the file for writing.
    • FileStorage::APPEND Open the file for appending.
    • FileStorage::MEMORY Read data from source or write data to the internal buffer (which is returned by FileStorage::release)
  • encoding – Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.
FileStorage cp("calipara.txt",FileStorage::WRITE);
cp<<"intrinsic"<<intrinsic;
cp<<"DistCoefs"<<distCoeffs;
cp<<"rotation_matrix"<<rotation_matrix;
cp<<"trans_vec"<<cameraCalibrator.tvecs;
cp.release();

直接就是上面的代码,用FileStorage,就行了。想换成.xml格式则把后缀.txt改成.xml就可以了。

放上效果图

猜你喜欢

转载自blog.csdn.net/qq_27931977/article/details/82994188
今日推荐