android loadsvm raw,OpenCV for Android - training SVM with SURF descriptors

问题

I need some help in training a SVM for an Android app.

I have a set of images in different classes (12 classes) and got all descriptors from them. I managed to get the same amount of descriptors for each image. What I need is to train a SVM for my android application with those descriptors.

I'm not sure if I should train it in the Android emulator or write a C++ program to train the SVM and then load it in my app (if I use the OpenCV's lib for windows to train the SVM and then save it, will the lib I'm using for Android recognize the saved SVM file?). I guess I shouldn't train the SVM with such big dataset in the emulator.

I've already tested my descriptor's dataset on the SMO of Weka (http://www.cs.waikato.ac.nz/ml/weka/) and got good results, but I need to implement (or use the openCV's) SVM and save it trained for future classification.

回答1:

Here is an example for training your SVM in OpenCV4Android. trainData is a MatOfFloat, the form of which will depend on the method you're using to get feature vectors. To make trainData, I used Core.hconcat() to concatenate the feature vectors for each element of the dataset into a single Mat.

Mat responses = new Mat(1, sizeOfDataset, CvType.CV_32F);

responses.put(0, 0, labelArray); // labelArray is a float[] of labels for the data

CvSVM svm = new CvSVM();

CvSVMParams params = new CvSVMParams();

params.set_svm_type(CvSVM.C_SVC);

params.set_kernel_type(CvSVM.LINEAR);

params.set_term_crit(new TermCriteria(TermCriteria.EPS, 100, 1e-6)); // use TermCriteria.COUNT for speed

svm.train_auto(trainData, responses, new Mat(), new Mat(), params);

I'm fairly sure OpenCV uses the same format to save SVMs in both the Android and C++ interfaces. Of course, you can always train the SVM in Android and save the XML file to your emulator's SD card using something like

File datasetFile = new File(Environment.getExternalStorageDirectory(), "dataset.xml");

svm.save(datasetFile.getAbsolutePath());

then pull it from the SD card and store it in your app's /res/raw folder.

来源:https://stackoverflow.com/questions/16162150/opencv-for-android-training-svm-with-surf-descriptors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值