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
de56163f
Commit
de56163f
authored
Apr 30, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored gpu::matchTemplate (converted it into Algorithm)
parent
1fcc8074
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
30 deletions
+42
-30
gpuimgproc.hpp
modules/gpuimgproc/include/opencv2/gpuimgproc.hpp
+14
-10
perf_match_template.cpp
modules/gpuimgproc/perf/perf_match_template.cpp
+6
-2
match_template.cpp
modules/gpuimgproc/src/match_template.cpp
+0
-0
test_match_template.cpp
modules/gpuimgproc/test/test_match_template.cpp
+18
-6
tests.cpp
samples/gpu/performance/tests.cpp
+4
-12
No files found.
modules/gpuimgproc/include/opencv2/gpuimgproc.hpp
View file @
de56163f
...
...
@@ -424,20 +424,24 @@ CV_EXPORTS void meanShiftSegmentation(InputArray src, OutputArray dst, int sp, i
/////////////////////////// Match Template ////////////////////////////
struct
CV_EXPORTS
MatchTemplateBuf
//! computes the proximity map for the raster template and the image where the template is searched for
class
CV_EXPORTS
TemplateMatching
:
public
Algorithm
{
Size
user_block_size
;
GpuMat
imagef
,
templf
;
std
::
vector
<
GpuMat
>
images
;
std
::
vector
<
GpuMat
>
image_sums
;
std
::
vector
<
GpuMat
>
image_sqsums
;
public
:
virtual
void
match
(
InputArray
image
,
InputArray
templ
,
OutputArray
result
,
Stream
&
stream
=
Stream
::
Null
())
=
0
;
};
//! computes the proximity map for the raster template and the image where the template is searched for
CV_EXPORTS
void
matchTemplate
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
int
method
,
Stream
&
stream
=
Stream
::
Null
());
CV_EXPORTS
Ptr
<
TemplateMatching
>
createTemplateMatching
(
int
srcType
,
int
method
,
Size
user_block_size
=
Size
());
//! computes the proximity map for the raster template and the image where the template is searched for
CV_EXPORTS
void
matchTemplate
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
int
method
,
MatchTemplateBuf
&
buf
,
Stream
&
stream
=
Stream
::
Null
());
// obsolete
__OPENCV_GPUIMGPROC_DEPR_BEFORE__
void
matchTemplate
(
InputArray
image
,
InputArray
templ
,
OutputArray
result
,
int
method
,
Stream
&
stream
=
Stream
::
Null
())
__OPENCV_GPUIMGPROC_DEPR_AFTER__
;
inline
void
matchTemplate
(
InputArray
image
,
InputArray
templ
,
OutputArray
result
,
int
method
,
Stream
&
stream
)
{
gpu
::
createTemplateMatching
(
image
.
type
(),
method
)
->
match
(
image
,
templ
,
result
,
stream
);
}
////////////////////////// Bilateral Filter ///////////////////////////
...
...
modules/gpuimgproc/perf/perf_match_template.cpp
View file @
de56163f
...
...
@@ -76,7 +76,9 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, MatchTemplate8U,
const
cv
::
gpu
::
GpuMat
d_templ
(
templ
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
cv
::
gpu
::
matchTemplate
(
d_image
,
d_templ
,
dst
,
method
);
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
method
);
TEST_CYCLE
()
alg
->
match
(
d_image
,
d_templ
,
dst
);
GPU_SANITY_CHECK
(
dst
,
1e-5
,
ERROR_RELATIVE
);
}
...
...
@@ -116,7 +118,9 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, MatchTemplate32F,
const
cv
::
gpu
::
GpuMat
d_templ
(
templ
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
cv
::
gpu
::
matchTemplate
(
d_image
,
d_templ
,
dst
,
method
);
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
method
);
TEST_CYCLE
()
alg
->
match
(
d_image
,
d_templ
,
dst
);
GPU_SANITY_CHECK
(
dst
,
1e-6
,
ERROR_RELATIVE
);
}
...
...
modules/gpuimgproc/src/match_template.cpp
View file @
de56163f
This diff is collapsed.
Click to expand it.
modules/gpuimgproc/test/test_match_template.cpp
View file @
de56163f
...
...
@@ -82,8 +82,10 @@ GPU_TEST_P(MatchTemplate8U, Accuracy)
cv
::
Mat
image
=
randomMat
(
size
,
CV_MAKETYPE
(
CV_8U
,
cn
));
cv
::
Mat
templ
=
randomMat
(
templ_size
,
CV_MAKETYPE
(
CV_8U
,
cn
));
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
method
);
cv
::
gpu
::
GpuMat
dst
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
image
),
loadMat
(
templ
),
dst
,
method
);
alg
->
match
(
loadMat
(
image
),
loadMat
(
templ
),
dst
);
cv
::
Mat
dst_gold
;
cv
::
matchTemplate
(
image
,
templ
,
dst_gold
,
method
);
...
...
@@ -128,8 +130,10 @@ GPU_TEST_P(MatchTemplate32F, Regression)
cv
::
Mat
image
=
randomMat
(
size
,
CV_MAKETYPE
(
CV_32F
,
cn
));
cv
::
Mat
templ
=
randomMat
(
templ_size
,
CV_MAKETYPE
(
CV_32F
,
cn
));
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
method
);
cv
::
gpu
::
GpuMat
dst
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
image
),
loadMat
(
templ
),
dst
,
method
);
alg
->
match
(
loadMat
(
image
),
loadMat
(
templ
),
dst
);
cv
::
Mat
dst_gold
;
cv
::
matchTemplate
(
image
,
templ
,
dst_gold
,
method
);
...
...
@@ -169,8 +173,10 @@ GPU_TEST_P(MatchTemplateBlackSource, Accuracy)
cv
::
Mat
pattern
=
readImage
(
"matchtemplate/cat.png"
);
ASSERT_FALSE
(
pattern
.
empty
());
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
method
);
cv
::
gpu
::
GpuMat
d_dst
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
image
),
loadMat
(
pattern
),
d_dst
,
method
);
alg
->
match
(
loadMat
(
image
),
loadMat
(
pattern
),
d_dst
);
cv
::
Mat
dst
(
d_dst
);
...
...
@@ -214,8 +220,10 @@ GPU_TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy)
cv
::
Mat
pattern
=
readImage
(
patternName
);
ASSERT_FALSE
(
pattern
.
empty
());
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
image
.
type
(),
cv
::
TM_CCOEFF_NORMED
);
cv
::
gpu
::
GpuMat
d_dst
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
image
),
loadMat
(
pattern
),
d_dst
,
cv
::
TM_CCOEFF_NORMED
);
alg
->
match
(
loadMat
(
image
),
loadMat
(
pattern
),
d_dst
);
cv
::
Mat
dst
(
d_dst
);
...
...
@@ -263,8 +271,10 @@ GPU_TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED)
cv
::
Mat
templ
=
readImage
(
"matchtemplate/template.png"
);
ASSERT_FALSE
(
templ
.
empty
());
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
scene
.
type
(),
cv
::
TM_SQDIFF_NORMED
);
cv
::
gpu
::
GpuMat
d_result
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
scene
),
loadMat
(
templ
),
d_result
,
cv
::
TM_SQDIFF_NORMED
);
alg
->
match
(
loadMat
(
scene
),
loadMat
(
templ
),
d_result
);
cv
::
Mat
result
(
d_result
);
...
...
@@ -286,8 +296,10 @@ GPU_TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF)
cv
::
Mat
templ
=
readImage
(
"matchtemplate/template.png"
);
ASSERT_FALSE
(
templ
.
empty
());
cv
::
Ptr
<
cv
::
gpu
::
TemplateMatching
>
alg
=
cv
::
gpu
::
createTemplateMatching
(
scene
.
type
(),
cv
::
TM_SQDIFF
);
cv
::
gpu
::
GpuMat
d_result
;
cv
::
gpu
::
matchTemplate
(
loadMat
(
scene
),
loadMat
(
templ
),
d_result
,
cv
::
TM_SQDIFF
);
alg
->
match
(
loadMat
(
scene
),
loadMat
(
templ
),
d_result
);
cv
::
Mat
result
(
d_result
);
...
...
samples/gpu/performance/tests.cpp
View file @
de56163f
...
...
@@ -17,24 +17,16 @@
using
namespace
std
;
using
namespace
cv
;
static
void
InitMatchTemplate
()
{
Mat
src
;
gen
(
src
,
500
,
500
,
CV_32F
,
0
,
1
);
Mat
templ
;
gen
(
templ
,
500
,
500
,
CV_32F
,
0
,
1
);
gpu
::
GpuMat
d_src
(
src
),
d_templ
(
templ
),
d_dst
;
gpu
::
matchTemplate
(
d_src
,
d_templ
,
d_dst
,
TM_CCORR
);
}
TEST
(
matchTemplate
)
{
InitMatchTemplate
();
Mat
src
,
templ
,
dst
;
gen
(
src
,
3000
,
3000
,
CV_32F
,
0
,
1
);
gpu
::
GpuMat
d_src
(
src
),
d_templ
,
d_dst
;
Ptr
<
gpu
::
TemplateMatching
>
alg
=
gpu
::
createTemplateMatching
(
src
.
type
(),
TM_CCORR
);
for
(
int
templ_size
=
5
;
templ_size
<
200
;
templ_size
*=
5
)
{
SUBTEST
<<
src
.
cols
<<
'x'
<<
src
.
rows
<<
", 32FC1"
<<
", templ "
<<
templ_size
<<
'x'
<<
templ_size
<<
", CCORR"
;
...
...
@@ -47,10 +39,10 @@ TEST(matchTemplate)
CPU_OFF
;
d_templ
.
upload
(
templ
);
gpu
::
matchTemplate
(
d_src
,
d_templ
,
d_dst
,
TM_CCORR
);
alg
->
match
(
d_src
,
d_templ
,
d_dst
);
GPU_ON
;
gpu
::
matchTemplate
(
d_src
,
d_templ
,
d_dst
,
TM_CCORR
);
alg
->
match
(
d_src
,
d_templ
,
d_dst
);
GPU_OFF
;
}
}
...
...
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