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
87fc75c6
Commit
87fc75c6
authored
Feb 05, 2016
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements in tests, bugfix in digits_video sample
parent
4e3a6328
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
52 deletions
+65
-52
test_camshift.py
modules/python/test/test_camshift.py
+10
-17
test_digits.py
modules/python/test/test_digits.py
+1
-1
test_facedetect.py
modules/python/test/test_facedetect.py
+1
-12
test_houghcircles.py
modules/python/test/test_houghcircles.py
+28
-4
test_peopledetect.py
modules/python/test/test_peopledetect.py
+1
-12
tests_common.py
modules/python/test/tests_common.py
+13
-2
tst_scene_render.py
modules/python/test/tst_scene_render.py
+6
-2
digits_video.py
samples/python/digits_video.py
+5
-2
No files found.
modules/python/test/test_camshift.py
View file @
87fc75c6
...
...
@@ -24,32 +24,22 @@ import numpy as np
import
cv2
from
tst_scene_render
import
TestSceneRender
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
from
tests_common
import
NewOpenCVTests
from
tests_common
import
NewOpenCVTests
,
intersectionRate
class
camshift_test
(
NewOpenCVTests
):
framesNum
=
300
frame
=
None
selection
=
None
drag_start
=
None
show_backproj
=
False
track_window
=
None
render
=
None
errors
=
0
def
prepareRender
(
self
):
self
.
render
=
TestSceneRender
(
self
.
get_sample
(
'samples/data/pca_test1.jpg'
))
self
.
render
=
TestSceneRender
(
self
.
get_sample
(
'samples/data/pca_test1.jpg'
)
,
True
)
def
runTracker
(
self
):
...
...
@@ -93,16 +83,18 @@ class camshift_test(NewOpenCVTests):
if
self
.
show_backproj
:
vis
[:]
=
prob
[
...
,
np
.
newaxis
]
trackingRect
=
np
.
array
(
self
.
track_window
)
trackingRect
[
2
]
+=
trackingRect
[
0
]
trackingRect
[
3
]
+=
trackingRect
[
1
]
self
.
assertGreater
(
intersectionRate
((
self
.
render
.
getCurrentRect
()),
trackingRect
),
0.5
)
if
intersectionRate
(
self
.
render
.
getCurrentRect
(),
trackingRect
)
<
0.4
:
self
.
errors
+=
1
if
framesCounter
>
300
:
if
framesCounter
>
self
.
framesNum
:
break
self
.
assertLess
(
float
(
self
.
errors
)
/
self
.
framesNum
,
0.4
)
def
test_camshift
(
self
):
self
.
prepareRender
()
self
.
runTracker
()
\ No newline at end of file
modules/python/test/test_digits.py
View file @
87fc75c6
...
...
@@ -95,7 +95,7 @@ def evaluate_model(model, digits, samples, labels):
confusion
=
np
.
zeros
((
10
,
10
),
np
.
int32
)
for
i
,
j
in
zip
(
labels
,
resp
):
confusion
[
i
,
j
]
+=
1
confusion
[
i
nt
(
i
),
int
(
j
)
]
+=
1
return
err
,
confusion
...
...
modules/python/test/test_facedetect.py
View file @
87fc75c6
...
...
@@ -10,17 +10,6 @@ from __future__ import print_function
import
numpy
as
np
import
cv2
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
def
detect
(
img
,
cascade
):
rects
=
cascade
.
detectMultiScale
(
img
,
scaleFactor
=
1.3
,
minNeighbors
=
4
,
minSize
=
(
30
,
30
),
flags
=
cv2
.
CASCADE_SCALE_IMAGE
)
...
...
@@ -29,7 +18,7 @@ def detect(img, cascade):
rects
[:,
2
:]
+=
rects
[:,:
2
]
return
rects
from
tests_common
import
NewOpenCVTests
from
tests_common
import
NewOpenCVTests
,
intersectionRate
class
facedetect_test
(
NewOpenCVTests
):
...
...
modules/python/test/test_houghcircles.py
View file @
87fc75c6
...
...
@@ -10,9 +10,31 @@ from __future__ import print_function
import
cv2
import
numpy
as
np
import
sys
from
numpy
import
pi
,
sin
,
cos
from
tests_common
import
NewOpenCVTests
def
circleApproximation
(
circle
):
nPoints
=
30
phi
=
0
dPhi
=
2
*
pi
/
nPoints
contour
=
[]
for
i
in
range
(
nPoints
):
contour
.
append
(([
circle
[
0
]
+
circle
[
2
]
*
cos
(
i
*
dPhi
),
circle
[
1
]
+
circle
[
2
]
*
sin
(
i
*
dPhi
)]))
return
np
.
array
(
contour
)
.
astype
(
int
)
def
convContoursIntersectiponRate
(
c1
,
c2
):
s1
=
cv2
.
contourArea
(
c1
)
s2
=
cv2
.
contourArea
(
c2
)
s
,
_
=
cv2
.
intersectConvexConvex
(
c1
,
c2
)
return
2
*
s
/
(
s1
+
s2
)
class
houghcircles_test
(
NewOpenCVTests
):
def
test_houghcircles
(
self
):
...
...
@@ -45,13 +67,15 @@ class houghcircles_test(NewOpenCVTests):
[
448.4
,
121.3
,
9.12
],
[
384.6
,
128.9
,
8.62
]]
eps
=
7
matches_counter
=
0
for
i
in
range
(
len
(
testCircles
)):
for
j
in
range
(
len
(
circles
)):
if
cv2
.
norm
(
testCircles
[
i
]
-
circles
[
j
],
cv2
.
NORM_L2
)
<
eps
:
tstCircle
=
circleApproximation
(
testCircles
[
i
])
circle
=
circleApproximation
(
circles
[
j
])
if
convContoursIntersectiponRate
(
tstCircle
,
circle
)
>
0.6
:
matches_counter
+=
1
self
.
assertGreater
(
float
(
matches_counter
)
/
len
(
testCircles
),
.
5
)
self
.
assertLess
(
float
(
len
(
circles
)
-
matches_counter
)
/
len
(
circles
),
.
7
)
\ No newline at end of file
self
.
assertLess
(
float
(
len
(
circles
)
-
matches_counter
)
/
len
(
circles
),
.
75
)
\ No newline at end of file
modules/python/test/test_peopledetect.py
View file @
87fc75c6
...
...
@@ -16,18 +16,7 @@ def inside(r, q):
qx
,
qy
,
qw
,
qh
=
q
return
rx
>
qx
and
ry
>
qy
and
rx
+
rw
<
qx
+
qw
and
ry
+
rh
<
qy
+
qh
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
from
tests_common
import
NewOpenCVTests
from
tests_common
import
NewOpenCVTests
,
intersectionRate
class
peopledetect_test
(
NewOpenCVTests
):
def
test_peopledetect
(
self
):
...
...
modules/python/test/tests_common.py
View file @
87fc75c6
...
...
@@ -53,4 +53,15 @@ class NewOpenCVTests(unittest.TestCase):
def
assertGreater
(
self
,
a
,
b
,
msg
=
None
):
if
not
a
>
b
:
self
.
fail
(
'
%
s not greater than
%
s'
%
(
repr
(
a
),
repr
(
b
)))
\ No newline at end of file
self
.
fail
(
'
%
s not greater than
%
s'
%
(
repr
(
a
),
repr
(
b
)))
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
#print(np.array(s2))
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
\ No newline at end of file
modules/python/test/tst_scene_render.py
View file @
87fc75c6
...
...
@@ -13,9 +13,10 @@ defaultSize = 512
class
TestSceneRender
():
def
__init__
(
self
,
bgImg
=
None
,
**
params
):
def
__init__
(
self
,
bgImg
=
None
,
deformation
=
False
,
**
params
):
self
.
time
=
0.0
self
.
timeStep
=
1.0
/
30.0
self
.
deformation
=
deformation
if
bgImg
!=
None
:
self
.
sceneBg
=
bgImg
.
copy
()
...
...
@@ -26,7 +27,7 @@ class TestSceneRender():
self
.
h
=
self
.
sceneBg
.
shape
[
1
]
self
.
initialRect
=
np
.
array
([
(
self
.
h
/
2
,
self
.
w
/
2
),
(
self
.
h
/
2
,
self
.
w
/
2
+
self
.
w
/
10
),
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
+
self
.
w
/
10
),
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
)])
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
+
self
.
w
/
10
),
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
)])
.
astype
(
int
)
self
.
currentRect
=
self
.
initialRect
def
setInitialRect
(
self
,
rect
):
...
...
@@ -42,6 +43,9 @@ class TestSceneRender():
img
=
self
.
sceneBg
.
copy
()
self
.
currentRect
=
self
.
initialRect
+
np
.
int
(
30
*
cos
(
self
.
time
)
+
50
*
sin
(
self
.
time
/
3
))
if
(
self
.
deformation
):
self
.
currentRect
[
1
:
3
]
+=
np
.
int
(
self
.
h
/
20
*
cos
(
self
.
time
))
cv2
.
fillConvexPoly
(
img
,
self
.
currentRect
,
(
0
,
0
,
255
))
return
img
...
...
samples/python/digits_video.py
View file @
87fc75c6
...
...
@@ -27,9 +27,12 @@ def main():
if
not
os
.
path
.
exists
(
classifier_fn
):
print
(
'"
%
s" not found, run digits.py first'
%
classifier_fn
)
return
model
=
SVM
()
model
.
load
(
classifier_fn
)
if
True
:
model
=
cv2
.
ml
.
SVM_load
(
classifier_fn
)
else
:
model
=
cv2
.
ml
.
SVM_create
()
model
.
load_
(
classifier_fn
)
#Known bug: https://github.com/Itseez/opencv/issues/4969
while
True
:
ret
,
frame
=
cap
.
read
()
...
...
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