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
8 years ago
by
Arthur Cinader
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow for an optional mask for MatchTemplate_Demo
parent
7fea7e06
master
4.3.0
4.2.0
4.1.2
4.1.2-openvino
4.1.1
4.1.1-openvino
4.1.0
4.1.0-openvino
4.0.1
4.0.1-openvino
4.0.0
4.0.0-rc
4.0.0-openvino
4.0.0-beta
4.0.0-alpha
3.4.10
3.4.9
3.4.8
3.4.7
3.4.6
3.4.5
3.4.4
3.4.3
3.4.3-openvino
3.4.2
3.4.2-openvino
3.4.1
3.4.1-cvsdk
3.4.0
3.4.0-rc
3.3.1
3.3.1-cvsdk
3.3.0
3.3.0-rc
3.3.0-cvsdk
3.2.0
3.2.0-rc
No related merge requests found
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
...
...
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