c++ - 使用带有 SURF 的 SVM 时出错

标签 c++ opencv image-processing computer-vision svm

下面是我的代码,运行正常,但经过长时间处理后显示运行时错误

// 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

enter image description here

我在第二个循环中制作了 descriptor_1 以 reshape SVM 的行,但错误没有解决

最佳答案

我认为您正在尝试使用比类别数量更少的特征进行聚类。

您可以从每张图片中获取更 multimap 片或超过 10 个描述符。

关于c++ - 使用带有 SURF 的 SVM 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18391673/

相关文章:

c++ - 如何链接到 Visual C++ 2010 中的 .lib 文件?没有引用项目?

java - 为什么int 1的最小值比正值更远离零?

matlab - matlab中的二维卷积——代码优化

python - 如何找到这些有时重叠的圆的中心

c++ - 清除任何交易

c++ - A* bug(A星搜索算法)

python-2.7 - openCV imwrite 写入 0 kb 图像帧

c++ - 检测图像中的文本轮廓

java - 如何找到图像中的局部最大值和最小值

python - 矢量图像的图像比较(基于边缘检测)?