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
can you show, how you build your 'labels' array ?
Thanks I got the mistake. I original kept the data type of label as 32FC1 . Now I changed it to 32SC1. Now it works :)
^^ ah, that looks ok now.
still, curious about how you handle the BOW training. (i don't think, that you can use opencv's BOWKMeansTrainer or such.)
I didnt use any inbuilt function for BoW , but implemented manually , using features and kmeans, and then saving the histograms in text file
^^ ahh, ok, makes a lot of sense.
( i was just asking, because some months ago, we tried to wrap the BowKmeansTrainer to opencv's scripting, and failed due to some warts in the java feature2d api. so - good, you found your own way doing so !)
Can u send the complete code for svm in java