Ask Your Question

Revision history [back]

OpenCV 3.2 vs OpenCV 2.4.11 SVM trainer files and predict

I was wondering if the predict function, trainer files trained in 2.4 are incompatible with OpenCV 3.2

in this code below:

        svm->kernel->calc(sv_total, svm->var_count, svm->sv.ptr<float>(), row_sample, buffer);

which calls

   case SVM::RBF:
        calc_rbf(vcount, var_count, vecs, another, results);

which is:

void calc_rbf( int vcount, int var_count, const float* vecs,
                   const float* another, Qfloat* results )
    {
        double gamma = -params.gamma;
        int j, k;

        for( j = 0; j < vcount; j++ )
        {
            const float* sample = &vecs[j*var_count];
            double s = 0;

            for( k = 0; k <= var_count - 4; k += 4 )
            {
                double t0 = sample[k] - another[k];
                double t1 = sample[k+1] - another[k+1];

                s += t0*t0 + t1*t1;

                t0 = sample[k+2] - another[k+2];
                t1 = sample[k+3] - another[k+3];

                s += t0*t0 + t1*t1;
            }

            for( ; k < var_count; k++ )
            {
                double t0 = sample[k] - another[k];
                s += t0*t0;
            }
            results[j] = (Qfloat)(s*gamma);
        }

        if( vcount > 0 )
        {
            Mat R( 1, vcount, QFLOAT_TYPE, results );
            exp( R, R );
        }
    }

It seeks like buffer or my samples obtained are different in percision comparing opencv 3.2/2.4