Getting errors loading my trained SVM when switching from OpenCv 2.4.8 to 3.3.0 [closed]

asked 2017-10-26 06:39:03 -0600

Jas92 gravatar image

updated 2017-10-26 09:59:18 -0600

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/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!

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-20 09:16:07.654683

Comments

show (the relevant portion of) your code, please.

(and yes, there are API changes 2.4 -> 3.3)

berak gravatar imageberak ( 2017-10-26 06:55:07 -0600 )edit

Thanks for your comment @berak , I updated my question please check it out!

Jas92 gravatar imageJas92 ( 2017-10-26 08:16:30 -0600 )edit

" is it because some functions are no longer there?" -- exactly ! please see here for SVM and here for the HOGDescriptor .

try again, and report back.

berak gravatar imageberak ( 2017-10-26 10:01:48 -0600 )edit

Thanks @break , sadly I don't have enough points to upvote your comment, I will try to upgrade the code and report any further issues.

Jas92 gravatar imageJas92 ( 2017-10-26 11:28:09 -0600 )edit

oh, hell, not more karma ;)

but yea, if you could do a short writeup, what you had to change from 2.4 -> 3.3, that would be very helpful to others !

berak gravatar imageberak ( 2017-10-26 11:31:27 -0600 )edit
1

If I succeed in this upgrade I will share the changes for sure :).

Jas92 gravatar imageJas92 ( 2017-10-26 11:54:17 -0600 )edit