OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作
生活随笔
收集整理的這篇文章主要介紹了
OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
OpenCV學(xué)習(xí)筆記(四):XML,YAML(.txt,.doc)文件讀寫操作
一、Write_XML_and_YAML_File(寫入XML)
#include <opencv2/opencv.hpp> #include <time.h>using namespace cv;int main() {// 1、準(zhǔn)備文件寫操作FileStorage fs("F:/C++/2. OPENCV 3.1.0/TEST/test.txt", FileStorage::WRITE);// 2、開始文件寫入fs << "frameCount" << 5;// 3、寫入時(shí)間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、寫入隨機(jī)數(shù)for (int i = 0; i < 3; i++){int x = rand() % 640; // 生成 640 隨機(jī)數(shù) xint y = rand() % 480; // 生成 640 隨機(jī)數(shù) yfs << "{:" << "x" << x << "y" << y << "lbp" << "[:";uchar lbp = rand() % 256; // 生成 256以內(nèi) 隨機(jī)數(shù) lbp//fs << "lbp" <<i<<lbp;for (int j = 0; j < 8; j++)fs << ((lbp >> j) & 1); // lbp 值右移 j 位(位運(yùn)算)fs << "]" << "}";}fs << "]";fs.release();printf("\n文件讀寫完畢,請(qǐng)?jiān)诠こ棠夸浵虏榭瓷傻奈募");getchar();return 0; }運(yùn)行結(jié)果:
1.寫操作
二、Read_XML_and_YAML_File(讀取XML)
2.讀操作:
總結(jié)
以上是生活随笔為你收集整理的OpenCV学习笔记(四):XML,YAML(.txt,.doc)文件读写操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QT学习笔记(一):VS2013 +QT
- 下一篇: asp.net ajax控件工具集 Au