Getting errors loading my trained SVM when switching from OpenCv 2.4.8 to 3.3.0
When trying to compile a people detection cpp code based on my own hog trained SVM. I've got some errors
The compilation was aborted in the part where I was loading the XML file of my trained SVM indicating that the LineraSVM has no member named load.
What has changed in OpenCV 3.3 regarding the SVM training and loading? Do I have to make some changes to succeed compilation? Or should I redo the hole training process?
Edit 1
I'm using The following Class:
#include "LinearSVM.h"
void LinearSVM::getSupportVector(std::vector<float>& support_vector) const {
int sv_count = get_support_vector_count();
const CvSVMDecisionFunc* df = decision_func;
const double* alphas = df[0].alpha;
double rho = df[0].rho;
int var_count = get_var_count();
support_vector.resize(var_count, 0);
for (unsigned int r = 0; r < (unsigned)sv_count; r++) {
float myalpha = alphas[r];
const float* v = get_support_vector(r);
for (int j = 0; j < var_count; j++,v++) {
support_vector[j] += (-myalpha) * (*v);
}
}
support_vector.push_back(rho);
and Header:
#ifndef LINEAR_SVM_H_
#define LINEAR_SVM_H_
#include "opencv2/core/core.hpp"
#include "opencv2/ml/ml.hpp"
class LinearSVM: public CvSVM {
public:
void getSupportVector(std::vector<float>& support_vector) const;
};
#endif
I did it as mentioned above because I encountered some trouble with the getSupportVector function.
The main code is something like:
#include "LinearSVM.h"
...
int main( int argc, char** argv )
{
LinearSVM svm;
string trained_data="/.../trainedSVM.xml";
const char * td = trained_data.c_str();
svm.load(td);
...
}
Edit 2
Apparently the compiler have problems with the class and header described above, below are the detailed error messages, is it because some functions are no longer there?
expected class-name before ‘{’ token
class LinearSVM: public CvSVM {
^
//src/LinearSVM.cpp: In member function ‘void LinearSVM::getSupportVector(std::vector<float>&) const’:
//src/LinearSVM.cpp:5:45: error: ‘get_support_vector_count’ was not declared in this scope
int sv_count = get_support_vector_count();
^
//src/LinearSVM.cpp:6:11: error: ‘CvSVMDecisionFunc’ does not name a type
const CvSVMDecisionFunc* df = decision_func;
^
//src/hog_detection/src/LinearSVM.cpp:7:28: error: ‘df’ was not declared in this scope
const double* alphas = df[0].alpha;
^
//src/LinearSVM.cpp:9:35: error: ‘get_var_count’ was not declared in this scope
int var_count = get_var_count();
^
/src/LinearSVM.cpp:13:44: error: ‘get_support_vector’ was not declared in this scope
const float* v = get_support_vector(r);
^
...
In file included from //src/detection_hog_svm.cpp:7:0:
/src/LinearSVM.h:6:31: error: expected class-name before ‘{’ token
class LinearSVM: public CvSVM {
^
//detection_hog_svm.cpp: In function ‘int main(int, char**)’...‘class LinearSVM’ has no member named ‘load’
svm.load(td);
Thanks!