每行4个数据,这个应该是你记事本显示的效果。根据你所给的xml文件的描述,你保存的是一个1行,10304列的矩阵。
保存的数据格式,OpenCV默认就哪携是保存成这样的薯神精度的,你可以在载入这个矩阵后,自己舍入到你数缓亏所需要的有效位数。
1.写XMl文件,void CrecognitionDlg::storeDirectoryFaces(){
CvFileStorage * fileStorage
fileStorage = cvOpenFileStorage( "directoryInfo.xml", 0, CV_STORAGE_WRITE )
cvWriteInt( fileStorage, "nFaces", indexFaces.size() )
cvStartWriteStruct(fileStorage, "CVFaceRecog", CV_NODE_MAP)
for (size_t i=0i<indexFaces.size()i++)
{
char person[100]
sprintf( person, "person_%d", (i+1) )//必须区分开,否则读的时候会出问题
cvStartWriteStruct(fileStorage,person, CV_NODE_MAP)
cvWriteInt( fileStorage, "index", indexFaces.at(i) )
cvWriteString(fileStorage, "name", namePerson.at(i))
cvWriteString(fileStorage, "directory", pathFaces.at(i))
cvEndWriteStruct(fileStorage)
}
cvEndWriteStruct(fileStorage)
cvReleaseFileStorage( &fileStorage )
}
写完的内容如下:
<?xml version="1.0"?>
<opencv_storage>
<nFaces>3</nFaces>
<CVFaceRecog>
<person_1>
<index>0</index>
<name>aaa</name>
<directory>C:\Pictures\kobe</directory></person_1>
<person_2>
<index>1</index>
<name>bbb</name>
<directory>C:\Pictures\Li</directory></person_2>
<person_3>
<index>2</index>
<name>ccc</name>
<directory>C:\Pictures\Sun</directory></person_3></CVFaceRecog>猜羡
</opencv_storage>
2.读XML
int CrecognitionDlg::loadDirectoryFaces(){
CvFileStorage * fileStorage = NULL
int i
CvSeq* seq
CvSeqReader reader
fileStorage = cvOpenFileStorage( 陆燃"directoryInfo.xml", 0, CV_STORAGE_READ )
if( !fileStorage ) {
return 0
}
namePerson.clear()
pathFaces.clear()
indexFaces.clear()
CvFileNode* root = cvGetRootFileNode( fileStorage, 0)
CvFileNode* data = cvGetFileNodeByName( fileStorage, root, "CVFaceRecog" )
seq = data->data.seq
cvStartReadSeq( seq, &reader, 0 )
int nFaces = cvReadIntByName( fileStorage, 0, "nFaces", 0 )
for(i = 0 i < nFaces i++)
{
CvFileNode *pt = (CvFileNode*)reader.ptr
namePerson.push_back(cvReadStringByName(fileStorage, pt, "name", 0))
pathFaces.push_back(cvReadStringByName(fileStorage, pt, 早兆虚"directory", 0))
indexFaces.push_back(cvReadIntByName(fileStorage,pt,"index",0))
CV_NEXT_SEQ_ELEM(seq->elem_size, reader)
}
cvReleaseFileStorage( &fileStorage )
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)