opencv xml读写
2014-08-13 09:02
225 查看
#include <opencv2/core/core.hpp> #include <iostream> #include <string> #include <time.h> using namespace cv; using namespace std; int main(int argc, char** argv) { if (0)//write { FileStorage fs("test.xml", FileStorage::WRITE); fs << "frameCount" << 5; time_t rawtime; time(&rawtime); fs << "calibrationDate" << asctime(localtime(&rawtime)); 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" << "["; for( int i = 0; i < 3; i++ ) { int x = rand() % 640; int y = rand() % 480; uchar lbp = rand() % 256; fs << "{:" << "x" << x << "y" << y << "lbp" << "[:"; for( int j = 0; j < 8; j++ ) fs << ((lbp >> j) & 1); fs << "]" << "}"; } fs << "]"; fs.release(); } else { FileStorage fs2("test.xml", FileStorage::READ); // first method: use (type) operator on FileNode. int frameCount = (int)fs2["frameCount"]; std::string date; // second method: use FileNode::operator >> fs2["calibrationDate"] >> date; Mat cameraMatrix2, distCoeffs2; fs2["cameraMatrix"] >> cameraMatrix2; fs2["distCoeffs"] >> distCoeffs2; cout << "frameCount: " << frameCount << endl << "calibration date: " << date << endl << "camera matrix: " << cameraMatrix2 << endl << "distortion coeffs: " << distCoeffs2 << endl; FileNode features = fs2["features"]; FileNodeIterator it = features.begin(), it_end = features.end(); int idx = 0; std::vector<uchar> lbpval; // iterate through a sequence using FileNodeIterator for( ; it != it_end; ++it, idx++ ) { cout << "feature #" << idx << ": "; cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; // you can also easily read numerical arrays using FileNode >> std::vector operator. (*it)["lbp"] >> lbpval; for( int i = 0; i < (int)lbpval.size(); i++ ) cout << " " << (int)lbpval[i]; cout << ")" << endl; } fs2.release(); } return 0; }
相关文章推荐
- 【学习OpenCV】xml的读写
- opencv 操作XML,读写数组
- opencv读写xml 、yml文件
- OpenCV教程(42) xml/yaml文件的读写
- Opencv中.xml和.yml读写
- OpenCv的xml读写(opencv教程大全)
- OpenCV FileStorage类读写XML/YML文件
- opencv下XML 文件的读写
- OpenCv的xml读写
- OpenCV FileStorage类读写XML/YML文件
- OpenCV 读写XML
- OpenCV学习——XML的读写
- OpenCV笔记(一)-XML文件读写
- OpenCV FileStorage类读写XML/YML文件
- 利用opencv的FileStorage类实现XML/YAML文件的读写
- 【OpenCV学习】XML的读写
- OpenCV FileStorage类读写XML/YML文件
- opencv下XML 文件的读写 很全滴
- OpenCV FileStorage类读写XML/YML文件
- OpenCV读写xml和yml文件