Ask Your Question
2

Accessing LibSVM through Visual Studio 2010 and C++

asked 2013-06-14 01:42:33 -0600

Heshan Sandeepa gravatar image

updated 2013-06-14 06:54:25 -0600

hi , I am using pure LibSVM for my OCR app instead of OpenCV inbuilt one(CVSVM). I download the LibSVM and test it with Command Prompt and it works fine. Now i want to access libsvm train, predict and other functions through my visual c++ project. I have followed "Building Windows Binaries" instructions in LibSVM README file. Here what i did,

  1. set the environment variables of VC++
  2. nmake -f Makefile.win clean all

all above steps were succeeded. But still i have no idea about how to link those svm-train.exe, svm-predict.exe applications or svm.h,svm.cpp files with my visual c++ project. what should i do after "Building Windows Binaries" . does any one has experience with that or can anyone give some suggestions to me? Please Help.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
3

answered 2013-06-14 02:21:39 -0600

updated 2013-06-14 02:39:15 -0600

I am currently working with LibSVM, Visual Studio 2010 and C++.

What I did is the following:

  1. Copy and paste svm.h and svm.cpp into my Visual Studio project. I am currently using versión 3.1 (#define LIBSVM_VERSION 310)

  2. Maybe you need to include "#pragma once" directive to cause the current source file to be included only once in svm.h file, and #include "StdAfx.h" in the svm.cpp file. (At least is what i did).

  3. In order to access to svm-train.c, svm-scale.c and svm-predict.c what i did is the following. I carefully copy the code of these files into one file "svmutils". And then what i did is to eliminate the main function of each one. But you must do the same functionality that is done in the main functions. For example, in the main funtion of the svm-train.c the code is something like this:

 int main(int argc, char **argv)
 {
 ...
 parse_command_line(argc, argv, input_file_name, model_file_name);
 ...
 model = svm_train(&prob,&param);
 ...
 }

You must change this, because if you want to call svm_train function inside your program, you don't have argc, or argv parameters.

EDIT

I you want to call "grid.py" file inside your project in order to find the best svm parameters (cross-validation, and so on), you can do something like this:

void findBestSVMParameters(string fileResult){
    char grid[] = "./tools/grid.py";
    _spawnl(P_WAIT,"C:\\Python27\\python.exe","C:\\Python27\\python.exe", grid, file_result.c_str(), NULL);
}

where fileResult is the file with the operator scale data.

edit flag offensive delete link more

Comments

hi albertofernandez - thank you very much for your effort and consideration of my question. i will follow those and let you know the result. thank you very much.

Heshan Sandeepa gravatar imageHeshan Sandeepa ( 2013-06-14 06:56:06 -0600 )edit

e-mail me if you have any problems. I'll try to answer you.

albertofernandez gravatar imagealbertofernandez ( 2013-06-14 06:57:52 -0600 )edit

Hi, albertofernandez I want to do the same thing but i don't understand how to access svm-predict.c from my cpp program without system call. can you help me out of that

hriddo gravatar imagehriddo ( 2017-08-05 04:29:21 -0600 )edit
0

answered 2013-07-10 05:22:48 -0600

Dear

I'm trying to use the train.c and predict.c of Libsvm in a my work. but i'm not an expert programmer and i'm not understanding how i can use them. I want to the following:

1) To train using a file that I save the data in libsvm format 2) To create a model from the traing file 3) To test (to predict) in real time the new data present in a my dynamic array.

Can you help me please? Thank you

edit flag offensive delete link more

Comments

hi Frank80 , i also tried to modify those .c files in my project. but it didnt work. so that i decided to use those train, scale and predict exe's outside of my project and invoke those exe's using system() function to my project. its easier than worrying about c files.

Heshan Sandeepa gravatar imageHeshan Sandeepa ( 2013-07-11 06:50:27 -0600 )edit

Question Tools

Stats

Asked: 2013-06-14 01:42:33 -0600

Seen: 4,724 times

Last updated: Jul 10 '13