// wenjianduxie.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdafx.h" #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, char** argv ) { //1. 将数据写入YAML(或XML) //注意,在OpenCV中,无论读写,文件的格式均由指定的后缀名确定。示例: /* FileStorage fs("test.yml", FileStorage::WRITE); fs << "i" << 5 << "r" << 3.1 << "str" << "ABCDEFGH"; fs << "mtx" << Mat::eye(3,3,CV_32F); fs << "mylist" << "[" << CV_PI << "1+1" << "{:" << "month" << 12 << "day" << 31 << "year" << 1969 << "}" << "]"; fs << "mystruct" << "{" << "x" << 1 << "y" << 2 << "width" << 100 << "height" << 200 << "lbp" << "[:"; const uchar arr[] = {0, 1, 1, 0, 1, 1, 0, 1}; fs.writeRaw("u", arr, (int)(sizeof(arr)/sizeof(arr[0]))); fs << "]" << "}"; */ ///* //1. 将数据读回 这段代码把上面写入文件的数据再读回来。 FileStorage fs("test.yml", FileStorage::READ); int i1 = (int)fs["i"]; double r1 = (double)fs["r"]; string str1 = (string)fs["str"]; Mat M; fs["mtx"] >> M; cout<<M<<endl; FileNode tl = fs["mylist"]; CV_Assert(tl.type() == FileNode::SEQ && tl.size() == 3); double tl0 = (double)tl[0]; string tl1 = (string)tl[1]; int m = (int)tl[2]["month"], d = (int)tl[2]["day"]; int year = (int)tl[2]["year"]; FileNode tm = fs["mystruct"]; Rect r; r.x = (int)tm["x"], r.y = (int)tm["y"]; r.width = (int)tm["width"], r.height = (int)tm["height"]; int lbp_val = 0; FileNodeIterator it = tm["lbp"].begin(); for(int k = 0; k < 8; k++, ++it) lbp_val |= ((int)*it) << k; //*/ cvWaitKey(0); return 0; } |
|
来自: 昵称14216904 > 《opencv》