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
4ffd3fb9
Commit
4ffd3fb9
authored
Oct 08, 2013
by
Sebastian Krämer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ocl::abs
parent
c844bbdd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
3 deletions
+49
-3
operations_on_matrices.rst
modules/ocl/doc/operations_on_matrices.rst
+12
-0
ocl.hpp
modules/ocl/include/opencv2/ocl/ocl.hpp
+4
-0
arithm.cpp
modules/ocl/src/arithm.cpp
+9
-3
arithm_add_scalar.cl
modules/ocl/src/opencl/arithm_add_scalar.cl
+7
-0
test_arithm.cpp
modules/ocl/test/test_arithm.cpp
+17
-0
No files found.
modules/ocl/doc/operations_on_matrices.rst
View file @
4ffd3fb9
...
...
@@ -3,6 +3,18 @@ Operations on Matrics
.. highlight:: cpp
ocl::abs
------------------
Returns void
.. ocv:function:: void ocl::absdiff(const oclMat& src, oclMat& dst)
:param src: input array.
:param dst: destination array, it will have the same size and same type as ``src``.
Computes per-element absolute values of the input array. Supports all data types.
ocl::absdiff
------------------
Returns void
...
...
modules/ocl/include/opencv2/ocl/ocl.hpp
View file @
4ffd3fb9
...
...
@@ -473,6 +473,10 @@ namespace cv
// supports all data types
CV_EXPORTS
void
transpose
(
const
oclMat
&
src
,
oclMat
&
dst
);
//! computes element-wise absolute values of an array (dst = abs(src))
// supports all data types
CV_EXPORTS
void
abs
(
const
oclMat
&
src
,
oclMat
&
dst
);
//! computes element-wise absolute difference of two arrays (dst = abs(src1 - src2))
// supports all data types
CV_EXPORTS
void
absdiff
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
oclMat
&
dst
);
...
...
modules/ocl/src/arithm.cpp
View file @
4ffd3fb9
...
...
@@ -60,7 +60,7 @@ using namespace cv::ocl;
/////////////// add subtract multiply divide min max /////////////////////////
//////////////////////////////////////////////////////////////////////////////
enum
{
ADD
=
0
,
SUB
,
MUL
,
DIV
,
ABS_DIFF
,
MIN
,
MAX
};
enum
{
ADD
=
0
,
SUB
,
MUL
,
DIV
,
ABS
,
ABS
_DIFF
,
MIN
,
MAX
};
static
void
arithmetic_run_generic
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
const
Scalar
&
scalar
,
const
oclMat
&
mask
,
oclMat
&
dst
,
int
op_type
,
bool
use_scalar
=
false
)
...
...
@@ -93,7 +93,7 @@ static void arithmetic_run_generic(const oclMat &src1, const oclMat &src2, const
const
char
*
const
typeMap
[]
=
{
"uchar"
,
"char"
,
"ushort"
,
"short"
,
"int"
,
"float"
,
"double"
};
const
char
*
const
WTypeMap
[]
=
{
"short"
,
"short"
,
"int"
,
"int"
,
"int"
,
"float"
,
"double"
};
const
char
*
const
funcMap
[]
=
{
"FUNC_ADD"
,
"FUNC_SUB"
,
"FUNC_MUL"
,
"FUNC_DIV"
,
"FUNC_ABS_DIFF"
,
"FUNC_MIN"
,
"FUNC_MAX"
};
const
char
*
const
funcMap
[]
=
{
"FUNC_ADD"
,
"FUNC_SUB"
,
"FUNC_MUL"
,
"FUNC_DIV"
,
"FUNC_ABS
"
,
"FUNC_ABS
_DIFF"
,
"FUNC_MIN"
,
"FUNC_MAX"
};
const
char
*
const
channelMap
[]
=
{
""
,
""
,
"2"
,
"4"
,
"4"
};
bool
haveScalar
=
use_scalar
||
src2
.
empty
();
...
...
@@ -216,9 +216,15 @@ void cv::ocl::max(const oclMat &src1, const oclMat &src2, oclMat &dst)
}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////
////
Absdiff ////////////////////////////////////
/////////////////////////////
Abs,
Absdiff ////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void
cv
::
ocl
::
abs
(
const
oclMat
&
src1
,
oclMat
&
dst
)
{
// explicitly uses use_scalar (even if zero) so that the correct kernel is used
arithmetic_run_generic
(
src1
,
oclMat
(),
Scalar
(),
oclMat
(),
dst
,
ABS
,
true
);
}
void
cv
::
ocl
::
absdiff
(
const
oclMat
&
src1
,
const
oclMat
&
src2
,
oclMat
&
dst
)
{
arithmetic_run_generic
(
src1
,
src2
,
Scalar
(),
oclMat
(),
dst
,
ABS_DIFF
);
...
...
modules/ocl/src/opencl/arithm_add_scalar.cl
View file @
4ffd3fb9
...
...
@@ -68,6 +68,12 @@
dst[dst_index]
=
src1[src1_index]
==
zero
?
zero
:
convertToT
(
scalar[0]
/
convertToWT
(
src1[src1_index]
))
;
#
endif
#
if
defined
(
FUNC_ABS
)
#
define
EXPRESSION
\
T
value
=
(
src1[src1_index]
>
0
)
?
src1[src1_index]
:
-src1[src1_index]
; \
dst[dst_index]
=
value
;
#
endif
#
if
defined
(
FUNC_ABS_DIFF
)
#
define
EXPRESSION
WT
value
=
convertToWT
(
src1[src1_index]
)
-
scalar[0]
; \
value
=
value
>
(
WT
)(
0
)
?
value
:
-value
; \
...
...
@@ -92,5 +98,6 @@ __kernel void arithm_binary_op_scalar (__global T *src1, int src1_step, int src1
int
dst_index
=
mad24
(
y,
dst_step,
x
+
dst_offset
)
;
EXPRESSION
}
}
modules/ocl/test/test_arithm.cpp
View file @
4ffd3fb9
...
...
@@ -481,6 +481,22 @@ TEST_P(Max, Mat)
}
}
//////////////////////////////// Abs /////////////////////////////////////////////////////
typedef
ArithmTestBase
Abs
;
TEST_P
(
Abs
,
Abs
)
{
for
(
int
j
=
0
;
j
<
LOOP_TIMES
;
j
++
)
{
random_roi
();
dst1_roi
=
cv
::
abs
(
src1_roi
);
cv
::
ocl
::
abs
(
gsrc1
,
gdst1
);
Near
(
0
);
}
}
//////////////////////////////// Absdiff /////////////////////////////////////////////////
typedef
ArithmTestBase
Absdiff
;
...
...
@@ -1483,6 +1499,7 @@ INSTANTIATE_TEST_CASE_P(Arithm, Mul, Combine(testing::Range(CV_8U, CV_USRTYPE1),
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Div
,
Combine
(
testing
::
Range
(
CV_8U
,
CV_USRTYPE1
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Min
,
Combine
(
testing
::
Range
(
CV_8U
,
CV_USRTYPE1
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Max
,
Combine
(
testing
::
Range
(
CV_8U
,
CV_USRTYPE1
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Abs
,
Combine
(
testing
::
Range
(
CV_8U
,
CV_USRTYPE1
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
Absdiff
,
Combine
(
testing
::
Range
(
CV_8U
,
CV_USRTYPE1
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
CartToPolar
,
Combine
(
Values
(
CV_32F
,
CV_64F
),
testing
::
Range
(
1
,
5
),
Bool
()));
INSTANTIATE_TEST_CASE_P
(
Arithm
,
PolarToCart
,
Combine
(
Values
(
CV_32F
,
CV_64F
),
testing
::
Range
(
1
,
5
),
Bool
()));
...
...
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