Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
61c7c441
Commit
61c7c441
authored
Apr 06, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle single-point sets in kmeans properly
parent
71d87693
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
13 deletions
+20
-13
matrix.cpp
modules/core/src/matrix.cpp
+3
-2
test_math.cpp
modules/core/test/test_math.cpp
+17
-11
No files found.
modules/core/src/matrix.cpp
View file @
61c7c441
...
...
@@ -2459,8 +2459,9 @@ double cv::kmeans( InputArray _data, int K,
{
const
int
SPP_TRIALS
=
3
;
Mat
data
=
_data
.
getMat
();
int
N
=
data
.
rows
>
1
?
data
.
rows
:
data
.
cols
;
int
dims
=
(
data
.
rows
>
1
?
data
.
cols
:
1
)
*
data
.
channels
();
bool
isrow
=
data
.
rows
==
1
&&
data
.
channels
()
>
1
;
int
N
=
!
isrow
?
data
.
rows
:
data
.
cols
;
int
dims
=
(
!
isrow
?
data
.
cols
:
1
)
*
data
.
channels
();
int
type
=
data
.
depth
();
attempts
=
std
::
max
(
attempts
,
1
);
...
...
modules/core/test/test_math.cpp
View file @
61c7c441
...
...
@@ -2437,42 +2437,48 @@ public:
protected
:
void
run
(
int
)
{
int
i
,
iter
=
0
,
N
=
0
,
N0
=
0
,
K
=
0
,
dims
=
0
;
Mat
labels
;
try
{
RNG
&
rng
=
theRNG
();
const
int
MAX_DIM
=
5
;
int
MAX_POINTS
=
100
;
for
(
i
nt
iter
=
0
;
iter
<
100
;
iter
++
)
int
MAX_POINTS
=
100
,
maxIter
=
100
;
for
(
i
ter
=
0
;
iter
<
maxIter
;
iter
++
)
{
ts
->
update_context
(
this
,
iter
,
true
);
int
dims
=
rng
.
uniform
(
1
,
MAX_DIM
+
1
);
int
N
=
rng
.
uniform
(
1
,
MAX_POINTS
+
1
);
int
N0
=
rng
.
uniform
(
1
,
N
/
10
+
1
);
int
K
=
rng
.
uniform
(
1
,
N
+
1
);
dims
=
rng
.
uniform
(
1
,
MAX_DIM
+
1
);
N
=
rng
.
uniform
(
1
,
MAX_POINTS
+
1
);
N0
=
rng
.
uniform
(
1
,
MAX
(
N
/
10
,
2
)
);
K
=
rng
.
uniform
(
1
,
N
+
1
);
Mat
data0
(
N0
,
dims
,
CV_32F
)
,
labels
;
Mat
data0
(
N0
,
dims
,
CV_32F
);
rng
.
fill
(
data0
,
RNG
::
UNIFORM
,
-
1
,
1
);
Mat
data
(
N
,
dims
,
CV_32F
);
for
(
i
nt
i
=
0
;
i
<
N
;
i
++
)
for
(
i
=
0
;
i
<
N
;
i
++
)
data0
.
row
(
rng
.
uniform
(
0
,
N0
)).
copyTo
(
data
.
row
(
i
));
kmeans
(
data
,
K
,
labels
,
TermCriteria
(
TermCriteria
::
MAX_ITER
+
TermCriteria
::
EPS
,
30
,
0
),
5
,
KMEANS_PP_CENTERS
);
Mat
hist
(
K
,
1
,
CV_32S
,
Scalar
(
0
));
for
(
i
nt
i
=
0
;
i
<
N
;
i
++
)
for
(
i
=
0
;
i
<
N
;
i
++
)
{
int
l
=
labels
.
at
<
int
>
(
i
);
CV_Assert
(
0
<=
l
&&
l
<
K
);
CV_Assert
(
0
<=
l
&&
l
<
K
);
hist
.
at
<
int
>
(
l
)
++
;
}
for
(
i
nt
i
=
0
;
i
<
K
;
i
++
)
for
(
i
=
0
;
i
<
K
;
i
++
)
CV_Assert
(
hist
.
at
<
int
>
(
i
)
!=
0
);
}
}
catch
(...)
{
ts
->
printf
(
cvtest
::
TS
::
LOG
,
"context: iteration=%d, N=%d, N0=%d, K=%d
\n
"
,
iter
,
N
,
N0
,
K
);
std
::
cout
<<
labels
<<
std
::
endl
;
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_MISMATCH
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment