|
|
|
@ -44,6 +44,12 @@ |
|
|
|
|
#include "opencl_kernels_imgproc.hpp" |
|
|
|
|
#include "opencv2/core/hal/intrin.hpp" |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENVX |
|
|
|
|
#define IVX_HIDE_INFO_WARNINGS |
|
|
|
|
#define IVX_USE_OPENCV |
|
|
|
|
#include "ivx.hpp" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
@ -1244,6 +1250,99 @@ static bool ocl_threshold( InputArray _src, OutputArray _dst, double & thresh, d |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENVX |
|
|
|
|
#define IMPL_OPENVX_TOZERO 1 |
|
|
|
|
static bool openvx_threshold(Mat src, Mat dst, int thresh, int maxval, int type) |
|
|
|
|
{ |
|
|
|
|
Mat a = src; |
|
|
|
|
|
|
|
|
|
int trueVal, falseVal; |
|
|
|
|
switch (type) |
|
|
|
|
{ |
|
|
|
|
case THRESH_BINARY: |
|
|
|
|
#ifndef VX_VERSION_1_1 |
|
|
|
|
if (maxval != 255) |
|
|
|
|
return false; |
|
|
|
|
#endif |
|
|
|
|
trueVal = maxval; |
|
|
|
|
falseVal = 0; |
|
|
|
|
break; |
|
|
|
|
case THRESH_TOZERO: |
|
|
|
|
#if IMPL_OPENVX_TOZERO |
|
|
|
|
trueVal = 255; |
|
|
|
|
falseVal = 0; |
|
|
|
|
if (dst.data == src.data) |
|
|
|
|
{ |
|
|
|
|
a = Mat(src.size(), src.type()); |
|
|
|
|
src.copyTo(a); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
#endif |
|
|
|
|
case THRESH_BINARY_INV: |
|
|
|
|
#ifdef VX_VERSION_1_1 |
|
|
|
|
trueVal = 0; |
|
|
|
|
falseVal = maxval; |
|
|
|
|
break; |
|
|
|
|
#endif |
|
|
|
|
case THRESH_TOZERO_INV: |
|
|
|
|
#ifdef VX_VERSION_1_1 |
|
|
|
|
#if IMPL_OPENVX_TOZERO |
|
|
|
|
trueVal = 0; |
|
|
|
|
falseVal = 255; |
|
|
|
|
if (dst.data == src.data) |
|
|
|
|
{ |
|
|
|
|
a = Mat(src.size(), src.type()); |
|
|
|
|
src.copyTo(a); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
case THRESH_TRUNC: |
|
|
|
|
default: |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
ivx::Context ctx = ivx::Context::create(); |
|
|
|
|
|
|
|
|
|
ivx::Threshold thh = ivx::Threshold::createBinary(ctx, VX_TYPE_UINT8, thresh); |
|
|
|
|
thh.setValueTrue(trueVal); |
|
|
|
|
thh.setValueFalse(falseVal); |
|
|
|
|
|
|
|
|
|
ivx::Image |
|
|
|
|
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, |
|
|
|
|
ivx::Image::createAddressing(a.cols*a.channels(), a.rows, 1, (vx_int32)(a.step)), src.data), |
|
|
|
|
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, |
|
|
|
|
ivx::Image::createAddressing(dst.cols*dst.channels(), dst.rows, 1, (vx_int32)(dst.step)), dst.data); |
|
|
|
|
|
|
|
|
|
ivx::IVX_CHECK_STATUS(vxuThreshold(ctx, ia, thh, ib)); |
|
|
|
|
#if IMPL_OPENVX_TOZERO |
|
|
|
|
if (type == THRESH_TOZERO || type == THRESH_TOZERO_INV) |
|
|
|
|
{ |
|
|
|
|
ivx::Image |
|
|
|
|
ic = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, |
|
|
|
|
ivx::Image::createAddressing(dst.cols*dst.channels(), dst.rows, 1, (vx_int32)(dst.step)), dst.data); |
|
|
|
|
ivx::IVX_CHECK_STATUS(vxuAnd(ctx, ib, ia, ic)); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
catch (ivx::RuntimeError & e) |
|
|
|
|
{ |
|
|
|
|
CV_Error(CV_StsInternal, e.what()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
catch (ivx::WrapperError & e) |
|
|
|
|
{ |
|
|
|
|
CV_Error(CV_StsInternal, e.what()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type ) |
|
|
|
@ -1296,6 +1395,12 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m |
|
|
|
|
src.copyTo(dst); |
|
|
|
|
return thresh; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENVX |
|
|
|
|
if (openvx_threshold(src, dst, ithresh, imaxval, type)) |
|
|
|
|
return thresh; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
thresh = ithresh; |
|
|
|
|
maxval = imaxval; |
|
|
|
|
} |
|
|
|
|