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
This commit is contained in:
anandkaranubc 2024-12-09 22:21:25 -08:00 committed by GitHub
parent 0dfc5d416f
commit d85c13bcbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,10 +41,12 @@
//M*/
#include "precomp.hpp"
#include <opencv2/core/utils/logger.hpp>
#include <stdarg.h>
#include <ctype.h>
/****************************************************************************************\
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;
}
}
}
}