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
16ab6ec5
Commit
16ab6ec5
authored
Jun 26, 2014
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ported changes from PR #2867
parent
a3592cd0
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
44 deletions
+43
-44
morph.cpp
modules/imgproc/src/morph.cpp
+0
-0
morph.cl
modules/imgproc/src/opencl/morph.cl
+43
-44
No files found.
modules/imgproc/src/morph.cpp
View file @
16ab6ec5
This diff is collapsed.
Click to expand it.
modules/imgproc/src/opencl/morph.cl
View file @
16ab6ec5
...
...
@@ -54,59 +54,70 @@
#
endif
#
ifdef
DEPTH_0
#
ifdef
ERODE
#
define
VAL
255
#
endif
#
ifdef
DILATE
#
define
VAL
0
#
endif
#
define
MIN_VAL
0
#
define
MAX_VAL
UCHAR_MAX
#
elif
defined
DEPTH_1
#
define
MIN_VAL
SCHAR_MIN
#
define
MAX_VAL
SCHAR_MAX
#
elif
defined
DEPTH_2
#
define
MIN_VAL
0
#
define
MAX_VAL
USHRT_MAX
#
elif
defined
DEPTH_3
#
define
MIN_VAL
SHRT_MIN
#
define
MAX_VAL
SHRT_MAX
#
elif
defined
DEPTH_4
#
define
MIN_VAL
INT_MIN
#
define
MAX_VAL
INT_MAX
#
elif
defined
DEPTH_5
#
ifdef
ERODE
#
define
VAL
FLT_MAX
#
endif
#
ifdef
DILATE
#
define
VAL
-FLT_MAX
#
endif
#
define
MIN_VAL
(
-FLT_MAX
)
#
define
MAX_VAL
FLT_MAX
#
elif
defined
DEPTH_6
#
ifdef
ERODE
#
define
VAL
DBL_MAX
#
endif
#
ifdef
DILATE
#
define
VAL
-DBL_MAX
#
define
MIN_VAL
(
-DBL_MAX
)
#
define
MAX_VAL
DBL_MAX
#
endif
#
ifdef
OP_ERODE
#
define
VAL
MAX_VAL
#
elif
defined
OP_DILATE
#
define
VAL
MIN_VAL
#
else
#
error
"Unknown operation"
#
endif
#
ifdef
ERODE
#
if
defined
(
INTEL_DEVICE
)
&&
(
DEPTH_0
)
#
ifdef
OP_
ERODE
#
if
defined
INTEL_DEVICE
&&
defined
DEPTH_0
//
workaround
for
bug
in
Intel
HD
graphics
drivers
(
10.18.10.3496
or
older
)
#
define
__CAT
(
x,
y
)
x##y
#
define
CAT
(
x,
y
)
__CAT
(
x,
y
)
#
define
WA_CONVERT_1
CAT
(
convert_uint,
cn
)
#
define
WA_CONVERT_2
CAT
(
convert_,
T
)
#
define
convert_uint1
convert_uint
#
define
MORPH_OP
(
A,
B
)
WA_CONVERT_2
(
min
(
WA_CONVERT_1
(
A
)
,
WA_CONVERT_1
(
B
)))
#
define
MORPH_OP
(
A,
B
)
WA_CONVERT_2
(
min
(
WA_CONVERT_1
(
A
)
,
WA_CONVERT_1
(
B
)))
#
else
#
define
MORPH_OP
(
A,
B
)
min
((
A
)
,
(
B
))
#
define
MORPH_OP
(
A,
B
)
min
((
A
)
,
(
B
))
#
endif
#
endif
#
ifdef
DILATE
#
define
MORPH_OP
(
A,
B
)
max
((
A
)
,
(
B
))
#
ifdef
OP_
DILATE
#
define
MORPH_OP
(
A,
B
)
max
((
A
)
,
(
B
))
#
endif
#
define
PROCESS
(
y,
x
)
\
res
=
MORPH_OP
(
res,
LDS_DAT[mad24
(
l_y
+
y,
width,
l_x
+
x
)
]
)
;
//
BORDER_CONSTANT:
iiiiii|abcdefgh|iiiiiii
#
define
ELEM
(
i,
l_edge,
r_edge,
elem1,
elem2
)
(
i
)
<
(
l_edge
)
|
(
i
)
>=
(
r_edge
)
?
(
elem1
)
:
(
elem2
)
__kernel
void
morph
(
__global
const
uchar
*
srcptr,
int
src_step,
int
src_offset,
__global
uchar
*
dstptr,
int
dst_step,
int
dst_offset,
int
src_offset_x,
int
src_offset_y,
int
cols,
int
rows,
__constant
uchar
*
mat_kernel,
int
src_whole_cols,
int
src_whole_rows
)
int
src_whole_cols,
int
src_whole_rows
EXTRA_PARAMS
)
{
int
gidx
=
get_global_id
(
0
)
,
gidy
=
get_global_id
(
1
)
;
int
l_x
=
get_local_id
(
0
)
,
l_y
=
get_local_id
(
1
)
;
int
x
=
get_group_id
(
0
)
*
LSIZE0,
y
=
get_group_id
(
1
)
*
LSIZE1
;
int
start_x
=
x
+
src_offset_x
-
RADIUSX
;
int
end_x
=
x
+
src_offset_x
+
LSIZE0
+
RADIUSX
;
int
width
=
end_x
-
(
x
+
src_offset_x
-
RADIUSX
)
+
1
;
int
width
=
mad24
(
RADIUSX,
2
,
LSIZE0
+
1
)
;
int
start_y
=
y
+
src_offset_y
-
RADIUSY
;
int
point1
=
mad24
(
l_y,
LSIZE0,
l_x
)
;
int
point2
=
point1
+
LSIZE0
*
LSIZE1
;
...
...
@@ -117,7 +128,7 @@ __kernel void morph(__global const uchar * srcptr, int src_step, int src_offset,
int
start_addr
=
mad24
(
cur_y,
src_step,
cur_x
*
TSIZE
)
;
int
start_addr2
=
mad24
(
cur_y2,
src_step,
cur_x2
*
TSIZE
)
;
__local
T
LDS_DAT[2
*LSIZE1*
LSIZE0]
;
__local
T
LDS_DAT[2
*
LSIZE1
*
LSIZE0]
;
//
read
pixels
from
src
int
end_addr
=
mad24
(
src_whole_rows
-
1
,
src_step,
src_whole_cols
*
TSIZE
)
;
...
...
@@ -128,8 +139,8 @@ __kernel void morph(__global const uchar * srcptr, int src_step, int src_offset,
T
temp1
=
loadpix
(
srcptr
+
start_addr2
)
;
//
judge
if
read
out
of
boundary
temp0
=
ELEM
(
cur_x,
0
,
src_whole_cols,
(
T
)(
VAL
)
,
temp0
)
;
temp0
=
ELEM
(
cur_y,
0
,
src_whole_rows,
(
T
)(
VAL
)
,
temp0
)
;
temp0
=
ELEM
(
cur_x,
0
,
src_whole_cols,
(
T
)(
VAL
)
,
temp0
)
;
temp0
=
ELEM
(
cur_y,
0
,
src_whole_rows,
(
T
)(
VAL
)
,
temp0
)
;
temp1
=
ELEM
(
cur_x2,
0
,
src_whole_cols,
(
T
)(
VAL
)
,
temp1
)
;
temp1
=
ELEM
(
cur_y2,
0
,
src_whole_rows,
(
T
)(
VAL
)
,
temp1
)
;
...
...
@@ -138,23 +149,11 @@ __kernel void morph(__global const uchar * srcptr, int src_step, int src_offset,
LDS_DAT[point2]
=
temp1
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
T
res
=
(
T
)(
VAL
)
;
for
(
int
i
=
0
,
sizey
=
2
*
RADIUSY
+
1
; i < sizey; i++)
for
(
int
j
=
0
,
sizex
=
2
*
RADIUSX
+
1
; j < sizex; j++)
{
res
=
#
ifndef
RECTKERNEL
mat_kernel[i*
(
2*RADIUSX+1
)
+j]
?
#
endif
MORPH_OP
(
res,
LDS_DAT[mad24
(
l_y
+
i,
width,
l_x
+
j
)
]
)
#
ifndef
RECTKERNEL
:
res
#
endif
;
}
if
(
gidx
<
cols
&&
gidy
<
rows
)
{
T
res
=
(
T
)(
VAL
)
;
PROCESS_ELEMS
;
int
dst_index
=
mad24
(
gidy,
dst_step,
mad24
(
gidx,
TSIZE,
dst_offset
))
;
storepix
(
res,
dstptr
+
dst_index
)
;
}
...
...
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