Question

Im trying to setup libsvm in android to detect motion from accelerometer. I have no idea how to setup libsvm in android and how to use it. guys can you give clue for this ?

Was it helpful?

Solution

You do not setup libsvm, simply use the library wrapper for the language you are using to develop an app for android (Java I guess?). Wrapper is included in the official release. And it also includes the sample of usage of this particular library. There is nothing special here - if you know how to develop android app, then using additional library should not be a problem. If you do not know how to develop such an app - then starting from motion recognition is a bad idea. The same applies for ability to use SVM for anything. If you haven't ever used SVM it would be better to start with something simplier, like writing the "non mobile" version of the app and getting familiar with this model. Otherwise, probability of failing is quite big.

OTHER TIPS

Sorry for my previous wrong answer format

Since the libsvm is written in C, you can easily wrap the code via JNI interface and use libsvm in Java.

A wrapper can be found in: https://github.com/yctung/AndroidLibSvm

For example, once you import this project in Android studio, you can call

 jniSvmTrain(String options);

to make the svm training with the same interface of original libsvm.

If you look at the code, it is simply a wrapper of original "svm-train.c" in libsvm

#include "./libsvm/svm-train.h"
// helper function to be called in Java for making svm-train
extern "C" void Java_edu_umich_eecs_androidlibsvm_MainActivity_jniSvmTrain(JNIEnv *env, jobject obj, jstring cmdIn){
    const char *cmd = env->GetStringUTFChars(cmdIn, 0);
    debug("jniSvmTrain cmd = %s", cmd);

    std::vector<char*> v;

    // add dummy head to meet argv/command format
    std::string cmdString = std::string("dummy ")+std::string(cmd);
    cmdToArgv(cmdString, v);

    // make svm train by libsvm
    svmtrain::main(v.size(),&v[0]);

    // free vector memory
    for(int i=0;i<v.size();i++){
        free(v[i]); 
    }   

    // free java object memory 
    env->ReleaseStringUTFChars(cmdIn, cmd);
}

"Setuping" I think you are asking to add the jar file the LIBSVM provide as a library to your android studio project. You can take a look here:

Android Studio: Add jar as library?

In the LIBSVM website you can download a zip file with the JAVA jar file inside and examples of usage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top