Hello everyone, basically I have this code:
cout << "extracting histograms in the form of BOW for each Training image " << endl;
Mat labels(0, 1, CV_32S);
int dictSize = 1500;
Mat trainingData(0, dictSize, CV_32S);
int k = 0;
vector<KeyPoint> keypoint;
Mat bowDescriptor;
Mat img;
vector<String> fn;
glob("C:/Users/albma/Desktop/Università/Computer Vision/Final_Project/training_alberi/*.jpg", fn, true);
//extracting histogram in the form of bow for each image
for (size_t i = 0; i < fn.size(); i++) { //each class having 60 images
printf("Training Image = %s\n", fn[i]);
img = imread(fn[i], 0);
detector->detect(img, keypoint); //detect keypoints
bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors
trainingData.push_back(bowDescriptor);
labels.push_back((int)1); //push labels in a matrix.. 1,2,3,4
}
//SVM Part
Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
printf("Training SVM\n");
Ptr<TrainData> td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM
svm->train(td);
And the last 2 lines gives me the error: OpenCV(4.3.0-pre) Error: Assertion failed ((layout == ROW_SAMPLE && responses.rows == nsamples) || (layout == COL_SAMPLE && responses.cols == nsamples)) in cv::ml::TrainDataImpl::setData
What could be the problem?