2016-06-15 2 views
0

OpenCVでFileStorageクラスを使用してYAMLファイルを出力したいとします。現在のところ、YAML出力には正しい字下げがありません。 以下は.cppコードです。YAMLインデントOpenCV

FileStorage fs("detectionOutput.yml", FileStorage::WRITE) 
Mat face_detect(Mat img, int count, cv::VideoWriter face_writer) 
{ 
    Rect r; 
    Mat detected_face; 
    CascadeClassifier face_cascade; 
    face_cascade.load("cascades_orig.xml"); 

    std::vector<Rect> faces; 
    face_cascade.detectMultiScale(img, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30)); 

    numOfValidRegion=0; 
    for(int i = 0; i < faces.size(); i++) 
    { 
     r.x = faces[i].x; 
     r.y = faces[i].y; 
     r.width = faces[i].width; 
     r.height = faces[i].height; 
     rectangle(img, r, Scalar(0, 255, 255), +2, 4, 0);  
    Rect large_face; 



    large_face.x = faces[i].x ; 
    large_face.y = faces[i].y ; 
    large_face.width = faces[i].width; 
     large_face.height = faces[i].height; 


    detected_face = img(large_face); 
     string path1 = prepare_path("output_ppm/face", count, i); 

     string tmpStr2; 
     stringstream ssFrameID; 
     ssFrameID << curFrameNo; 
     stringstream ssRegionID; 
     ssRegionID << i; 
     tmpStr2 = "frame"+ ssFrameID.str()+"region"+ssRegionID.str(); 
     fs << tmpStr2 << ""; 
     fs << "numPts" << 2; 
     Mat tmpMat(2,2,DataType<int>::type); 
    tmpMat.at<int>(0,0) = large_face.x ; // TLx 
     tmpMat.at<int>(0,1) = large_face.y ; // TLy 
     tmpMat.at<int>(1,0) = large_face.x + large_face.width ; // BRx 
     tmpMat.at<int>(1,1) = large_face.y + large_face.height ; // BRy 
     fs << "matPts" << tmpMat; 
     fs << "attribute" << "head"; 
     numOfValidRegion++; 
    } 
    string tmpStr; 
    stringstream ss; 
    ss << curFrameNo; 
    tmpStr = "frame"+ss.str()+"numValidRegions"; 
    fs << tmpStr << numOfValidRegion; 
    return img; 
} 

以下は、私が正しいインデントで次の出力をしたい現在のYAML出力

frame0Region0: "" 
numPts: 2 
matPts: !!opencv-matrix 
    rows: 2 
    cols: 2 
    dt: i 
    data: [ 1156, 336, 1206, 386 ] 
attribute: head 
frame0Region1: "" 
numPts: 2 
matPts: !!opencv-matrix 
    rows: 2 
    cols: 2 
    dt: i 
    data: [ 1112, 376, 1181, 445 ] 
attribute: head 
frame0Region2: "" 
numPts: 2 
matPts: !!opencv-matrix 
    rows: 2 
    cols: 2 
    dt: i 
    data: [ 1177, 385, 1252, 460 ] 
attribute: head 
frame0Region3: "" 
numPts: 2 
matPts: !!opencv-matrix 
    rows: 2 
    cols: 2 
    dt: i 
    data: [ 140, 310, 245, 415 ] 
attribute: head 
frame0numValidRegions: 4 

であると私は(frame0Region0: "")の前に二重引用符を望んでいないが、私は二重引用符を削除するときに表示さエラー。

frame0region0: 
    numPts: 2 
    matPts: !!opencv-matrix 
     rows: 2 
     cols: 2 
     dt: i 
     data: [ 1156, 336, 1206, 386 ] 
    attribute: head 
frame0region1: 
    numPts: 2 
    matPts: !!opencv-matrix 
     rows: 2 
     cols: 2 
     dt: i 
     data: [ 1112, 376, 1181, 445 ] 
    attribute: head 
frame0region2: 
    numPts: 2 
    matPts: !!opencv-matrix 
     rows: 2 
     cols: 2 
     dt: i 
     data: [ 1177, 385, 1252, 460 ] 
    attribute: head 
frame0region3: 
    numPts: 2 
    matPts: !!opencv-matrix 
     rows: 2 
     cols: 2 
     dt: i 
     data: [ 140, 310, 245, 415 ] 
    attribute: head 
frame0numValidRegions: 4 

答えて

0

YAMLは左から右に読んで、そう""frame0Region0キーの後ろに実際にされています。値は空の文字列のスカラーと整数値 `とxyzなどでabc:あなたはそれらの""を削除してから、次の値をインデントする場合

、あなたが実際に完全に意味を変更:

abc: "" 
xyz: 1 

は、2つのキーを定義します。一方:

abc: 
    xyz: 1 

ためくぼみの、キーabcの値がマッピング、xyzされた第1の鍵であると定義します。それは全く異なる構造を持ち、ロードされません。

インデントしなくても""を削除しても、空のスカラ文字列を空のスカラー(C++でNULLポインタとしてロードする)に変更すると、処理ソフトウェアには受け入れられないようです明示的なテスト。