OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作
生活随笔
收集整理的這篇文章主要介紹了
OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
OpenCV學習筆記(四):XML,YAML(.txt,.doc)文件讀寫操作
一、Write_XML_and_YAML_File(寫入XML)
#include <opencv2/opencv.hpp> #include <time.h>using namespace cv;int main() {// 1、準備文件寫操作FileStorage fs("F:/C++/2. OPENCV 3.1.0/TEST/test.txt", FileStorage::WRITE);// 2、開始文件寫入fs << "frameCount" << 5;// 3、寫入時間time_t rawtime; // 64-bit time valuetime(&rawtime);fs << "calibrationDate" << asctime(localtime(&rawtime));// 4、寫入矩陣Mat cameraMatrix = (Mat_<double>(3, 3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);Mat distCoeffs = (Mat_<double>(5, 1) << 0.1, 0.01, -0.001, 0, 0);fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs;fs << "features" << "[";// 5、寫入隨機數for (int i = 0; i < 3; i++){int x = rand() % 640; // 生成 640 隨機數 xint y = rand() % 480; // 生成 640 隨機數 yfs << "{:" << "x" << x << "y" << y << "lbp" << "[:";uchar lbp = rand() % 256; // 生成 256以內 隨機數 lbp//fs << "lbp" <<i<<lbp;for (int j = 0; j < 8; j++)fs << ((lbp >> j) & 1); // lbp 值右移 j 位(位運算)fs << "]" << "}";}fs << "]";fs.release();printf("\n文件讀寫完畢,請在工程目錄下查看生成的文件~");getchar();return 0; }運行結果:
1.寫操作
二、Read_XML_and_YAML_File(讀取XML)
2.讀操作:
總結
以上是生活随笔為你收集整理的OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QT学习笔记(一):VS2013 +QT
- 下一篇: 设计模式--观察者模式