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
42936d32
Commit
42936d32
authored
Jun 30, 2017
by
Vladislav Sovrasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imgproc: fix MORPH_HITMISS operation when kernel has no negative values
parent
7b8e6307
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
13 deletions
+52
-13
morph.cpp
modules/imgproc/src/morph.cpp
+19
-13
test_filter.cpp
modules/imgproc/test/test_filter.cpp
+33
-0
No files found.
modules/imgproc/src/morph.cpp
View file @
42936d32
...
...
@@ -2012,8 +2012,6 @@ void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
CV_IPP_RUN_FAST
(
ipp_morphologyEx
(
op
,
src
,
dst
,
kernel
,
anchor
,
iterations
,
borderType
,
borderValue
));
#endif
Mat
k1
,
k2
,
e1
,
e2
;
//only for hit and miss op
switch
(
op
)
{
case
MORPH_ERODE
:
...
...
@@ -2051,21 +2049,29 @@ void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
break
;
case
MORPH_HITMISS
:
CV_Assert
(
src
.
type
()
==
CV_8UC1
);
k1
=
(
kernel
==
1
);
k2
=
(
kernel
==
-
1
);
if
(
countNonZero
(
k1
)
<=
0
)
e1
=
src
;
else
erode
(
src
,
e1
,
k1
,
anchor
,
iterations
,
borderType
,
borderValue
);
if
(
countNonZero
(
k2
)
<=
0
)
e2
=
src
;
else
if
(
countNonZero
(
kernel
)
<=
0
)
{
src
.
copyTo
(
dst
);
break
;
}
{
Mat
k1
,
k2
,
e1
,
e2
;
k1
=
(
kernel
==
1
);
k2
=
(
kernel
==
-
1
);
if
(
countNonZero
(
k1
)
<=
0
)
e1
=
src
;
else
erode
(
src
,
e1
,
k1
,
anchor
,
iterations
,
borderType
,
borderValue
);
Mat
src_complement
;
bitwise_not
(
src
,
src_complement
);
erode
(
src_complement
,
e2
,
k2
,
anchor
,
iterations
,
borderType
,
borderValue
);
if
(
countNonZero
(
k2
)
<=
0
)
e2
=
src_complement
;
else
erode
(
src_complement
,
e2
,
k2
,
anchor
,
iterations
,
borderType
,
borderValue
);
dst
=
e1
&
e2
;
}
dst
=
e1
&
e2
;
break
;
default
:
CV_Error
(
CV_StsBadArg
,
"unknown morphological operation"
);
...
...
modules/imgproc/test/test_filter.cpp
View file @
42936d32
...
...
@@ -2065,3 +2065,36 @@ TEST(Imgproc_Sobel, borderTypes)
EXPECT_EQ
(
expected_dst
.
size
(),
dst
.
size
());
EXPECT_DOUBLE_EQ
(
0.0
,
cvtest
::
norm
(
expected_dst
,
dst
,
NORM_INF
));
}
TEST
(
Imgproc_MorphEx
,
hitmiss_regression_8957
)
{
Mat_
<
uchar
>
src
(
3
,
3
);
src
<<
0
,
255
,
0
,
0
,
0
,
0
,
0
,
255
,
0
;
Mat_
<
uchar
>
kernel
=
src
/
255
;
Mat
dst
;
morphologyEx
(
src
,
dst
,
MORPH_HITMISS
,
kernel
);
Mat
ref
=
Mat
::
zeros
(
3
,
3
,
CV_8U
);
ref
.
at
<
uchar
>
(
1
,
1
)
=
255
;
ASSERT_DOUBLE_EQ
(
norm
(
dst
,
ref
,
NORM_INF
),
0.
);
}
TEST
(
Imgproc_MorphEx
,
hitmiss_zero_kernel
)
{
Mat_
<
uchar
>
src
(
3
,
3
);
src
<<
0
,
255
,
0
,
0
,
0
,
0
,
0
,
255
,
0
;
Mat_
<
uchar
>
kernel
=
Mat_
<
uchar
>::
zeros
(
3
,
3
);
Mat
dst
;
morphologyEx
(
src
,
dst
,
MORPH_HITMISS
,
kernel
);
ASSERT_DOUBLE_EQ
(
norm
(
dst
,
src
,
NORM_INF
),
0.
);
}
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