to train SVM classifier i use features extracted from different images ( each image have number of features =! of other images beacause i use SLIC classifier and from each region i extract 20 features) after preparing the TraingMatData and LabelsMat i got this bugwhith a notification : Microsoft C++ exception: cv::Exception at memory location 0x000000E5176E2740. I couldn't understand what's the wrong in my code here's my code and i'm waiting your helps.) whith a notification : Microsoft C++ exception: cv::Exception at memory location 0x000000E5176E2740. I couldn't understand what's the wrong in my code here's my code and i'm waiting your helps.
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);
// ...