Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Iam doing an project based on opencv and SVM (support vector machines). In there in order to identify user shown gesture i need to do the classification using SVM. I have added svm.cpp and svm.h files to my project and below is my code for the prediction part.

C++
svm_node x[featureVectorSize];

// inside a loop
for(int k;0 < featureVectorSize; k++)
{
    x[k].index = k+1;
    x[k].value = FeatureVectorVal[k]; // i have a vector to store feature values for test data    //(without scaling)
}

    svm_model* newmodel = svm_load_model("Mymodels\\A.scale.model");
    double *ProbVal = new double[1];
    double result = svm_predict_probability(newmodel,x,ProbVal);
    cout<<"result "<< result<<"\n";
    cout<<"ProbVal "<< *ProbVal<<"\n";
    svm_free_model_content(newmodel); 
    svm_free_and_destroy_model(&newmodel);


C++
//some code to show output


Q1. when i do the classification with model A it always gives matching result value as -1. That means not matching with the test data. After that i have hardcoded the scaled feature values for test data (write above FeatureVectorVal to a text file and scale using scale.exe which is provided by the Libsvm package). Then i did the prediction with the same model.Now it gave me result as +1. So that means i have to input scaled test data to svm_node structure. But in svm.cpp i couldn't find any function for scaling my test data. How can i scale my test data using svm.cpp functions?

Q2. When i do prediction with more than one model (using a array of model file paths) program crashes after prediction with first model and prompt me to ;

C++
if ((model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) &&
	    model->probA!=NULL && model->probB!=NULL)


line in svm.cpp file.

Need help guys..Thanks in advance :-)
Posted
Updated 18-Aug-13 5:17am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900