.. 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
// 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);
/////////////// 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)
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();
}
//////////////////////////////////////////////////////////////////////////////
-///////////////////////////////// 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);
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; \
int dst_index = mad24(y, dst_step, x + dst_offset);
EXPRESSION
+
}
}
}
}
+//////////////////////////////// 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;
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()));