|
|
@ -2512,6 +2512,15 @@ TEST(Core_SVD, flt) |
|
|
|
|
|
|
|
|
|
|
|
// TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)),
|
|
|
|
// TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MAT_N_DIM_C1, |
|
|
|
|
|
|
|
MAT_N_1_CDIM, |
|
|
|
|
|
|
|
MAT_1_N_CDIM, |
|
|
|
|
|
|
|
MAT_N_DIM_C1_NONCONT, |
|
|
|
|
|
|
|
MAT_N_1_CDIM_NONCONT, |
|
|
|
|
|
|
|
VECTOR |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class CV_KMeansSingularTest : public cvtest::BaseTest |
|
|
|
class CV_KMeansSingularTest : public cvtest::BaseTest |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2519,7 +2528,7 @@ public: |
|
|
|
CV_KMeansSingularTest() {} |
|
|
|
CV_KMeansSingularTest() {} |
|
|
|
~CV_KMeansSingularTest() {} |
|
|
|
~CV_KMeansSingularTest() {} |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
void run(int) |
|
|
|
void run(int inVariant) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i, iter = 0, N = 0, N0 = 0, K = 0, dims = 0; |
|
|
|
int i, iter = 0, N = 0, N0 = 0, K = 0, dims = 0; |
|
|
|
Mat labels; |
|
|
|
Mat labels; |
|
|
@ -2531,20 +2540,70 @@ protected: |
|
|
|
for( iter = 0; iter < maxIter; iter++ ) |
|
|
|
for( iter = 0; iter < maxIter; iter++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ts->update_context(this, iter, true); |
|
|
|
ts->update_context(this, iter, true); |
|
|
|
dims = rng.uniform(1, MAX_DIM+1); |
|
|
|
dims = rng.uniform(inVariant == MAT_1_N_CDIM ? 2 : 1, MAX_DIM+1); |
|
|
|
N = rng.uniform(1, MAX_POINTS+1); |
|
|
|
N = rng.uniform(1, MAX_POINTS+1); |
|
|
|
N0 = rng.uniform(1, MAX(N/10, 2)); |
|
|
|
N0 = rng.uniform(1, MAX(N/10, 2)); |
|
|
|
K = rng.uniform(1, N+1); |
|
|
|
K = rng.uniform(1, N+1); |
|
|
|
|
|
|
|
|
|
|
|
Mat data0(N0, dims, CV_32F); |
|
|
|
if (inVariant == VECTOR) |
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1); |
|
|
|
{ |
|
|
|
|
|
|
|
dims = 2; |
|
|
|
|
|
|
|
|
|
|
|
Mat data(N, dims, CV_32F); |
|
|
|
std::vector<cv::Point2f> data0(N0); |
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1); |
|
|
|
data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<cv::Point2f> data(N); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
data[i] = data0[rng.uniform(0, N0)]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), |
|
|
|
|
|
|
|
5, KMEANS_PP_CENTERS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Mat data0(N0, dims, CV_32F); |
|
|
|
|
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1); |
|
|
|
|
|
|
|
|
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), |
|
|
|
Mat data; |
|
|
|
5, KMEANS_PP_CENTERS); |
|
|
|
|
|
|
|
|
|
|
|
switch (inVariant) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case MAT_N_DIM_C1: |
|
|
|
|
|
|
|
data.create(N, dims, CV_32F); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MAT_N_1_CDIM: |
|
|
|
|
|
|
|
data.create(N, 1, CV_32FC(dims)); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MAT_1_N_CDIM: |
|
|
|
|
|
|
|
data.create(1, N, CV_32FC(dims)); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
memcpy(data.data + i * dims * sizeof(float), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MAT_N_DIM_C1_NONCONT: |
|
|
|
|
|
|
|
data.create(N, dims + 5, CV_32F); |
|
|
|
|
|
|
|
data = data(Range(0, N), Range(0, dims)); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case MAT_N_1_CDIM_NONCONT: |
|
|
|
|
|
|
|
data.create(N, 3, CV_32FC(dims)); |
|
|
|
|
|
|
|
data = data.colRange(0, 1); |
|
|
|
|
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
|
|
|
|
memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), |
|
|
|
|
|
|
|
5, KMEANS_PP_CENTERS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Mat hist(K, 1, CV_32S, Scalar(0)); |
|
|
|
Mat hist(K, 1, CV_32S, Scalar(0)); |
|
|
|
for( i = 0; i < N; i++ ) |
|
|
|
for( i = 0; i < N; i++ ) |
|
|
@ -2568,7 +2627,19 @@ protected: |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(); } |
|
|
|
TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(MAT_N_DIM_C1); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CV_ENUM(KMeansInputVariant, MAT_N_DIM_C1, MAT_N_1_CDIM, MAT_1_N_CDIM, MAT_N_DIM_C1_NONCONT, MAT_N_1_CDIM_NONCONT, VECTOR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef testing::TestWithParam<KMeansInputVariant> Core_KMeans_InputVariants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(Core_KMeans_InputVariants, singular) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CV_KMeansSingularTest test; |
|
|
|
|
|
|
|
test.safe_run(GetParam()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(AllVariants, Core_KMeans_InputVariants, KMeansInputVariant::all()); |
|
|
|
|
|
|
|
|
|
|
|
TEST(CovariationMatrixVectorOfMat, accuracy) |
|
|
|
TEST(CovariationMatrixVectorOfMat, accuracy) |
|
|
|
{ |
|
|
|
{ |
|
|
|