From d85c13bcbb5b7c866ffbcebbe6e9227cd68ca627 Mon Sep 17 00:00:00 2001 From: anandkaranubc <119553199+anandkaranubc@users.noreply.github.com> Date: Mon, 9 Dec 2024 22:21:25 -0800 Subject: [PATCH] Merge pull request #26587 from anandkaranubc:fix-nu-svc-parameter-check Fix #25812: Add error handling for invalid nu parameter in SVM NU_SVC #26587 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work [Issue #25812](https://github.com/opencv/opencv/issues/25812) - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/ml/src/svm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index 0d62f7858a..3bc01ba8ad 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -41,10 +41,12 @@ //M*/ #include "precomp.hpp" +#include #include #include + /****************************************************************************************\ COPYRIGHT NOTICE ---------------- @@ -1458,9 +1460,10 @@ public: for( j = i+1; j< class_count; j++ ) { int cj = class_ranges[j+1] - class_ranges[j]; - if( nu*(ci + cj)*0.5 > std::min( ci, cj ) ) - // TODO: add some diagnostic + if( nu*(ci + cj)*0.5 > std::min( ci, cj ) ) { + CV_LOG_ERROR(NULL, "Training cases incompatible with nu parameter—try a lower value."); return false; + } } } }