add ocl::abs
This commit is contained in:
parent
c844bbdd82
commit
4ffd3fb905
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user