Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
82e6edfb
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
82e6edfb
编写于
3月 17, 2014
作者:
I
Ilya Lavrenov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimized sep filter
上级
dc28451b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
251 addition
and
33 deletion
+251
-33
modules/core/include/opencv2/core/ocl.hpp
modules/core/include/opencv2/core/ocl.hpp
+1
-1
modules/core/src/ocl.cpp
modules/core/src/ocl.cpp
+2
-2
modules/imgproc/perf/opencl/perf_filters.cpp
modules/imgproc/perf/opencl/perf_filters.cpp
+1
-1
modules/imgproc/src/filter.cpp
modules/imgproc/src/filter.cpp
+70
-29
modules/imgproc/src/opencl/filterSep_singlePass.cl
modules/imgproc/src/opencl/filterSep_singlePass.cl
+177
-0
未找到文件。
modules/core/include/opencv2/core/ocl.hpp
浏览文件 @
82e6edfb
...
...
@@ -592,7 +592,7 @@ protected:
CV_EXPORTS
const
char
*
convertTypeStr
(
int
sdepth
,
int
ddepth
,
int
cn
,
char
*
buf
);
CV_EXPORTS
const
char
*
typeToStr
(
int
t
);
CV_EXPORTS
const
char
*
memopTypeToStr
(
int
t
);
CV_EXPORTS
String
kernelToStr
(
InputArray
_kernel
,
int
ddepth
=
-
1
);
CV_EXPORTS
String
kernelToStr
(
InputArray
_kernel
,
int
ddepth
=
-
1
,
const
char
*
name
=
NULL
);
CV_EXPORTS
void
getPlatfomsInfo
(
std
::
vector
<
PlatformInfo
>&
platform_info
);
CV_EXPORTS
int
predictOptimalVectorWidth
(
InputArray
src1
,
InputArray
src2
=
noArray
(),
InputArray
src3
=
noArray
(),
InputArray
src4
=
noArray
(),
InputArray
src5
=
noArray
(),
InputArray
src6
=
noArray
(),
...
...
modules/core/src/ocl.cpp
浏览文件 @
82e6edfb
...
...
@@ -4306,7 +4306,7 @@ static std::string kerToStr(const Mat & k)
return
stream
.
str
();
}
String
kernelToStr
(
InputArray
_kernel
,
int
ddepth
)
String
kernelToStr
(
InputArray
_kernel
,
int
ddepth
,
const
char
*
name
)
{
Mat
kernel
=
_kernel
.
getMat
().
reshape
(
1
,
1
);
...
...
@@ -4323,7 +4323,7 @@ String kernelToStr(InputArray _kernel, int ddepth)
const
func_t
func
=
funcs
[
depth
];
CV_Assert
(
func
!=
0
);
return
cv
::
format
(
" -D
COEFF=%s
"
,
func
(
kernel
).
c_str
());
return
cv
::
format
(
" -D
%s=%s"
,
name
?
name
:
"COEFF
"
,
func
(
kernel
).
c_str
());
}
#define PROCESS_SRC(src) \
...
...
modules/imgproc/perf/opencl/perf_filters.cpp
浏览文件 @
82e6edfb
...
...
@@ -211,7 +211,7 @@ OCL_PERF_TEST_P(SobelFixture, Sobel,
OCL_TEST_CYCLE
()
cv
::
Sobel
(
src
,
dst
,
-
1
,
dx
,
dy
);
SANITY_CHECK
(
dst
);
SANITY_CHECK
(
dst
,
1e-6
);
}
///////////// Scharr ////////////////////////
...
...
modules/imgproc/src/filter.cpp
浏览文件 @
82e6edfb
...
...
@@ -3350,27 +3350,8 @@ static bool ocl_sepRowFilter2D( UMat &src, UMat &buf, Mat &kernelX, int anchor,
int
radiusY
=
(
int
)((
buf
.
rows
-
src
.
rows
)
>>
1
);
bool
isIsolatedBorder
=
(
borderType
&
BORDER_ISOLATED
)
!=
0
;
const
char
*
btype
=
NULL
;
switch
(
borderType
&
~
BORDER_ISOLATED
)
{
case
BORDER_CONSTANT
:
btype
=
"BORDER_CONSTANT"
;
break
;
case
BORDER_REPLICATE
:
btype
=
"BORDER_REPLICATE"
;
break
;
case
BORDER_REFLECT
:
btype
=
"BORDER_REFLECT"
;
break
;
case
BORDER_WRAP
:
btype
=
"BORDER_WRAP"
;
break
;
case
BORDER_REFLECT101
:
btype
=
"BORDER_REFLECT_101"
;
break
;
default:
return
false
;
}
const
char
*
const
borderMap
[]
=
{
"BORDER_CONSTANT"
,
"BORDER_REPLICATE"
,
"BORDER_REFLECT"
,
"BORDER_WRAP"
,
"BORDER_REFLECT_101"
},
*
const
btype
=
borderMap
[
borderType
&
~
BORDER_ISOLATED
];
bool
extra_extrapolation
=
src
.
rows
<
(
int
)((
-
radiusY
+
globalsize
[
1
])
>>
1
)
+
1
;
extra_extrapolation
|=
src
.
rows
<
radiusY
;
...
...
@@ -3463,36 +3444,96 @@ static bool ocl_sepColFilter2D(const UMat &buf, UMat &dst, Mat &kernelY, int anc
return
kernelCol
.
run
(
2
,
globalsize
,
localsize
,
sync
);
}
const
int
optimizedSepFilterLocalSize
=
16
;
static
bool
ocl_sepFilter2D_SinglePass
(
InputArray
_src
,
OutputArray
_dst
,
InputArray
_row_kernel
,
InputArray
_col_kernel
,
int
borderType
,
int
ddepth
)
{
Size
size
=
_src
.
size
(),
wholeSize
;
Point
origin
;
int
stype
=
_src
.
type
(),
sdepth
=
CV_MAT_DEPTH
(
stype
),
cn
=
CV_MAT_CN
(
stype
),
esz
=
CV_ELEM_SIZE
(
stype
),
wdepth
=
std
::
max
(
std
::
max
(
sdepth
,
ddepth
),
CV_32F
),
dtype
=
CV_MAKE_TYPE
(
ddepth
,
cn
);
size_t
src_step
=
_src
.
step
(),
src_offset
=
_src
.
offset
();
bool
doubleSupport
=
ocl
::
Device
::
getDefault
().
doubleFPConfig
()
>
0
;
if
((
src_offset
%
src_step
)
%
esz
!=
0
||
(
!
doubleSupport
&&
sdepth
==
CV_64F
)
||
!
(
borderType
==
BORDER_CONSTANT
||
borderType
==
BORDER_REPLICATE
||
borderType
==
BORDER_REFLECT
||
borderType
==
BORDER_WRAP
||
borderType
==
BORDER_REFLECT_101
))
return
false
;
size_t
lt2
[
2
]
=
{
optimizedSepFilterLocalSize
,
optimizedSepFilterLocalSize
};
size_t
gt2
[
2
]
=
{
lt2
[
0
]
*
(
1
+
(
size
.
width
-
1
)
/
lt2
[
0
]),
lt2
[
1
]
*
(
1
+
(
size
.
height
-
1
)
/
lt2
[
1
])
};
char
cvt
[
2
][
40
];
const
char
*
const
borderMap
[]
=
{
"BORDER_CONSTANT"
,
"BORDER_REPLICATE"
,
"BORDER_REFLECT"
,
"BORDER_WRAP"
,
"BORDER_REFLECT_101"
};
String
opts
=
cv
::
format
(
"-D BLK_X=%d -D BLK_Y=%d -D RADIUSX=%d -D RADIUSY=%d%s%s"
" -D srcT=%s -D convertToWT=%s -D WT=%s -D dstT=%s -D convertToDstT=%s"
" -D %s"
,
(
int
)
lt2
[
0
],
(
int
)
lt2
[
1
],
_row_kernel
.
size
().
height
/
2
,
_col_kernel
.
size
().
height
/
2
,
ocl
::
kernelToStr
(
_row_kernel
,
CV_32F
,
"KERNEL_MATRIX_X"
).
c_str
(),
ocl
::
kernelToStr
(
_col_kernel
,
CV_32F
,
"KERNEL_MATRIX_Y"
).
c_str
(),
ocl
::
typeToStr
(
stype
),
ocl
::
convertTypeStr
(
sdepth
,
wdepth
,
cn
,
cvt
[
0
]),
ocl
::
typeToStr
(
CV_MAKE_TYPE
(
wdepth
,
cn
)),
ocl
::
typeToStr
(
dtype
),
ocl
::
convertTypeStr
(
wdepth
,
ddepth
,
cn
,
cvt
[
1
]),
borderMap
[
borderType
]);
ocl
::
Kernel
k
(
"sep_filter"
,
ocl
::
imgproc
::
filterSep_singlePass_oclsrc
,
opts
);
if
(
k
.
empty
())
return
false
;
UMat
src
=
_src
.
getUMat
();
_dst
.
create
(
size
,
dtype
);
UMat
dst
=
_dst
.
getUMat
();
int
src_offset_x
=
static_cast
<
int
>
((
src_offset
%
src_step
)
/
esz
);
int
src_offset_y
=
static_cast
<
int
>
(
src_offset
/
src_step
);
src
.
locateROI
(
wholeSize
,
origin
);
k
.
args
(
ocl
::
KernelArg
::
PtrReadOnly
(
src
),
(
int
)
src_step
,
src_offset_x
,
src_offset_y
,
wholeSize
.
height
,
wholeSize
.
width
,
ocl
::
KernelArg
::
WriteOnly
(
dst
));
return
k
.
run
(
2
,
gt2
,
lt2
,
false
);
}
static
bool
ocl_sepFilter2D
(
InputArray
_src
,
OutputArray
_dst
,
int
ddepth
,
InputArray
_kernelX
,
InputArray
_kernelY
,
Point
anchor
,
double
delta
,
int
borderType
)
{
Size
imgSize
=
_src
.
size
();
if
(
abs
(
delta
)
>
FLT_MIN
)
return
false
;
int
type
=
_src
.
type
();
int
type
=
_src
.
type
()
,
cn
=
CV_MAT_CN
(
type
)
;
if
(
!
(
(
type
==
CV_8UC1
||
type
==
CV_8UC4
||
type
==
CV_32FC1
||
type
==
CV_32FC4
)
&&
(
ddepth
==
CV_32F
||
ddepth
==
CV_16S
||
ddepth
==
CV_8U
||
ddepth
<
0
)
)
)
return
false
;
int
cn
=
CV_MAT_CN
(
type
);
Mat
kernelX
=
_kernelX
.
getMat
().
reshape
(
1
,
1
);
if
(
1
!=
(
kernelX
.
cols
%
2
)
)
if
(
kernelX
.
cols
%
2
!=
1
)
return
false
;
Mat
kernelY
=
_kernelY
.
getMat
().
reshape
(
1
,
1
);
if
(
1
!=
(
kernelY
.
cols
%
2
)
)
if
(
kernelY
.
cols
%
2
!=
1
)
return
false
;
int
sdepth
=
CV_MAT_DEPTH
(
type
);
if
(
anchor
.
x
<
0
)
if
(
anchor
.
x
<
0
)
anchor
.
x
=
kernelX
.
cols
>>
1
;
if
(
anchor
.
y
<
0
)
if
(
anchor
.
y
<
0
)
anchor
.
y
=
kernelY
.
cols
>>
1
;
if
(
ddepth
<
0
)
if
(
ddepth
<
0
)
ddepth
=
sdepth
;
CV_OCL_RUN_
(
kernelY
.
rows
<=
21
&&
kernelX
.
rows
<=
21
&&
imgSize
.
width
>
optimizedSepFilterLocalSize
+
(
kernelX
.
rows
>>
1
)
&&
imgSize
.
height
>
optimizedSepFilterLocalSize
+
(
kernelY
.
rows
>>
1
),
ocl_sepFilter2D_SinglePass
(
_src
,
_dst
,
_kernelX
,
_kernelY
,
borderType
,
ddepth
),
true
)
UMat
src
=
_src
.
getUMat
();
Size
srcWholeSize
;
Point
srcOffset
;
src
.
locateROI
(
srcWholeSize
,
srcOffset
);
...
...
modules/imgproc/src/opencl/filterSep_singlePass.cl
0 → 100644
浏览文件 @
82e6edfb
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//
IMPORTANT:
READ
BEFORE
DOWNLOADING,
COPYING,
INSTALLING
OR
USING.
//
//
By
downloading,
copying,
installing
or
using
the
software
you
agree
to
this
license.
//
If
you
do
not
agree
to
this
license,
do
not
download,
install,
//
copy
or
use
the
software.
//
//
//
License
Agreement
//
For
Open
Source
Computer
Vision
Library
//
//
Copyright
(
C
)
2014
,
Intel
Corporation,
all
rights
reserved.
//
Third
party
copyrights
are
property
of
their
respective
owners.
//
//
Redistribution
and
use
in
source
and
binary
forms,
with
or
without
modification,
//
are
permitted
provided
that
the
following
conditions
are
met:
//
//
*
Redistribution
's
of
source
code
must
retain
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer.
//
//
*
Redistribution
's
in
binary
form
must
reproduce
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer
in
the
documentation
//
and/or
other
materials
provided
with
the
distribution.
//
//
*
The
name
of
the
copyright
holders
may
not
be
used
to
endorse
or
promote
products
//
derived
from
this
software
without
specific
prior
written
permission.
//
//
This
software
is
provided
by
the
copyright
holders
and
contributors
"as is"
and
//
any
express
or
implied
warranties,
including,
but
not
limited
to,
the
implied
//
warranties
of
merchantability
and
fitness
for
a
particular
purpose
are
disclaimed.
//
In
no
event
shall
the
Intel
Corporation
or
contributors
be
liable
for
any
direct,
//
indirect,
incidental,
special,
exemplary,
or
consequential
damages
//
(
including,
but
not
limited
to,
procurement
of
substitute
goods
or
services
;
//
loss
of
use,
data,
or
profits
; or business interruption) however caused
//
and
on
any
theory
of
liability,
whether
in
contract,
strict
liability,
//
or
tort
(
including
negligence
or
otherwise
)
arising
in
any
way
out
of
//
the
use
of
this
software,
even
if
advised
of
the
possibility
of
such
damage.
//
//M*/
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Macro
for
border
type////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
#
ifdef
BORDER_CONSTANT
//
CCCCCC|abcdefgh|CCCCCCC
#
define
EXTRAPOLATE
(
x,
maxV
)
#
elif
defined
BORDER_REPLICATE
//
aaaaaa|abcdefgh|hhhhhhh
#
define
EXTRAPOLATE
(
x,
maxV
)
\
{
\
(
x
)
=
max
(
min
((
x
)
,
(
maxV
)
-
1
)
,
0
)
; \
}
#
elif
defined
BORDER_WRAP
//
cdefgh|abcdefgh|abcdefg
#
define
EXTRAPOLATE
(
x,
maxV
)
\
{
\
(
x
)
=
(
(
x
)
+
(
maxV
)
)
%
(
maxV
)
; \
}
#
elif
defined
BORDER_REFLECT
//
fedcba|abcdefgh|hgfedcb
#
define
EXTRAPOLATE
(
x,
maxV
)
\
{
\
(
x
)
=
min
(((
maxV
)
-1
)
*2-
(
x
)
+1
,
max
((
x
)
,
-
(
x
)
-1
)
)
; \
}
#
elif
defined
BORDER_REFLECT_101
|
| defined BORDER_REFLECT101
// gfedcb|abcdefgh|gfedcba
#define EXTRAPOLATE(x, maxV) \
{ \
(x) = min(((maxV)-1)*2-(x), max((x),-(x)) ); \
}
#else
#error No extrapolation method
#endif
#define SRC(_x,_y) convertToWT(((global srcT*)(Src+(_y)*src_step))[_x])
#ifdef BORDER_CONSTANT
// CCCCCC|abcdefgh|CCCCCCC
#define ELEM(_x,_y,r_edge,t_edge,const_v) (_x)<0 |
(
_x
)
>=
(
r_edge
)
| (_y)<0 |
(
_y
)
>=
(
t_edge
)
?
(
const_v
)
:
SRC
((
_x
)
,
(
_y
))
#
else
#
define
ELEM
(
_x,_y,r_edge,t_edge,const_v
)
SRC
((
_x
)
,
(
_y
))
#
endif
#
define
DST
(
_x,_y
)
(((
global
dstT*
)(
Dst+dst_offset+
(
_y
)
*dst_step
))
[_x]
)
#
define
noconvert
//
horizontal
and
vertical
filter
kernels
//
should
be
defined
on
host
during
compile
time
to
avoid
overhead
#
define
DIG
(
a
)
a,
__constant
float
mat_kernelX[]
=
{
KERNEL_MATRIX_X
}
;
__constant
float
mat_kernelY[]
=
{
KERNEL_MATRIX_Y
}
;
__kernel
void
sep_filter
(
__global
uchar*
Src,
int
src_step,
int
srcOffsetX,
int
srcOffsetY,
int
height,
int
width,
__global
uchar*
Dst,
int
dst_step,
int
dst_offset,
int
dst_rows,
int
dst_cols
)
{
//
RADIUSX,
RADIUSY
are
filter
dimensions
//
BLK_X,
BLK_Y
are
local
wrogroup
sizes
//
all
these
should
be
defined
on
host
during
compile
time
//
first
lsmem
array
for
source
pixels
used
in
first
pass,
//
second
lsmemDy
for
storing
first
pass
results
__local
WT
lsmem[BLK_Y+2*RADIUSY][BLK_X+2*RADIUSX]
;
__local
WT
lsmemDy[BLK_Y][BLK_X+2*RADIUSX]
;
//
get
local
and
global
ids
-
used
as
image
and
local
memory
array
indexes
int
lix
=
get_local_id
(
0
)
;
int
liy
=
get_local_id
(
1
)
;
int
x
=
(
int
)
get_global_id
(
0
)
;
int
y
=
(
int
)
get_global_id
(
1
)
;
//
calculate
pixel
position
in
source
image
taking
image
offset
into
account
int
srcX
=
x
+
srcOffsetX
-
RADIUSX
;
int
srcY
=
y
+
srcOffsetY
-
RADIUSY
;
int
xb
=
srcX
;
int
yb
=
srcY
;
//
extrapolate
coordinates,
if
needed
//
and
read
my
own
source
pixel
into
local
memory
//
with
account
for
extra
border
pixels,
which
will
be
read
by
starting
workitems
int
clocY
=
liy
;
int
cSrcY
=
srcY
;
do
{
int
yb
=
cSrcY
;
EXTRAPOLATE
(
yb,
(
height
))
;
int
clocX
=
lix
;
int
cSrcX
=
srcX
;
do
{
int
xb
=
cSrcX
;
EXTRAPOLATE
(
xb,
(
width
))
;
lsmem[clocY][clocX]
=
ELEM
(
xb,
yb,
(
width
)
,
(
height
)
,
0
)
;
clocX
+=
BLK_X
;
cSrcX
+=
BLK_X
;
}
while
(
clocX
<
BLK_X+
(
RADIUSX*2
))
;
clocY
+=
BLK_Y
;
cSrcY
+=
BLK_Y
;
}
while
(
clocY
<
BLK_Y+
(
RADIUSY*2
))
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
//
do
vertical
filter
pass
//
and
store
intermediate
results
to
second
local
memory
array
int
i,
clocX
=
lix
;
WT
sum
=
0.0f
;
do
{
sum
=
0.0f
;
for
(
i=0
; i<=2*RADIUSY; i++)
sum
=
mad
(
lsmem[liy+i][clocX],
mat_kernelY[i],
sum
)
;
lsmemDy[liy][clocX]
=
sum
;
clocX
+=
BLK_X
;
}
while
(
clocX
<
BLK_X+
(
RADIUSX*2
))
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
//
if
this
pixel
happened
to
be
out
of
image
borders
because
of
global
size
rounding,
//
then
just
return
if
(
x
>=
dst_cols
||
y
>=dst_rows
)
return
;
//
do
second
horizontal
filter
pass
//
and
calculate
final
result
sum
=
0.0f
;
for
(
i=0
; i<=2*RADIUSX; i++)
sum
=
mad
(
lsmemDy[liy][lix+i],
mat_kernelX[i],
sum
)
;
//store
result
into
destination
image
DST
(
x,y
)
=
convertToDstT
(
sum
)
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录