@@ -26,6 +26,7 @@ NAN_MODULE_INIT(SVM::Init) {
2626 Nan::SetPrototypeMethod (ctor, " predict" , Predict);
2727 Nan::SetPrototypeMethod (ctor, " getSupportVectors" , GetSupportVectors);
2828 Nan::SetPrototypeMethod (ctor, " getUncompressedSupportVectors" , GetUncompressedSupportVectors);
29+ Nan::SetPrototypeMethod (ctor, " getDecisionFunction" , GetDecisionFunction);
2930 Nan::SetPrototypeMethod (ctor, " calcError" , CalcError);
3031 Nan::SetPrototypeMethod (ctor, " save" , Save);
3132 Nan::SetPrototypeMethod (ctor, " load" , Load);
@@ -139,6 +140,25 @@ NAN_METHOD(SVM::GetUncompressedSupportVectors) {
139140#endif
140141}
141142
143+ NAN_METHOD (SVM::GetDecisionFunction) {
144+ FF_METHOD_CONTEXT (" SVM::GetDecisionFunction" );
145+
146+ if (!info[0 ]->IsNumber ()) {
147+ FF_THROW (" expected arg 0 to be a Int" );
148+ }
149+
150+ FF_OBJ alpha = FF_NEW_INSTANCE (Mat::constructor);
151+ FF_OBJ svidx = FF_NEW_INSTANCE (Mat::constructor);
152+ FF_ARG_INT (0 , int i);
153+ double rho = FF_UNWRAP (info.This (), SVM)->svm ->getDecisionFunction (i, FF_UNWRAP_MAT_AND_GET (alpha), FF_UNWRAP_MAT_AND_GET (svidx));
154+
155+ FF_OBJ ret = FF_NEW_OBJ ();
156+ Nan::Set (ret, FF_NEW_STRING (" rho" ), Nan::New ((double )rho));
157+ Nan::Set (ret, FF_NEW_STRING (" alpha" ), alpha);
158+ Nan::Set (ret, FF_NEW_STRING (" svidx" ), svidx);
159+ FF_RETURN (ret);
160+ }
161+
142162NAN_METHOD (SVM::CalcError) {
143163 FF_METHOD_CONTEXT (" SVM::CalcError" );
144164 FF_ARG_INSTANCE (0 , cv::Ptr<cv::ml::TrainData> trainData, TrainData::constructor, FF_UNWRAP_TRAINDATA_AND_GET);
0 commit comments