Ask Your Question

Phazoozoo's profile - activity

2018-06-22 05:58:45 -0600 received badge  Popular Question (source)
2015-11-13 10:20:14 -0600 commented question Confusing SVM training error

It compiled and ran! My output was not correct, but that could be an issue with my feature extraction. So I still have some things to try to get it working. Thank you very much.

2015-11-12 22:45:09 -0600 commented question Confusing SVM training error

Thanks, I changed the type of classes. I changed trainingDataMat_32.reshape(trainingDataMat_32.cols, 1); to trainingDataMat_32.reshape(1, trainingDataMat_32.rows); TrainingDataMat.cols was not the correct value at all. I am still getting errors, but this time it says "OpenCV error: one of the arguments' values is out of range (the kernel parameter <degree> must be positive)".

2015-11-11 22:48:44 -0600 asked a question Confusing SVM training error

Hello,

I am attempting to use BoW and SVM to match a query image with its class in the training image set. Right now I am only attempting to match the query into one of two classes (either it is or is not the correct class). After extrating features and clustering, I computed histograms for each of the images in the training set. I am trying to use svm->train() with a Mat of the histograms, and a Mat of the class number (1 or 0). The problem I have is this stubborn error.

    "Assertion failed (samples.type() == CV_32F || samples.type == CV_32S) in cv::ml::TrainDataImpl::setData"

I have code to convert the types of both inputs to CV_32F, yet the error persists. I have tried making the conversion in various ways, and declaring the variables in various ways. Nothing I change seems to get rid of the error.

Here is my code. histograms and classes are declared as shown below. This is done before filling them with the data.

Mat histograms(0, numOfClusters, CV_32FC1);
Mat classes(0, 1,CV_32FC1);

    Ptr<ml::SVM> svm = ml::SVM::create();

svm->setType(ml::SVM::C_SVC);
svm->setKernel(ml::SVM::POLY);
svm->setGamma(3);
cout << "params set" << endl;
Mat trainingDataMat(histograms);


Mat trainingDataMat_32;
Mat classes_32;
trainingDataMat.convertTo(trainingDataMat_32, CV_32F);
trainingDataMat_32 = trainingDataMat_32.reshape(trainingDataMat_32.cols, 1); 
svm->train(trainingDataMat_32, ml::ROW_SAMPLE, classes);    //incorrect types? I think it is a problem with ROW_SAMPLE


Mat res;   // output
svm->predict(Qoutput, res);

I am using opencv 3.0.0 with Visual Studio 2013. Any help would be greatly appreciated.

Thanks