c++ - Call OpenCV CvSVMParams in Objective-C -


i want implement svm algorithm using opencv in ios can not call methods in objective-c. how call opencv cvsvmparams in objective-c. when tried shows error 'unknown type name cvsvmparams'

edited: understand mistake using old version of opencv fixed that. compiler says

opencv error: assertion failed (samples.cols == var_count && samples.type() == cv_32f) in predict, file /volumes/linux/builds/precommit_ios/opencv/modules/ml/src/svm.cpp, line 1919 libc++abi.dylib: terminating uncaught exception of type cv::exception: /volumes/linux/builds/precommit_ios/opencv/modules/ml/src/svm.cpp:1919: error: (-215) samples.cols == var_count && samples.type() == cv_32f in function predict

#import "customobject.h" #import <opencv2/opencv.hpp> #import <coregraphics/coregraphics.h> #import <uikit/uikit.h>  using namespace cv;  @implementation customobject  - (void) supportvectormachine {  float labels[10] = { 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 }; cv::mat labelsmat(10, 1, cv_32fc1, labels);  float trainingdata[10][2] = { { 100, 10 }, { 150, 10 }, { 600, 200 }, { 600, 10 }, { 10, 100 }, { 455, 10 }, { 345, 255 }, { 10, 501 }, { 401, 255 }, { 30, 150 } };  cv::mat traindatamat(10, 2, cv_32fc1, trainingdata);  //opencv 3.0 ptr<ml::svm> svm = ml::svm::create(); // edit: params struct got removed, // use setter/getter now: svm->settype(ml::svm::c_svc); svm->setkernel(ml::svm::linear); svm->settermcriteria(termcriteria(termcriteria::max_iter, 100, 1e-6));  ptr<traindata> td = traindata::create(traindatamat, row_sample, labelsmat);  //create test features float testdata[2] = { 150, 15 };  cv::mat testdatamat(2, 1, cv_32fc1, testdata);  //predict class labele test data sample float predictlable = svm->predict(testdatamat);  nslog(@"%f", predictlable);  }  end 

problem solved. forgot call train method trained data , change labels float integers.

- (void) supportvectormachine {  int labels[10] = {1, 1, 1}; cv::mat labelsmat(10, 1, cv_32s, labels);  float trainingdata[3][3] = { { 84, 191, 19 }, { 24, 186, 17}, { 22, 157, 21} };  //float trainingdata[10][1] = { 100, 150, 600, 600, 100, 455, 345, 501, 401, 150};  cv::mat traindatamat(3, 3, cv_32fc1, trainingdata);    //opencv 3.0 ptr<ml::svm> svm = ml::svm::create(); // edit: params struct got removed, // use setter/getter now: svm->settype(ml::svm::c_svc); svm->setkernel(ml::svm::linear); svm->settermcriteria(termcriteria(termcriteria::max_iter, 100, 1e-6)); svm->setgamma(3.0);  ptr<traindata> td = traindata::create(traindatamat, row_sample, labelsmat); svm->train(td);  //create test features float testdata[1] = {500};  cv::mat testdatamat(1, 1, cv_32fc1, testdata);  //predict class labele test data sample float predictlable = svm->predict(testdatamat);  nslog(@"%f", predictlable); } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -