Conversation
31a6514 to
fe843a3
Compare
|
@vpisarev please take a look on the patch. |
modules/ml/test/test_knearest.cpp
Outdated
|
|
||
| TEST(ML_KNearest, bug_11877) { | ||
| Mat trainData = (Mat_<float>(5,2) << 3, 3, 3, 3, 4, 4, 4, 4, 4, 4); | ||
| Mat trainLabels = (Mat_<float>(5,1) << 0, 0, 1, 1, 1); |
There was a problem hiding this comment.
Please remove tabs. Use 4 spaces for indentation
| if( _results.needed() ) | ||
| { | ||
| _results.create(testcount, 1, CV_32F); | ||
| res = _results.getMat(); |
There was a problem hiding this comment.
This doesn't look valid.
OpenCV API can reuse output buffers (if they are not zero). However it is not tested widely.
res.push_back(_res.t());
will keep garbage in the beginning from the passed buffer for output.
There was a problem hiding this comment.
I believe I saw some similar behavior with what you're describing when I left these lines in here - in the example of the test case with two samples, res would contain four values - the first two of which were garbage, and the latter two contained valid/reasonable values.
fe843a3 to
a2c694a
Compare
modules/ml/test/test_knearest.cpp
Outdated
|
|
||
| EXPECT_EQ(int(result.at<int>(0, 0)), 1); | ||
| EXPECT_EQ(int(result.at<int>(1, 0)), 2); | ||
| EXPECT_EQ(trainLabels.at<int>(result.at<int>(0, 0), 0), 0); |
There was a problem hiding this comment.
Please swap arguments for EXPECT_EQ() macro:
EXPECT_EQ(expected, actual)
remove docs and revert change Make KDTree mode in kNN functional spacing Make KDTree mode in kNN functional fix window compilations warnings Make KDTree mode in kNN functional fix window compilations warnings Make KDTree mode in kNN functional casting Make KDTree mode in kNN functional formatting Make KDTree mode in kNN functional
Several issues about the implementation of the KDTree for kNN have been brought up over the years:
I believe this PR should address the issues described:
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.