3

以下は私のコードです。これは正常に動作していますが、長い処理の後、実行時エラーが表示されます

// Initialize constant values
const int nb_cars = files.size();
const int not_cars = files_no.size();
const int num_img = nb_cars + not_cars; // Get the number of images
// Initialize your training set.
cv::Mat training_mat(num_img,dictionarySize,CV_32FC1);
cv::Mat labels(0,1,CV_32FC1);

std::vector<string> all_names;

all_names.assign(files.begin(),files.end());
all_names.insert(all_names.end(), files_no.begin(), files_no.end());

// Load image and add them to the training set
int count = 0;
vector<string>::const_iterator i;
string Dir;
for (i = all_names.begin(); i != all_names.end(); ++i)
{
    Dir=( (count < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);

    Mat row_img = cv::imread( Dir +*i, 0 );

    detector.detect( row_img, keypoints);

    RetainBestKeypoints(keypoints, 20); // retain top 10 key points

    extractor->compute( row_img, keypoints, descriptors_1);

    //uncluster.push_back(descriptors_1);
    descriptors.reshape(1,1);

    bow.add(descriptors_1);

    ++count;
}

int count_2=0;
vector<string>::const_iterator k;
Mat vocabulary = bow.cluster();
dextract.setVocabulary(vocabulary);


for (k = all_names.begin(); k != all_names.end(); ++k)
{
    Dir=( (count_2 < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);

    row_img = cv::imread( Dir +*k, 0 );

    detector.detect( row_img, keypoints);

    RetainBestKeypoints(keypoints, 20);

    dextract.compute( row_img, keypoints, descriptors_1);

    descriptors_1.reshape(1,1);

    training_mat.push_back(descriptors_1);

    labels.at< float >(count_2, 0) = (count_2<nb_cars)?1:-1;

    ++count_2;
}

エラー :

OpenCv Error : Formats of input argument do not match() in unknown function , file ..\..\..\src\opencv\modules\core\src\matrix.cpp, line 652

ここに画像の説明を入力

descriptor_1SVM の行に再形成するために 2 番目のループを作成しましたが、エラーが解決されません

4

2 に答える 2

0

クラスの数よりも少ない機能でクラスター化しようとしていると思います。

各画像からより多くの画像または 10 を超える記述子を取得できます。

于 2013-08-28T10:53:21.190 に答える
0

3日後にエラーがラベル付けにあることがわかった限り、画像にラベルを付けるとエラーが発生しました。上記の答えは、少ない数の画像を使用してもエラーが発生することにも関連していますが、私の場合、これは理由ではなく、エラーを行ごとにチェックし始めると、エラーはここから始まります:

labels.at< float >(count_2, 0) = (count_2<nb_cars)?1:-1;

行のため:

Mat labels(0,1,CV_32FC1);

それ以外の :

Mat labels(num_img,1,CV_32FC1);

そして私は使うべきです

my_img.convertTo( training_mat.row(count_2), CV_32FC1 );
于 2013-08-29T16:55:10.730 に答える