2016-03-22 2 views
0

、次のようになります。読み取りデータ - OpenCVの私は.ymlファイル形式のデータを持っている

%YAML:1.0 
rotMatrix1: 
- !!opencv-matrix 
    rows: 3 
    cols: 1 
    dt: d 
    data: [ -2.3829520379560337e-01, -3.7857313177578661e-01, -1.2002438267340013e-01 ] 
- !!opencv-matrix 
    rows: 3 
    cols: 1 
    dt: d 
    data: [ -1.9532717166408006e-01, -1.9842197713512208e-01, -2.4142492122139054e-02 ] 
- !!opencv-matrix 
    rows: 3 
    cols: 1 
    dt: d 
    data: [ 7.0848561493555007e-02, -1.5300625945509461e-01, -2.2789227495909796e-03 ] 
- !!opencv-matrix 
    rows: 3 
    cols: 1 
    dt: d 
    data: [ -6.4432249078642076e-02, 2.6156730119463567e-01, -1.0216960054886982e-01 ] 

ファイルは一つだけのノード名(rotMatrix1)が、このノード例えば下の10種類が含まれていますデータが保存されます。 opencvを使用して個々の1x3マトリックスにアクセスするにはどうすればよいですか?私はすでに試した何

は:: CVを使用するFileNodeIteratorですが、私は任意のヘルプ

FileStorage fs(inputData, CV_STORAGE_READ) 
FileNode fn= fs["rotMatrix1"]; 

for(cv::FileNodeIterator it= fn.begin(); it!= fn.end(); ++it) 
{ 
    cv::FileNode node= *it; 
    double data= (double)node 
} 
fs.release(); 

おかげ

に注目しました!

+0

あなたは_exact_ YAMLファイルを投稿することができますか? OpenCVはyamlがフォーマットされていないと言っています – Miki

+0

おそらくコピー&ペーストの問題です。質問の書式設定のためにスペース/タブを削除しないようにしてください – Miki

+0

実際に.ymlファイルは、OpenCVで10個の画像から 'calibrateCamera'機能を使ってカメラ較正を行った後、' cv :: FileStorage'によって作成されます。ファイル全体は[link](http://www.filedropper.com/calib)または[link](http://s000.tinyupload.com/index.php?file_id=07914558306087960523) – nasil122002

答えて

1

ファイルを解析することができます(完全なファイルはコメントでリンクされており、hereが利用可能です)。

私はFileStorageFileNodeFileNodeIteratorの概念に慣れるためのチュートリアルherehereに従うことをお勧めします。私は&があるため、元のファイルといくつかのエンコーディングの問題のため、新しいファイル内のファイルの内容をコピー&ペーストする必要がありました

注意

コード:

#include <opencv2/opencv.hpp> 
#include <vector> 
using namespace cv; 
using namespace std; 

int main() 
{ 
    FileStorage fs("calib.yml", FileStorage::READ); 

    string time; 
    int calibrationImageWidth; 
    int calibrationImageHeight; 
    int numberOfCrossPointsInWidth; 
    int numberOfCrossPointsInHeight; 
    double squareSize; 
    int numberOfCalibratedImages; 
    Mat cameraMatrix1; 
    Mat distortionCoefficient1; 
    vector<Mat> rotationMatrix1; 
    vector<Mat> translationMatrix1; 

    // Read data 
    FileNode fn_time = fs.root(); 
    time = fn_time["time"]; 

    calibrationImageWidth = fs["calibrationImageWidth"]; 
    calibrationImageHeight = fs["calibrationImageHeight"]; 
    numberOfCrossPointsInWidth = fs["numberOfCrossPointsInWidth"]; 
    numberOfCrossPointsInHeight = fs["numberOfCrossPointsInHeight"]; 
    squareSize = fs["squareSize"]; 
    numberOfCalibratedImages = fs["numberOfCalibratedImages"]; 

    fs["cameraMatrix1"] >> cameraMatrix1; 
    fs["distortionCoefficient1"] >> distortionCoefficient1; 

    FileNode fn_rot = fs["rotationMatrix1"]; 
    FileNodeIterator fn_rot_it = fn_rot.begin(), fn_rot_it_end = fn_rot.end(); 
    for (; fn_rot_it != fn_rot_it_end; ++fn_rot_it) 
    { 
     Mat tmp; 
     (*fn_rot_it) >> tmp; 

     rotationMatrix1.push_back(tmp.clone()); 
    } 

    FileNode fn_tr = fs["translationMatrix1"]; 
    FileNodeIterator fn_tr_it = fn_tr.begin(), fn_tr_it_end = fn_tr.end(); 
    for (; fn_tr_it != fn_tr_it_end; ++fn_tr_it) 
    { 
     Mat tmp; 
     (*fn_tr_it) >> tmp; 

     translationMatrix1.push_back(tmp.clone()); 
    } 

    return 0; 
} 
+0

でダウンロードできます!今は完全に動作します。 – nasil122002

+0

うれしかったよ!答えとして記入してください – Miki

関連する問題