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
2b08f295
Commit
2b08f295
authored
Jul 01, 2016
by
Arthur Cinader
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow for an optional mask for MatchTemplate_Demo
parent
7fea7e06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
MatchTemplate_Demo.cpp
.../tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
+15
-4
No files found.
samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
View file @
2b08f295
...
...
@@ -13,7 +13,8 @@ using namespace std;
using
namespace
cv
;
/// Global Variables
Mat
img
;
Mat
templ
;
Mat
result
;
bool
use_mask
;
Mat
img
;
Mat
templ
;
Mat
mask
;
Mat
result
;
const
char
*
image_window
=
"Source Image"
;
const
char
*
result_window
=
"Result window"
;
...
...
@@ -31,7 +32,7 @@ int main( int argc, char** argv )
if
(
argc
<
3
)
{
cout
<<
"Not enough parameters"
<<
endl
;
cout
<<
"Usage:
\n
./MatchTemplate_Demo <image_name> <template_name>"
<<
endl
;
cout
<<
"Usage:
\n
./MatchTemplate_Demo <image_name> <template_name>
[<mask_name>]
"
<<
endl
;
return
-
1
;
}
...
...
@@ -39,7 +40,12 @@ int main( int argc, char** argv )
img
=
imread
(
argv
[
1
],
IMREAD_COLOR
);
templ
=
imread
(
argv
[
2
],
IMREAD_COLOR
);
if
(
img
.
empty
()
||
templ
.
empty
())
if
(
argc
>
3
)
{
use_mask
=
true
;
mask
=
imread
(
argv
[
3
],
IMREAD_COLOR
);
}
if
(
img
.
empty
()
||
templ
.
empty
()
||
(
use_mask
&&
mask
.
empty
()))
{
cout
<<
"Can't read one of the images"
<<
endl
;
return
-
1
;
...
...
@@ -76,7 +82,12 @@ void MatchingMethod( int, void* )
result
.
create
(
result_rows
,
result_cols
,
CV_32FC1
);
/// Do the Matching and Normalize
matchTemplate
(
img
,
templ
,
result
,
match_method
);
bool
method_accepts_mask
=
CV_TM_SQDIFF
==
match_method
||
match_method
==
CV_TM_CCORR_NORMED
;
if
(
use_mask
&&
method_accepts_mask
)
{
matchTemplate
(
img
,
templ
,
result
,
match_method
,
mask
);
}
else
{
matchTemplate
(
img
,
templ
,
result
,
match_method
);
}
normalize
(
result
,
result
,
0
,
1
,
NORM_MINMAX
,
-
1
,
Mat
()
);
/// Localizing the best match with minMaxLoc
...
...
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