本帖最后由 mayingjie116 于 2013-05-15 11:48:07 编辑

解决方案 »

  1.   


    哥哥我知道了教给你CvMat* mat = cvCreateMat( 3, 3, CV_32F );
    CvMat *mat1=cvCreateMat(3,3,CV_64FC3);
    cvSetIdentity(mat1);
    CvFileStorage* fs = cvOpenFileStorage( "c:\\example.xml", 0, CV_STORAGE_WRITE );
        cvSetIdentity( mat );
         cvWrite( fs, "A", mat, cvAttrList(0,0) );
    // cvWrite(fs,"B",mat1,cvAttrList(0,0));
        cvReleaseFileStorage( &fs );
    CvFileStorage* fs1 = cvOpenFileStorage( "c:\\example.xml", 0, CV_STORAGE_APPEND );//这么简单就是这里CV_STORAGE_APPEND     //cvSetIdentity( mat );
        // cvWrite( fs1, "A", mat, cvAttrList(0,0) );
     cvWrite(fs1,"B",mat1,cvAttrList(0,0));
     
        cvReleaseFileStorage( &fs1 );
     
        cvReleaseMat( &mat );
    cvReleaseMat(&mat1);
    //读取 
    CvMat *mata=cvCreateMat(3,3,CV_32F);
    CvMat *matb=cvCreateMat(3,3,CV_64FC3); CvFileStorage *fs_read;
    fs_read=cvOpenFileStorage("c:\\example.xml",0,CV_STORAGE_READ);
    //mata=(CvMat*)cvReadByName(fs_read,NULL,"A",NULL);
    matb=(CvMat*)cvReadByName(fs_read,NULL,"B",NULL);
    int a=12;
    for(int row=0;row<matb->rows;row++){
    double *pd_row_start=(double *)(matb->data.ptr+row*(matb->step));
    for(int col=0;col<matb->cols;col++){
    double *pd_data=pd_row_start+col*3;
    printf("%3.2f   ",*pd_data);
    printf("%3.2f   ",*(pd_data+1));
    printf("%3.2f   ",*(pd_data+2));
    }

    printf("\n %d\n",row);
    } cvReleaseFileStorage(&fs_read);
    cvReleaseMat(&mata);
    cvReleaseMat(&matb);
         return 0;