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