Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

svm java opencv 3

Hi, I am trying to implement BoW model using opencv java, but I am facing an issue while using SVM.Kindly help me to debug it. My code goes as follows

     SVM classifier = SVM.create();
     TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER,100,0.1);
 classifier.setKernel(SVM.LINEAR);
 classifier.setType(SVM.C_SVC);
 classifier.setGamma(0.5);
 classifier.setNu(0.5);
 classifier.setC(1);
 classifier.setTermCriteria(criteria);

 //data is N x 64 trained data Mat , labels is N x 1 label Mat with integer values;
 classifier.train(data, Ml.ROW_SAMPLE, labels);

 Mat results = new Mat();
 int label = (int) classifier.predict(testSamples, results, 0);
return label;

But while excecuting classifier.train() its throwing this error OpenCV Error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses) in cv::ml::SVMImpl::train, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\ml\src\svm.cpp, line 1610owing this error