训练SVM分类器后,在准备TraingMatData和LabelsMat后,我使用了从不同图像中提取的特征(每个图像具有特征数量=!其他图像,因为我使用SLIC superpixeland从每个区域中提取了20个特征) 3}}发出通知:Microsoft C ++异常:内存位置0x000000E5176E2740的cv :: Exception。我不明白我的代码有什么问题,这是我的代码,我在等待您的帮助。
int main()
{
/// training
cv::Mat image;
//load the features from files
Mat trainingDataMat(47,27000, CV_32FC1);
float features[1350][20];
float labels[47] = {-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,... i delet the rest of them};
vector<int> size;
for (int i = 1; i < 48; i++) {
vector<float> numbers;
//Mat features(1200, 20, CV_32FC1);
string filename = "D:\\mémoire\\training\\trainingData\\featuers";
filename = filename + std::to_string(i);
filename = filename + ".txt";
int size_e = 0;
//read(numbers, filename);
ifstream in(filename);
float number;
string aa;
while (in.good()) {
getline(in, aa, ',');
number = strtod(aa.c_str(), NULL);
numbers.push_back(number);
size_e = size_e + 1;
//features.push_back(number);
}
in.close();
size.push_back(size_e);
int pp = numbers.size()/ 20;
int d = 0;
for (int p = 0; p < 1350; p++) {
for (int p1 = 0; p1 < 20; p1++) {
if (pp <= d) {
features[p][p1] = 0;
}
else {
//features.at<uchar>(p, p1) = numbers[d];
features[p][p1] = numbers[d];
d++;
}
}
}
cv::Mat A(1350, 20, CV_32FC1, features);
trainingDataMat.push_back(A.reshape(1, 1));
}
Mat labelsMat(47, 1, CV_32FC1, labels);
//////////////////////////////////////////////////////////////////////////////////////////////////////
//seting the SVM
Ptr<ml::SVM> svm = ml::SVM::create();
// edit: the params struct got removed,
svm->setType(ml::SVM::C_SVC);
svm->setKernel(ml::SVM::RBF);
svm->setGamma(100);
//Mat trainData; // one row per feature
svm->train(trainingDataMat, ml::ROW_SAMPLE, labelsMat);
// ...