1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #18857 from OrestChura:oc/kmeans

[G-API]: kmeans() Standard Kernel Implementation

* cv::gapi::kmeans kernel implementation
 - 4 overloads:
    - standard GMat - for any dimensionality
    - GMat without bestLabels initialization
    - GArray<Point2f> - for 2D
    - GArray<Point3f> - for 3D
 - Accuracy tests:
   - for every input - 2 tests
   1) without initializing. In this case, no comparison with cv::kmeans is done as kmeans uses random auto-initialization
   2) with initialization
   - in both cases, only 1 attempt is done as after first attempt kmeans initializes bestLabels randomly

* Addressing comments
 - bestLabels is returned to its original place among parameters
 - checkVector and isPointsVector functions are merged into one, shared between core.hpp & imgproc.hpp by placing it into gmat.hpp (and implementation - to gmat.cpp)
 - typos corrected

* addressing comments
 - unified names in tests
 - const added
 - typos

* Addressing comments
 - fixed the doc note
 - ddepth -> expectedDepth, `< 0 ` -> `== -1`

* Fix unsupported cases of input Mat
 - supported: multiple channels, reversed width
 - added test cases for those
 - added notes in docs
 - refactored checkVector to return dimentionality along with quantity

* Addressing comments
 - makes chackVector smaller and (maybe) clearer

* Addressing comments

* Addressing comments
 - cv::checkVector -> cv::gapi::detail

* Addressing comments
 - Changed checkVector: returns bool, quantity & dimensionality as references

* Addressing comments
 - Polishing checkVector
 - FIXME added

* Addressing discussion
 - checkVector: added overload, separate two different functionalities
 - depth assert - out of the function

* Addressing comments
 - quantity -> amount, dimensionality -> dim
 - Fix typos

* Addressing comments
 - fix docs
 - use 2 variable's definitions instead of one (for all non-trivial variables)
This commit is contained in:
Orest Chura
2020-11-30 16:18:43 +03:00
committed by GitHub
parent 95ce8f45ea
commit 986ad4ff06
10 changed files with 599 additions and 15 deletions
@@ -484,6 +484,72 @@ INSTANTIATE_TEST_CASE_P(NormalizeTestCPU, NormalizeTest,
Values(NORM_MINMAX, NORM_INF, NORM_L1, NORM_L2),
Values(-1, CV_8U, CV_16U, CV_16S, CV_32F)));
INSTANTIATE_TEST_CASE_P(KMeansNDNoInitTestCPU, KMeansNDNoInitTest,
Combine(Values(CV_32FC1),
Values(cv::Size(2, 20)),
Values(-1),
Values(CORE_CPU),
Values(5),
Values(cv::KMEANS_RANDOM_CENTERS, cv::KMEANS_PP_CENTERS)));
INSTANTIATE_TEST_CASE_P(KMeansNDInitTestCPU, KMeansNDInitTest,
Combine(Values(CV_32FC1, CV_32FC3),
Values(cv::Size(1, 20),
cv::Size(2, 20),
cv::Size(5, 720)),
Values(-1),
Values(CORE_CPU),
Values(AbsTolerance(0.01).to_compare_obj()),
Values(5, 15),
Values(cv::KMEANS_RANDOM_CENTERS | cv::KMEANS_USE_INITIAL_LABELS,
cv::KMEANS_PP_CENTERS | cv::KMEANS_USE_INITIAL_LABELS)));
INSTANTIATE_TEST_CASE_P(KMeansNDInitReverseTestCPU, KMeansNDInitTest,
Combine(Values(CV_32FC3),
Values(cv::Size(20, 1)),
Values(-1),
Values(CORE_CPU),
Values(AbsTolerance(0.01).to_compare_obj()),
Values(5, 15),
Values(cv::KMEANS_RANDOM_CENTERS | cv::KMEANS_USE_INITIAL_LABELS,
cv::KMEANS_PP_CENTERS | cv::KMEANS_USE_INITIAL_LABELS)));
INSTANTIATE_TEST_CASE_P(KMeans2DNoInitTestCPU, KMeans2DNoInitTest,
Combine(Values(-1),
Values(cv::Size(-1, 20)),
Values(-1),
Values(CORE_CPU),
Values(5),
Values(cv::KMEANS_RANDOM_CENTERS, cv::KMEANS_PP_CENTERS)));
INSTANTIATE_TEST_CASE_P(KMeans2DInitTestCPU, KMeans2DInitTest,
Combine(Values(-1),
Values(cv::Size(-1, 720),
cv::Size(-1, 20)),
Values(-1),
Values(CORE_CPU),
Values(5, 15),
Values(cv::KMEANS_RANDOM_CENTERS | cv::KMEANS_USE_INITIAL_LABELS,
cv::KMEANS_PP_CENTERS | cv::KMEANS_USE_INITIAL_LABELS)));
INSTANTIATE_TEST_CASE_P(KMeans3DNoInitTestCPU, KMeans3DNoInitTest,
Combine(Values(-1),
Values(cv::Size(-1, 20)),
Values(-1),
Values(CORE_CPU),
Values(5),
Values(cv::KMEANS_RANDOM_CENTERS, cv::KMEANS_PP_CENTERS)));
INSTANTIATE_TEST_CASE_P(KMeans3DInitTestCPU, KMeans3DInitTest,
Combine(Values(-1),
Values(cv::Size(-1, 720),
cv::Size(-1, 20)),
Values(-1),
Values(CORE_CPU),
Values(5, 15),
Values(cv::KMEANS_RANDOM_CENTERS | cv::KMEANS_USE_INITIAL_LABELS,
cv::KMEANS_PP_CENTERS | cv::KMEANS_USE_INITIAL_LABELS)));
// PLEASE DO NOT PUT NEW ACCURACY TESTS BELOW THIS POINT! //////////////////////
INSTANTIATE_TEST_CASE_P(BackendOutputAllocationTestCPU, BackendOutputAllocationTest,