0

ウェブカメラ経由で取得した画像から、testdata という単一の浮動ベクトルを取得しようとしています。画像が単一の浮動ベクトルに変換されると、トレーニング済みのニューラル ネットワークに渡されます。ネットワークをテストするには、float CvANN_MLP::predict 関数を使用します。 (定数 Mat& 入力、Mat& 出力)。この関数には、次の形式のテスト サンプルが必要です。

入力ベクトルの浮動小数点行列、行ごとに 1 つのベクトル。

testdata ベクトルは次のように定義されます:-

// define testing data storage matrices
//NumberOfTestingSamples is 1 and AttributesPerSample is number of rows *number of columns

Mat testing_data = Mat(NumberOfTestingSamples, AttributesPerSample, CV_32FC1);

画像の各行を CSV 形式で保存するには、次のようにします。

Formatted row0= format(Image.row(0),"CSV" ); //Get all rows to store in a single vector
Formatted row1= format(Image.row(1),"CSV" ); //Get all rows to store in a single vector
Formatted row2= format(Image.row(2),"CSV" ); //Get all rows to store in a single vector
Formatted row3= format(Image.row(3),"CSV" ); //Get all rows to store in a single vector

次に、row0 から row3 に保存されたすべての書式設定された行を次のようにテキストファイルに出力します。

store_in_file<<row0<<", "<<row1<<", "<<row2<<", "<<row3<<endl;

これにより、マット全体が 1 行に格納されます。

テキストファイルが閉じられます。同じテキストファイルを再度開いて、ベクター testdata に格納するデータを抽出します

 // if we can't read the input file then return 0

 FILE* Loadpixel = fopen( "txtFileValue.txt", "r" );

 if(!Loadpixel) // file didn't open
{
    cout<<"ERROR: cannot read file \n";
    return 0; // all not OK;
}
for(int attribute = 0; attribute < AttributesPerSample; attribute++)
{
            fscanf(Loadpixel, "%f,",&colour_value);//Reads a single attribute and stores it in colour_value
            testdata.at<float>(0, attribute) = colour_value;
}

これは機能しますが、しばらくするとファイルが開かず、「エラー: ファイルを読み取れません」というエラー メッセージが表示されます。画像(マット)を単一の浮動小数点ベクトルに格納する最良の方法はtestdata.at<float>(0, attribute)何ですか? または、ファイルが常に開かれるようにする簡単な方法はありますか?基本的に問題を修正しますか?

4

1 に答える 1