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
1eedc6c4
Commit
1eedc6c4
authored
Apr 29, 2013
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored Linear Filter
parent
fcfcd4cb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
191 additions
and
146 deletions
+191
-146
gpufilters.hpp
modules/gpufilters/include/opencv2/gpufilters.hpp
+28
-13
perf_filters.cpp
modules/gpufilters/perf/perf_filters.cpp
+45
-36
filter2d.cu
modules/gpufilters/src/cuda/filter2d.cu
+0
-0
filtering.cpp
modules/gpufilters/src/filtering.cpp
+0
-0
test_filters.cpp
modules/gpufilters/test/test_filters.cpp
+115
-95
tests.cpp
samples/gpu/performance/tests.cpp
+3
-2
No files found.
modules/gpufilters/include/opencv2/gpufilters.hpp
View file @
1eedc6c4
...
...
@@ -96,6 +96,34 @@ inline void blur(InputArray src, OutputArray dst, Size ksize, Point anchor, Stre
f
->
apply
(
src
,
dst
,
stream
);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Linear Filter
//! non-separable linear 2D filter
CV_EXPORTS
Ptr
<
Filter
>
createLinearFilter
(
int
srcType
,
int
dstType
,
InputArray
kernel
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
borderMode
=
BORDER_DEFAULT
,
Scalar
borderVal
=
Scalar
::
all
(
0
));
__OPENCV_GPUFILTERS_DEPR_BEFORE__
void
filter2D
(
InputArray
src
,
OutputArray
dst
,
int
ddepth
,
InputArray
kernel
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
borderType
=
BORDER_DEFAULT
,
Stream
&
stream
=
Stream
::
Null
())
__OPENCV_GPUFILTERS_DEPR_AFTER__
;
inline
void
filter2D
(
InputArray
src
,
OutputArray
dst
,
int
ddepth
,
InputArray
kernel
,
Point
anchor
,
int
borderType
,
Stream
&
stream
)
{
Ptr
<
gpu
::
Filter
>
f
=
gpu
::
createLinearFilter
(
src
.
type
(),
ddepth
,
kernel
,
anchor
,
borderType
);
f
->
apply
(
src
,
dst
,
stream
);
}
//! applies Laplacian operator to the image
//! supports only ksize = 1 and ksize = 3
CV_EXPORTS
void
Laplacian
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ddepth
,
int
ksize
=
1
,
double
scale
=
1
,
int
borderType
=
BORDER_DEFAULT
,
Stream
&
stream
=
Stream
::
Null
());
...
...
@@ -194,13 +222,7 @@ CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, co
CV_EXPORTS
Ptr
<
FilterEngine_GPU
>
createMorphologyFilter_GPU
(
int
op
,
int
type
,
const
Mat
&
kernel
,
GpuMat
&
buf
,
const
Point
&
anchor
=
Point
(
-
1
,
-
1
),
int
iterations
=
1
);
//! returns 2D filter with the specified kernel
//! supports CV_8U, CV_16U and CV_32F one and four channel image
CV_EXPORTS
Ptr
<
BaseFilter_GPU
>
getLinearFilter_GPU
(
int
srcType
,
int
dstType
,
const
Mat
&
kernel
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
borderType
=
BORDER_DEFAULT
);
//! returns the non-separable linear filter engine
CV_EXPORTS
Ptr
<
FilterEngine_GPU
>
createLinearFilter_GPU
(
int
srcType
,
int
dstType
,
const
Mat
&
kernel
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
borderType
=
BORDER_DEFAULT
);
//! returns the primitive row filter with the specified kernel.
//! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 source type.
...
...
@@ -269,9 +291,6 @@ CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat&
CV_EXPORTS
void
morphologyEx
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
op
,
const
Mat
&
kernel
,
GpuMat
&
buf1
,
GpuMat
&
buf2
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
iterations
=
1
,
Stream
&
stream
=
Stream
::
Null
());
//! applies non-separable 2D linear filter to the image
CV_EXPORTS
void
filter2D
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ddepth
,
const
Mat
&
kernel
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
borderType
=
BORDER_DEFAULT
,
Stream
&
stream
=
Stream
::
Null
());
//! applies separable 2D linear filter to the image
CV_EXPORTS
void
sepFilter2D
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ddepth
,
const
Mat
&
kernelX
,
const
Mat
&
kernelY
,
Point
anchor
=
Point
(
-
1
,
-
1
),
int
rowBorderType
=
BORDER_DEFAULT
,
int
columnBorderType
=
-
1
);
...
...
@@ -297,10 +316,6 @@ CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double
CV_EXPORTS
void
GaussianBlur
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
Size
ksize
,
GpuMat
&
buf
,
double
sigma1
,
double
sigma2
=
0
,
int
rowBorderType
=
BORDER_DEFAULT
,
int
columnBorderType
=
-
1
,
Stream
&
stream
=
Stream
::
Null
());
//! applies Laplacian operator to the image
//! supports only ksize = 1 and ksize = 3
CV_EXPORTS
void
Laplacian
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
int
ddepth
,
int
ksize
=
1
,
double
scale
=
1
,
int
borderType
=
BORDER_DEFAULT
,
Stream
&
stream
=
Stream
::
Null
());
}}
// namespace cv { namespace gpu {
#undef __OPENCV_GPUFILTERS_DEPR_BEFORE__
...
...
modules/gpufilters/perf/perf_filters.cpp
View file @
1eedc6c4
...
...
@@ -86,6 +86,51 @@ PERF_TEST_P(Sz_Type_KernelSz, Blur,
}
}
//////////////////////////////////////////////////////////////////////
// Filter2D
PERF_TEST_P
(
Sz_Type_KernelSz
,
Filter2D
,
Combine
(
GPU_TYPICAL_MAT_SIZES
,
Values
(
CV_8UC1
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
),
Values
(
3
,
5
,
7
,
9
,
11
,
13
,
15
)))
{
declare
.
time
(
20.0
);
const
cv
::
Size
size
=
GET_PARAM
(
0
);
const
int
type
=
GET_PARAM
(
1
);
const
int
ksize
=
GET_PARAM
(
2
);
cv
::
Mat
src
(
size
,
type
);
declare
.
in
(
src
,
WARMUP_RNG
);
cv
::
Mat
kernel
(
ksize
,
ksize
,
CV_32FC1
);
declare
.
in
(
kernel
,
WARMUP_RNG
);
if
(
PERF_RUN_GPU
())
{
const
cv
::
gpu
::
GpuMat
d_src
(
src
);
cv
::
gpu
::
GpuMat
dst
;
cv
::
Ptr
<
cv
::
gpu
::
Filter
>
filter2D
=
cv
::
gpu
::
createLinearFilter
(
d_src
.
type
(),
-
1
,
kernel
);
TEST_CYCLE
()
filter2D
->
apply
(
d_src
,
dst
);
GPU_SANITY_CHECK
(
dst
);
}
else
{
cv
::
Mat
dst
;
TEST_CYCLE
()
cv
::
filter2D
(
src
,
dst
,
-
1
,
kernel
);
CPU_SANITY_CHECK
(
dst
);
}
}
//////////////////////////////////////////////////////////////////////
// Sobel
...
...
@@ -330,39 +375,3 @@ PERF_TEST_P(Sz_Type_Op, MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8
CPU_SANITY_CHECK
(
dst
);
}
}
//////////////////////////////////////////////////////////////////////
// Filter2D
PERF_TEST_P
(
Sz_Type_KernelSz
,
Filter2D
,
Combine
(
GPU_TYPICAL_MAT_SIZES
,
Values
(
CV_8UC1
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
),
Values
(
3
,
5
,
7
,
9
,
11
,
13
,
15
)))
{
declare
.
time
(
20.0
);
const
cv
::
Size
size
=
GET_PARAM
(
0
);
const
int
type
=
GET_PARAM
(
1
);
const
int
ksize
=
GET_PARAM
(
2
);
cv
::
Mat
src
(
size
,
type
);
declare
.
in
(
src
,
WARMUP_RNG
);
cv
::
Mat
kernel
(
ksize
,
ksize
,
CV_32FC1
);
declare
.
in
(
kernel
,
WARMUP_RNG
);
if
(
PERF_RUN_GPU
())
{
const
cv
::
gpu
::
GpuMat
d_src
(
src
);
cv
::
gpu
::
GpuMat
dst
;
TEST_CYCLE
()
cv
::
gpu
::
filter2D
(
d_src
,
dst
,
-
1
,
kernel
);
GPU_SANITY_CHECK
(
dst
);
}
else
{
cv
::
Mat
dst
;
TEST_CYCLE
()
cv
::
filter2D
(
src
,
dst
,
-
1
,
kernel
);
CPU_SANITY_CHECK
(
dst
);
}
}
modules/gpufilters/src/cuda/filter2d.cu
View file @
1eedc6c4
This diff is collapsed.
Click to expand it.
modules/gpufilters/src/filtering.cpp
View file @
1eedc6c4
This diff is collapsed.
Click to expand it.
modules/gpufilters/test/test_filters.cpp
View file @
1eedc6c4
...
...
@@ -118,6 +118,121 @@ INSTANTIATE_TEST_CASE_P(GPU_Filters, Blur, testing::Combine(
testing
::
Values
(
BorderType
(
cv
::
BORDER_REFLECT101
),
BorderType
(
cv
::
BORDER_REPLICATE
),
BorderType
(
cv
::
BORDER_CONSTANT
),
BorderType
(
cv
::
BORDER_REFLECT
)),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Filter2D
PARAM_TEST_CASE
(
Filter2D
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
MatType
,
KSize
,
Anchor
,
BorderType
,
UseRoi
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
Size
size
;
int
type
;
cv
::
Size
ksize
;
cv
::
Point
anchor
;
int
borderType
;
bool
useRoi
;
virtual
void
SetUp
()
{
devInfo
=
GET_PARAM
(
0
);
size
=
GET_PARAM
(
1
);
type
=
GET_PARAM
(
2
);
ksize
=
GET_PARAM
(
3
);
anchor
=
GET_PARAM
(
4
);
borderType
=
GET_PARAM
(
5
);
useRoi
=
GET_PARAM
(
6
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
}
};
GPU_TEST_P
(
Filter2D
,
Accuracy
)
{
cv
::
Mat
src
=
randomMat
(
size
,
type
);
cv
::
Mat
kernel
=
randomMat
(
cv
::
Size
(
ksize
.
width
,
ksize
.
height
),
CV_32FC1
,
0.0
,
1.0
);
cv
::
Ptr
<
cv
::
gpu
::
Filter
>
filter2D
=
cv
::
gpu
::
createLinearFilter
(
src
.
type
(),
-
1
,
kernel
,
anchor
,
borderType
);
cv
::
gpu
::
GpuMat
dst
=
createMat
(
size
,
type
,
useRoi
);
filter2D
->
apply
(
loadMat
(
src
,
useRoi
),
dst
);
cv
::
Mat
dst_gold
;
cv
::
filter2D
(
src
,
dst_gold
,
-
1
,
kernel
,
anchor
,
0
,
borderType
);
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
CV_MAT_DEPTH
(
type
)
==
CV_32F
?
1e-1
:
1.0
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_Filters
,
Filter2D
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
KSize
(
cv
::
Size
(
3
,
3
)),
KSize
(
cv
::
Size
(
5
,
5
)),
KSize
(
cv
::
Size
(
7
,
7
)),
KSize
(
cv
::
Size
(
11
,
11
)),
KSize
(
cv
::
Size
(
13
,
13
)),
KSize
(
cv
::
Size
(
15
,
15
))),
testing
::
Values
(
Anchor
(
cv
::
Point
(
-
1
,
-
1
)),
Anchor
(
cv
::
Point
(
0
,
0
)),
Anchor
(
cv
::
Point
(
2
,
2
))),
testing
::
Values
(
BorderType
(
cv
::
BORDER_REFLECT101
),
BorderType
(
cv
::
BORDER_REPLICATE
),
BorderType
(
cv
::
BORDER_CONSTANT
),
BorderType
(
cv
::
BORDER_REFLECT
)),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Laplacian
PARAM_TEST_CASE
(
Laplacian
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
MatType
,
KSize
,
UseRoi
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
Size
size
;
int
type
;
cv
::
Size
ksize
;
bool
useRoi
;
virtual
void
SetUp
()
{
devInfo
=
GET_PARAM
(
0
);
size
=
GET_PARAM
(
1
);
type
=
GET_PARAM
(
2
);
ksize
=
GET_PARAM
(
3
);
useRoi
=
GET_PARAM
(
4
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
}
};
GPU_TEST_P
(
Laplacian
,
Accuracy
)
{
cv
::
Mat
src
=
randomMat
(
size
,
type
);
cv
::
gpu
::
GpuMat
dst
=
createMat
(
size
,
type
,
useRoi
);
cv
::
gpu
::
Laplacian
(
loadMat
(
src
,
useRoi
),
dst
,
-
1
,
ksize
.
width
);
cv
::
Mat
dst_gold
;
cv
::
Laplacian
(
src
,
dst_gold
,
-
1
,
ksize
.
width
);
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
src
.
depth
()
<
CV_32F
?
0.0
:
1e-3
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_Filters
,
Laplacian
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC4
),
MatType
(
CV_32FC1
)),
testing
::
Values
(
KSize
(
cv
::
Size
(
1
,
1
)),
KSize
(
cv
::
Size
(
3
,
3
))),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Sobel
...
...
@@ -332,49 +447,6 @@ INSTANTIATE_TEST_CASE_P(GPU_Filters, GaussianBlur, testing::Combine(
BorderType
(
cv
::
BORDER_REFLECT
)),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Laplacian
PARAM_TEST_CASE
(
Laplacian
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
MatType
,
KSize
,
UseRoi
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
Size
size
;
int
type
;
cv
::
Size
ksize
;
bool
useRoi
;
virtual
void
SetUp
()
{
devInfo
=
GET_PARAM
(
0
);
size
=
GET_PARAM
(
1
);
type
=
GET_PARAM
(
2
);
ksize
=
GET_PARAM
(
3
);
useRoi
=
GET_PARAM
(
4
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
}
};
GPU_TEST_P
(
Laplacian
,
Accuracy
)
{
cv
::
Mat
src
=
randomMat
(
size
,
type
);
cv
::
gpu
::
GpuMat
dst
=
createMat
(
size
,
type
,
useRoi
);
cv
::
gpu
::
Laplacian
(
loadMat
(
src
,
useRoi
),
dst
,
-
1
,
ksize
.
width
);
cv
::
Mat
dst_gold
;
cv
::
Laplacian
(
src
,
dst_gold
,
-
1
,
ksize
.
width
);
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
src
.
depth
()
<
CV_32F
?
0.0
:
1e-3
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_Filters
,
Laplacian
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC4
),
MatType
(
CV_32FC1
)),
testing
::
Values
(
KSize
(
cv
::
Size
(
1
,
1
)),
KSize
(
cv
::
Size
(
3
,
3
))),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Erode
...
...
@@ -527,56 +599,4 @@ INSTANTIATE_TEST_CASE_P(GPU_Filters, MorphEx, testing::Combine(
testing
::
Values
(
Iterations
(
1
),
Iterations
(
2
),
Iterations
(
3
)),
WHOLE_SUBMAT
));
/////////////////////////////////////////////////////////////////////////////////////////////////
// Filter2D
PARAM_TEST_CASE
(
Filter2D
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
MatType
,
KSize
,
Anchor
,
BorderType
,
UseRoi
)
{
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
Size
size
;
int
type
;
cv
::
Size
ksize
;
cv
::
Point
anchor
;
int
borderType
;
bool
useRoi
;
cv
::
Mat
img
;
virtual
void
SetUp
()
{
devInfo
=
GET_PARAM
(
0
);
size
=
GET_PARAM
(
1
);
type
=
GET_PARAM
(
2
);
ksize
=
GET_PARAM
(
3
);
anchor
=
GET_PARAM
(
4
);
borderType
=
GET_PARAM
(
5
);
useRoi
=
GET_PARAM
(
6
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
}
};
GPU_TEST_P
(
Filter2D
,
Accuracy
)
{
cv
::
Mat
src
=
randomMat
(
size
,
type
);
cv
::
Mat
kernel
=
randomMat
(
cv
::
Size
(
ksize
.
width
,
ksize
.
height
),
CV_32FC1
,
0.0
,
1.0
);
cv
::
gpu
::
GpuMat
dst
=
createMat
(
size
,
type
,
useRoi
);
cv
::
gpu
::
filter2D
(
loadMat
(
src
,
useRoi
),
dst
,
-
1
,
kernel
,
anchor
,
borderType
);
cv
::
Mat
dst_gold
;
cv
::
filter2D
(
src
,
dst_gold
,
-
1
,
kernel
,
anchor
,
0
,
borderType
);
EXPECT_MAT_NEAR
(
dst_gold
,
dst
,
CV_MAT_DEPTH
(
type
)
==
CV_32F
?
1e-1
:
1.0
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_Filters
,
Filter2D
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
KSize
(
cv
::
Size
(
3
,
3
)),
KSize
(
cv
::
Size
(
5
,
5
)),
KSize
(
cv
::
Size
(
7
,
7
)),
KSize
(
cv
::
Size
(
11
,
11
)),
KSize
(
cv
::
Size
(
13
,
13
)),
KSize
(
cv
::
Size
(
15
,
15
))),
testing
::
Values
(
Anchor
(
cv
::
Point
(
-
1
,
-
1
)),
Anchor
(
cv
::
Point
(
0
,
0
)),
Anchor
(
cv
::
Point
(
2
,
2
))),
testing
::
Values
(
BorderType
(
cv
::
BORDER_REFLECT101
),
BorderType
(
cv
::
BORDER_REPLICATE
),
BorderType
(
cv
::
BORDER_CONSTANT
),
BorderType
(
cv
::
BORDER_REFLECT
)),
WHOLE_SUBMAT
));
#endif // HAVE_CUDA
samples/gpu/performance/tests.cpp
View file @
1eedc6c4
...
...
@@ -961,10 +961,11 @@ TEST(filter2D)
gpu
::
GpuMat
d_src
(
src
);
gpu
::
GpuMat
d_dst
;
gpu
::
filter2D
(
d_src
,
d_dst
,
-
1
,
kernel
);
Ptr
<
gpu
::
Filter
>
filter2D
=
gpu
::
createLinearFilter
(
d_src
.
type
(),
-
1
,
kernel
);
filter2D
->
apply
(
d_src
,
d_dst
);
GPU_ON
;
gpu
::
filter2D
(
d_src
,
d_dst
,
-
1
,
kernel
);
filter2D
->
apply
(
d_src
,
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