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
a46adbfc
Commit
a46adbfc
authored
8 years ago
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8020 from alalek:fix_4976
parents
c25f5875
a2b6b595
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
0 deletions
+56
-0
test_shape.py
modules/python/test/test_shape.py
+23
-0
haus_dis.cpp
modules/shape/src/haus_dis.cpp
+7
-0
sc_dis.cpp
modules/shape/src/sc_dis.cpp
+7
-0
test_shape.cpp
modules/shape/test/test_shape.cpp
+19
-0
No files found.
modules/python/test/test_shape.py
0 → 100644
View file @
a46adbfc
#!/usr/bin/env python
import
cv2
from
tests_common
import
NewOpenCVTests
class
shape_test
(
NewOpenCVTests
):
def
test_computeDistance
(
self
):
a
=
self
.
get_sample
(
'samples/data/shape_sample/1.png'
,
cv2
.
IMREAD_GRAYSCALE
);
b
=
self
.
get_sample
(
'samples/data/shape_sample/2.png'
,
cv2
.
IMREAD_GRAYSCALE
);
_
,
ca
,
_
=
cv2
.
findContours
(
a
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_TC89_KCOS
)
_
,
cb
,
_
=
cv2
.
findContours
(
b
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_TC89_KCOS
)
hd
=
cv2
.
createHausdorffDistanceExtractor
()
sd
=
cv2
.
createShapeContextDistanceExtractor
()
d1
=
hd
.
computeDistance
(
ca
[
0
],
cb
[
0
])
d2
=
sd
.
computeDistance
(
ca
[
0
],
cb
[
0
])
self
.
assertAlmostEqual
(
d1
,
26.4196891785
,
3
,
"HausdorffDistanceExtractor"
)
self
.
assertAlmostEqual
(
d2
,
0.25804194808
,
3
,
"ShapeContextDistanceExtractor"
)
This diff is collapsed.
Click to expand it.
modules/shape/src/haus_dis.cpp
View file @
a46adbfc
...
...
@@ -138,6 +138,13 @@ float HausdorffDistanceExtractorImpl::computeDistance(InputArray contour1, Input
set2
.
convertTo
(
set2
,
CV_32F
);
CV_Assert
((
set1
.
channels
()
==
2
)
&&
(
set1
.
cols
>
0
));
CV_Assert
((
set2
.
channels
()
==
2
)
&&
(
set2
.
cols
>
0
));
// Force vectors column-based
if
(
set1
.
dims
>
1
)
set1
=
set1
.
reshape
(
2
,
1
);
if
(
set2
.
dims
>
1
)
set2
=
set2
.
reshape
(
2
,
1
);
return
std
::
max
(
_apply
(
set1
,
set2
,
distanceFlag
,
rankProportion
),
_apply
(
set2
,
set1
,
distanceFlag
,
rankProportion
)
);
}
...
...
This diff is collapsed.
Click to expand it.
modules/shape/src/sc_dis.cpp
View file @
a46adbfc
...
...
@@ -202,6 +202,13 @@ float ShapeContextDistanceExtractorImpl::computeDistance(InputArray contour1, In
CV_Assert
((
set1
.
channels
()
==
2
)
&&
(
set1
.
cols
>
0
));
CV_Assert
((
set2
.
channels
()
==
2
)
&&
(
set2
.
cols
>
0
));
// Force vectors column-based
if
(
set1
.
dims
>
1
)
set1
=
set1
.
reshape
(
2
,
1
);
if
(
set2
.
dims
>
1
)
set2
=
set2
.
reshape
(
2
,
1
);
if
(
imageAppearanceWeight
!=
0
)
{
CV_Assert
((
!
image1
.
empty
())
&&
(
!
image2
.
empty
()));
...
...
This diff is collapsed.
Click to expand it.
modules/shape/test/test_shape.cpp
View file @
a46adbfc
...
...
@@ -299,3 +299,22 @@ TEST(Hauss, regression)
ShapeBaseTest
<
int
,
computeShapeDistance_Haussdorf
>
test
(
NSN_val
,
NP_val
,
CURRENT_MAX_ACCUR_val
);
test
.
safe_run
();
}
TEST
(
computeDistance
,
regression_4976
)
{
Mat
a
=
imread
(
cvtest
::
findDataFile
(
"shape/samples/1.png"
),
0
);
Mat
b
=
imread
(
cvtest
::
findDataFile
(
"shape/samples/2.png"
),
0
);
vector
<
vector
<
Point
>
>
ca
,
cb
;
findContours
(
a
,
ca
,
cv
::
RETR_CCOMP
,
cv
::
CHAIN_APPROX_TC89_KCOS
);
findContours
(
b
,
cb
,
cv
::
RETR_CCOMP
,
cv
::
CHAIN_APPROX_TC89_KCOS
);
Ptr
<
HausdorffDistanceExtractor
>
hd
=
createHausdorffDistanceExtractor
();
Ptr
<
ShapeContextDistanceExtractor
>
sd
=
createShapeContextDistanceExtractor
();
double
d1
=
hd
->
computeDistance
(
ca
[
0
],
cb
[
0
]);
double
d2
=
sd
->
computeDistance
(
ca
[
0
],
cb
[
0
]);
EXPECT_NEAR
(
d1
,
26.4196891785
,
1e-3
)
<<
"HausdorffDistanceExtractor"
;
EXPECT_NEAR
(
d2
,
0.25804194808
,
1e-3
)
<<
"ShapeContextDistanceExtractor"
;
}
This diff is collapsed.
Click to expand it.
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