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
56571561
Commit
56571561
authored
Jan 28, 2016
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add k-means python test, fix loading images in calibration test
parent
5625d795
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletion
+76
-1
test.py
modules/python/test/test.py
+1
-0
test_calibration.py
modules/python/test/test_calibration.py
+1
-1
test_kmeans.py
modules/python/test/test_kmeans.py
+74
-0
No files found.
modules/python/test/test.py
View file @
56571561
...
...
@@ -27,6 +27,7 @@ from test_houghcircles import houghcircles_test
from
test_houghlines
import
houghlines_test
from
test_gaussian_mix
import
gaussian_mix_test
from
test_facedetect
import
facedetect_test
from
test_kmeans
import
kmeans_test
# Python 3 moved urlopen to urllib.requests
try
:
...
...
modules/python/test/test_calibration.py
View file @
56571561
...
...
@@ -23,7 +23,7 @@ class calibration_test(NewOpenCVTests):
for
i
in
range
(
1
,
15
):
if
i
<
10
:
img_names
.
append
(
'samples/data/left0{}.jpg'
.
format
(
str
(
i
)))
el
se
:
el
if
i
!=
10
:
img_names
.
append
(
'samples/data/left{}.jpg'
.
format
(
str
(
i
)))
square_size
=
1.0
...
...
modules/python/test/test_kmeans.py
0 → 100644
View file @
56571561
#!/usr/bin/env python
'''
K-means clusterization test
'''
# Python 2/3 compatibility
from
__future__
import
print_function
import
numpy
as
np
import
cv2
from
numpy
import
random
from
tests_common
import
NewOpenCVTests
def
make_gaussians
(
cluster_n
,
img_size
):
points
=
[]
ref_distrs
=
[]
sizes
=
[]
for
i
in
xrange
(
cluster_n
):
mean
=
(
0.1
+
0.8
*
random
.
rand
(
2
))
*
img_size
a
=
(
random
.
rand
(
2
,
2
)
-
0.5
)
*
img_size
*
0.1
cov
=
np
.
dot
(
a
.
T
,
a
)
+
img_size
*
0.05
*
np
.
eye
(
2
)
n
=
100
+
random
.
randint
(
900
)
pts
=
random
.
multivariate_normal
(
mean
,
cov
,
n
)
points
.
append
(
pts
)
ref_distrs
.
append
(
(
mean
,
cov
)
)
sizes
.
append
(
n
)
points
=
np
.
float32
(
np
.
vstack
(
points
)
)
return
points
,
ref_distrs
,
sizes
def
getMainLabelConfidence
(
labels
,
nLabels
):
n
=
len
(
labels
)
labelsDict
=
dict
.
fromkeys
(
range
(
nLabels
),
0
)
labelsConfDict
=
dict
.
fromkeys
(
range
(
nLabels
))
for
i
in
range
(
n
):
labelsDict
[
labels
[
i
][
0
]]
+=
1
for
i
in
range
(
nLabels
):
labelsConfDict
[
i
]
=
float
(
labelsDict
[
i
])
/
n
return
max
(
labelsConfDict
.
values
())
class
kmeans_test
(
NewOpenCVTests
):
def
test_kmeans
(
self
):
np
.
random
.
seed
(
10
)
cluster_n
=
5
img_size
=
512
# generating bright palette
colors
=
np
.
zeros
((
1
,
cluster_n
,
3
),
np
.
uint8
)
colors
[
0
,:]
=
255
colors
[
0
,:,
0
]
=
np
.
arange
(
0
,
180
,
180.0
/
cluster_n
)
colors
=
cv2
.
cvtColor
(
colors
,
cv2
.
COLOR_HSV2BGR
)[
0
]
points
,
_
,
clusterSizes
=
make_gaussians
(
cluster_n
,
img_size
)
term_crit
=
(
cv2
.
TERM_CRITERIA_EPS
,
30
,
0.1
)
ret
,
labels
,
centers
=
cv2
.
kmeans
(
points
,
cluster_n
,
None
,
term_crit
,
10
,
0
)
self
.
assertEqual
(
len
(
centers
),
cluster_n
)
offset
=
0
for
i
in
range
(
cluster_n
):
confidence
=
getMainLabelConfidence
(
labels
[
offset
:
(
offset
+
clusterSizes
[
i
])],
cluster_n
)
offset
+=
clusterSizes
[
i
]
self
.
assertGreater
(
confidence
,
0.9
)
\ No newline at end of file
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