mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #26911 from asmorkalov:as/openvx_hal_imgproc
Migrate remaning OpenVX integrations to OpenVX HAL (imgproc)
This commit is contained in:
@@ -48,8 +48,6 @@
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
#include "opencl_kernels_imgproc.hpp"
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
|
||||
#include "box_filter.simd.hpp"
|
||||
#include "box_filter.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
|
||||
|
||||
@@ -315,80 +313,6 @@ Ptr<FilterEngine> createBoxFilter(int srcType, int dstType, Size ksize,
|
||||
CV_CPU_DISPATCH_MODES_ALL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace ovx {
|
||||
template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 640 * 480; }
|
||||
}
|
||||
static bool openvx_boxfilter(InputArray _src, OutputArray _dst, int ddepth,
|
||||
Size ksize, Point anchor,
|
||||
bool normalize, int borderType)
|
||||
{
|
||||
if (ddepth < 0)
|
||||
ddepth = CV_8UC1;
|
||||
if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize ||
|
||||
_src.cols() < 3 || _src.rows() < 3 ||
|
||||
ksize.width != 3 || ksize.height != 3 ||
|
||||
(anchor.x >= 0 && anchor.x != 1) ||
|
||||
(anchor.y >= 0 && anchor.y != 1) ||
|
||||
ovx::skipSmallImages<VX_KERNEL_BOX_3x3>(_src.cols(), _src.rows()))
|
||||
return false;
|
||||
|
||||
Mat src = _src.getMat();
|
||||
|
||||
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
|
||||
return false; //Process isolated borders only
|
||||
vx_enum border;
|
||||
switch (borderType & ~BORDER_ISOLATED)
|
||||
{
|
||||
case BORDER_CONSTANT:
|
||||
border = VX_BORDER_CONSTANT;
|
||||
break;
|
||||
case BORDER_REPLICATE:
|
||||
border = VX_BORDER_REPLICATE;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
_dst.create(src.size(), CV_8UC1);
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
|
||||
Mat a;
|
||||
if (dst.data != src.data)
|
||||
a = src;
|
||||
else
|
||||
src.copyTo(a);
|
||||
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
|
||||
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data);
|
||||
|
||||
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
|
||||
//since OpenVX standard says nothing about thread-safety for now
|
||||
ivx::border_t prevBorder = ctx.immediateBorder();
|
||||
ctx.setImmediateBorder(border, (vx_uint8)(0));
|
||||
ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
|
||||
ctx.setImmediateBorder(prevBorder);
|
||||
}
|
||||
catch (const ivx::RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const ivx::WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 //defined(HAVE_IPP)
|
||||
static bool ipp_boxfilter(Mat &src, Mat &dst, Size ksize, Point anchor, bool normalize, int borderType)
|
||||
{
|
||||
@@ -475,9 +399,6 @@ void boxFilter(InputArray _src, OutputArray _dst, int ddepth,
|
||||
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height,
|
||||
anchor.x, anchor.y, normalize, borderType&~BORDER_ISOLATED);
|
||||
|
||||
CV_OVX_RUN(true,
|
||||
openvx_boxfilter(src, dst, ddepth, ksize, anchor, normalize, borderType))
|
||||
|
||||
//CV_IPP_RUN_FAST(ipp_boxfilter(src, dst, ksize, anchor, normalize, borderType));
|
||||
|
||||
borderType = (borderType&~BORDER_ISOLATED);
|
||||
|
||||
@@ -45,8 +45,6 @@
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
#include <deque>
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@@ -761,65 +759,6 @@ private:
|
||||
finalPass& operator=(const finalPass&); // = delete
|
||||
};
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace ovx {
|
||||
template <> inline bool skipSmallImages<VX_KERNEL_CANNY_EDGE_DETECTOR>(int w, int h) { return w*h < 640 * 480; }
|
||||
}
|
||||
static bool openvx_canny(const Mat& src, Mat& dst, int loVal, int hiVal, int kSize, bool useL2)
|
||||
{
|
||||
using namespace ivx;
|
||||
|
||||
Context context = ovx::getOpenVXContext();
|
||||
try
|
||||
{
|
||||
Image _src = Image::createFromHandle(
|
||||
context,
|
||||
Image::matTypeToFormat(src.type()),
|
||||
Image::createAddressing(src),
|
||||
src.data );
|
||||
Image _dst = Image::createFromHandle(
|
||||
context,
|
||||
Image::matTypeToFormat(dst.type()),
|
||||
Image::createAddressing(dst),
|
||||
dst.data );
|
||||
Threshold threshold = Threshold::createRange(context, VX_TYPE_UINT8, saturate_cast<uchar>(loVal), saturate_cast<uchar>(hiVal));
|
||||
|
||||
#if 0
|
||||
// the code below is disabled because vxuCannyEdgeDetector()
|
||||
// ignores context attribute VX_CONTEXT_IMMEDIATE_BORDER
|
||||
|
||||
// FIXME: may fail in multithread case
|
||||
border_t prevBorder = context.immediateBorder();
|
||||
context.setImmediateBorder(VX_BORDER_REPLICATE);
|
||||
IVX_CHECK_STATUS( vxuCannyEdgeDetector(context, _src, threshold, kSize, (useL2 ? VX_NORM_L2 : VX_NORM_L1), _dst) );
|
||||
context.setImmediateBorder(prevBorder);
|
||||
#else
|
||||
// alternative code without vxuCannyEdgeDetector()
|
||||
Graph graph = Graph::create(context);
|
||||
ivx::Node node = ivx::Node(vxCannyEdgeDetectorNode(graph, _src, threshold, kSize, (useL2 ? VX_NORM_L2 : VX_NORM_L1), _dst) );
|
||||
node.setBorder(VX_BORDER_REPLICATE);
|
||||
graph.verify();
|
||||
graph.process();
|
||||
#endif
|
||||
|
||||
#ifdef VX_VERSION_1_1
|
||||
_src.swapHandle();
|
||||
_dst.swapHandle();
|
||||
#endif
|
||||
}
|
||||
catch(const WrapperError& e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch(const RuntimeError& e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // HAVE_OPENVX
|
||||
|
||||
void Canny( InputArray _src, OutputArray _dst,
|
||||
double low_thresh, double high_thresh,
|
||||
int aperture_size, bool L2gradient )
|
||||
@@ -864,21 +803,6 @@ void Canny( InputArray _src, OutputArray _dst,
|
||||
CALL_HAL(canny, cv_hal_canny, src.data, src.step, dst.data, dst.step, src.cols, src.rows, src.channels(),
|
||||
low_thresh, high_thresh, aperture_size, L2gradient);
|
||||
|
||||
CV_OVX_RUN(
|
||||
false && /* disabling due to accuracy issues */
|
||||
src.type() == CV_8UC1 &&
|
||||
!src.isSubmatrix() &&
|
||||
src.cols >= aperture_size &&
|
||||
src.rows >= aperture_size &&
|
||||
!ovx::skipSmallImages<VX_KERNEL_CANNY_EDGE_DETECTOR>(src.cols, src.rows),
|
||||
openvx_canny(
|
||||
src,
|
||||
dst,
|
||||
cvFloor(low_thresh),
|
||||
cvFloor(high_thresh),
|
||||
aperture_size,
|
||||
L2gradient ) )
|
||||
|
||||
CV_IPP_RUN_FAST(ipp_Canny(src, Mat(), Mat(), dst, (float)low_thresh, (float)high_thresh, L2gradient, aperture_size))
|
||||
|
||||
if (L2gradient)
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#include "precomp.hpp"
|
||||
#include "opencl_kernels_imgproc.hpp"
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
#include "filter.hpp"
|
||||
|
||||
/****************************************************************************************\
|
||||
@@ -182,83 +181,6 @@ cv::Ptr<cv::FilterEngine> cv::createDerivFilter(int srcType, int dstType,
|
||||
kx, ky, Point(-1,-1), 0, borderType );
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace cv
|
||||
{
|
||||
namespace ovx {
|
||||
template <> inline bool skipSmallImages<VX_KERNEL_SOBEL_3x3>(int w, int h) { return w*h < 320 * 240; }
|
||||
}
|
||||
static bool openvx_sobel(InputArray _src, OutputArray _dst,
|
||||
int dx, int dy, int ksize,
|
||||
double scale, double delta, int borderType)
|
||||
{
|
||||
if (_src.type() != CV_8UC1 || _dst.type() != CV_16SC1 ||
|
||||
ksize != 3 || scale != 1.0 || delta != 0.0 ||
|
||||
(dx | dy) != 1 || (dx + dy) != 1 ||
|
||||
_src.cols() < ksize || _src.rows() < ksize ||
|
||||
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(_src.cols(), _src.rows())
|
||||
)
|
||||
return false;
|
||||
|
||||
Mat src = _src.getMat();
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
|
||||
return false; //Process isolated borders only
|
||||
vx_enum border;
|
||||
switch (borderType & ~BORDER_ISOLATED)
|
||||
{
|
||||
case BORDER_CONSTANT:
|
||||
border = VX_BORDER_CONSTANT;
|
||||
break;
|
||||
case BORDER_REPLICATE:
|
||||
// border = VX_BORDER_REPLICATE;
|
||||
// break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
//if ((vx_size)ksize > ctx.convolutionMaxDimension())
|
||||
// return false;
|
||||
|
||||
Mat a;
|
||||
if (dst.data != src.data)
|
||||
a = src;
|
||||
else
|
||||
src.copyTo(a);
|
||||
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
|
||||
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_S16,
|
||||
ivx::Image::createAddressing(dst.cols, dst.rows, 2, (vx_int32)(dst.step)), dst.data);
|
||||
|
||||
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
|
||||
//since OpenVX standard says nothing about thread-safety for now
|
||||
ivx::border_t prevBorder = ctx.immediateBorder();
|
||||
ctx.setImmediateBorder(border, (vx_uint8)(0));
|
||||
if(dx)
|
||||
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL));
|
||||
else
|
||||
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib));
|
||||
ctx.setImmediateBorder(prevBorder);
|
||||
}
|
||||
catch (const ivx::RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const ivx::WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 //defined HAVE_IPP
|
||||
namespace cv
|
||||
@@ -456,9 +378,6 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy,
|
||||
CALL_HAL(sobel, cv_hal_sobel, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, ddepth, cn,
|
||||
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, dx, dy, ksize, scale, delta, borderType&~BORDER_ISOLATED);
|
||||
|
||||
CV_OVX_RUN(true,
|
||||
openvx_sobel(src, dst, dx, dy, ksize, scale, delta, borderType))
|
||||
|
||||
//CV_IPP_RUN_FAST(ipp_Deriv(src, dst, dx, dy, ksize, scale, delta, borderType));
|
||||
|
||||
sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType );
|
||||
|
||||
@@ -3396,43 +3396,6 @@ static bool ocl_equalizeHist(InputArray _src, OutputArray _dst)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace cv
|
||||
{
|
||||
static bool openvx_equalize_hist(Mat srcMat, Mat dstMat)
|
||||
{
|
||||
using namespace ivx;
|
||||
|
||||
try
|
||||
{
|
||||
Context context = ovx::getOpenVXContext();
|
||||
Image srcImage = Image::createFromHandle(context, Image::matTypeToFormat(srcMat.type()),
|
||||
Image::createAddressing(srcMat), srcMat.data);
|
||||
Image dstImage = Image::createFromHandle(context, Image::matTypeToFormat(dstMat.type()),
|
||||
Image::createAddressing(dstMat), dstMat.data);
|
||||
|
||||
IVX_CHECK_STATUS(vxuEqualizeHist(context, srcImage, dstImage));
|
||||
|
||||
#ifdef VX_VERSION_1_1
|
||||
//we should take user memory back before release
|
||||
//(it's not done automatically according to standard)
|
||||
srcImage.swapHandle(); dstImage.swapHandle();
|
||||
#endif
|
||||
}
|
||||
catch (const RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void cv::equalizeHist( InputArray _src, OutputArray _dst )
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
@@ -3449,9 +3412,6 @@ void cv::equalizeHist( InputArray _src, OutputArray _dst )
|
||||
_dst.create( src.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_EQUALIZE_HISTOGRAM>(src.cols, src.rows),
|
||||
openvx_equalize_hist(src, dst))
|
||||
|
||||
CALL_HAL(equalizeHist, cv_hal_equalize_hist, src.data, src.step, dst.data, dst.step, src.cols, src.rows);
|
||||
|
||||
Mutex histogramLockInstance;
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include "hal_replacement.hpp"
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
#include "opencv2/core/softfloat.hpp"
|
||||
#include "imgwarp.hpp"
|
||||
|
||||
@@ -1573,94 +1572,6 @@ static bool ocl_logPolar(InputArray _src, OutputArray _dst,
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
static bool openvx_remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation, const Scalar& borderValue)
|
||||
{
|
||||
vx_interpolation_type_e inter_type;
|
||||
switch (interpolation)
|
||||
{
|
||||
case INTER_LINEAR:
|
||||
#if VX_VERSION > VX_VERSION_1_0
|
||||
inter_type = VX_INTERPOLATION_BILINEAR;
|
||||
#else
|
||||
inter_type = VX_INTERPOLATION_TYPE_BILINEAR;
|
||||
#endif
|
||||
break;
|
||||
case INTER_NEAREST:
|
||||
/* NEAREST_NEIGHBOR mode disabled since OpenCV round half to even while OpenVX sample implementation round half up
|
||||
#if VX_VERSION > VX_VERSION_1_0
|
||||
inter_type = VX_INTERPOLATION_NEAREST_NEIGHBOR;
|
||||
#else
|
||||
inter_type = VX_INTERPOLATION_TYPE_NEAREST_NEIGHBOR;
|
||||
#endif
|
||||
if (!map1.empty())
|
||||
for (int y = 0; y < map1.rows; ++y)
|
||||
{
|
||||
float* line = map1.ptr<float>(y);
|
||||
for (int x = 0; x < map1.cols; ++x)
|
||||
line[x] = cvRound(line[x]);
|
||||
}
|
||||
if (!map2.empty())
|
||||
for (int y = 0; y < map2.rows; ++y)
|
||||
{
|
||||
float* line = map2.ptr<float>(y);
|
||||
for (int x = 0; x < map2.cols; ++x)
|
||||
line[x] = cvRound(line[x]);
|
||||
}
|
||||
break;
|
||||
*/
|
||||
case INTER_AREA://AREA interpolation mode is unsupported
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
|
||||
Mat a;
|
||||
if (dst.data != src.data)
|
||||
a = src;
|
||||
else
|
||||
src.copyTo(a);
|
||||
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
|
||||
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data);
|
||||
|
||||
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
|
||||
//since OpenVX standard says nothing about thread-safety for now
|
||||
ivx::border_t prevBorder = ctx.immediateBorder();
|
||||
ctx.setImmediateBorder(VX_BORDER_CONSTANT, (vx_uint8)(borderValue[0]));
|
||||
|
||||
ivx::Remap map = ivx::Remap::create(ctx, src.cols, src.rows, dst.cols, dst.rows);
|
||||
if (map1.empty()) map.setMappings(map2);
|
||||
else if (map2.empty()) map.setMappings(map1);
|
||||
else map.setMappings(map1, map2);
|
||||
ivx::IVX_CHECK_STATUS(vxuRemap(ctx, ia, map, inter_type, ib));
|
||||
#ifdef VX_VERSION_1_1
|
||||
ib.swapHandle();
|
||||
ia.swapHandle();
|
||||
#endif
|
||||
|
||||
ctx.setImmediateBorder(prevBorder);
|
||||
}
|
||||
catch (const ivx::RuntimeError & e)
|
||||
{
|
||||
CV_Error(cv::Error::StsInternal, e.what());
|
||||
return false;
|
||||
}
|
||||
catch (const ivx::WrapperError & e)
|
||||
{
|
||||
CV_Error(cv::Error::StsInternal, e.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined HAVE_IPP && !IPP_DISABLE_REMAP
|
||||
|
||||
typedef IppStatus (CV_STDCALL * ippiRemap)(const void * pSrc, IppiSize srcSize, int srcStep, IppiRect srcRoi,
|
||||
@@ -1799,17 +1710,6 @@ void cv::remap( InputArray _src, OutputArray _dst,
|
||||
_dst.create( map1.size(), src.type() );
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
CV_OVX_RUN(
|
||||
src.type() == CV_8UC1 && dst.type() == CV_8UC1 &&
|
||||
!ovx::skipSmallImages<VX_KERNEL_REMAP>(src.cols, src.rows) &&
|
||||
(borderType& ~BORDER_ISOLATED) == BORDER_CONSTANT &&
|
||||
((map1.type() == CV_32FC2 && map2.empty() && map1.size == dst.size) ||
|
||||
(map1.type() == CV_32FC1 && map2.type() == CV_32FC1 && map1.size == dst.size && map2.size == dst.size) ||
|
||||
(map1.empty() && map2.type() == CV_32FC2 && map2.size == dst.size)) &&
|
||||
((borderType & BORDER_ISOLATED) != 0 || !src.isSubmatrix()) &&
|
||||
!hasRelativeFlag,
|
||||
openvx_remap(src, dst, map1, map2, interpolation, borderValue));
|
||||
|
||||
CV_Assert( dst.cols < SHRT_MAX && dst.rows < SHRT_MAX && src.cols < SHRT_MAX && src.rows < SHRT_MAX );
|
||||
|
||||
if( dst.data == src.data )
|
||||
|
||||
@@ -48,8 +48,6 @@
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
#include "opencl_kernels_imgproc.hpp"
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
|
||||
#include "median_blur.simd.hpp"
|
||||
#include "median_blur.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
|
||||
|
||||
@@ -112,97 +110,6 @@ static bool ocl_medianFilter(InputArray _src, OutputArray _dst, int m)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace ovx {
|
||||
template <> inline bool skipSmallImages<VX_KERNEL_MEDIAN_3x3>(int w, int h) { return w*h < 1280 * 720; }
|
||||
}
|
||||
static bool openvx_medianFilter(InputArray _src, OutputArray _dst, int ksize)
|
||||
{
|
||||
if (_src.type() != CV_8UC1 || _dst.type() != CV_8U
|
||||
#ifndef VX_VERSION_1_1
|
||||
|| ksize != 3
|
||||
#endif
|
||||
)
|
||||
return false;
|
||||
|
||||
Mat src = _src.getMat();
|
||||
Mat dst = _dst.getMat();
|
||||
|
||||
if (
|
||||
#ifdef VX_VERSION_1_1
|
||||
ksize != 3 ? ovx::skipSmallImages<VX_KERNEL_NON_LINEAR_FILTER>(src.cols, src.rows) :
|
||||
#endif
|
||||
ovx::skipSmallImages<VX_KERNEL_MEDIAN_3x3>(src.cols, src.rows)
|
||||
)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
ivx::Context ctx = ovx::getOpenVXContext();
|
||||
#ifdef VX_VERSION_1_1
|
||||
if ((vx_size)ksize > ctx.nonlinearMaxDimension())
|
||||
return false;
|
||||
#endif
|
||||
|
||||
Mat a;
|
||||
if (dst.data != src.data)
|
||||
a = src;
|
||||
else
|
||||
src.copyTo(a);
|
||||
|
||||
ivx::Image
|
||||
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
|
||||
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
|
||||
ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data);
|
||||
|
||||
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
|
||||
//since OpenVX standard says nothing about thread-safety for now
|
||||
ivx::border_t prevBorder = ctx.immediateBorder();
|
||||
ctx.setImmediateBorder(VX_BORDER_REPLICATE);
|
||||
#ifdef VX_VERSION_1_1
|
||||
if (ksize == 3)
|
||||
#endif
|
||||
{
|
||||
ivx::IVX_CHECK_STATUS(vxuMedian3x3(ctx, ia, ib));
|
||||
}
|
||||
#ifdef VX_VERSION_1_1
|
||||
else
|
||||
{
|
||||
ivx::Matrix mtx;
|
||||
if(ksize == 5)
|
||||
mtx = ivx::Matrix::createFromPattern(ctx, VX_PATTERN_BOX, ksize, ksize);
|
||||
else
|
||||
{
|
||||
vx_size supportedSize;
|
||||
ivx::IVX_CHECK_STATUS(vxQueryContext(ctx, VX_CONTEXT_NONLINEAR_MAX_DIMENSION, &supportedSize, sizeof(supportedSize)));
|
||||
if ((vx_size)ksize > supportedSize)
|
||||
{
|
||||
ctx.setImmediateBorder(prevBorder);
|
||||
return false;
|
||||
}
|
||||
Mat mask(ksize, ksize, CV_8UC1, Scalar(255));
|
||||
mtx = ivx::Matrix::create(ctx, VX_TYPE_UINT8, ksize, ksize);
|
||||
mtx.copyFrom(mask);
|
||||
}
|
||||
ivx::IVX_CHECK_STATUS(vxuNonLinearFilter(ctx, VX_NONLINEAR_FILTER_MEDIAN, ia, mtx, ib));
|
||||
}
|
||||
#endif
|
||||
ctx.setImmediateBorder(prevBorder);
|
||||
}
|
||||
catch (const ivx::RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const ivx::WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 //defined HAVE_IPP
|
||||
static bool ipp_medianFilter(Mat &src0, Mat &dst, int ksize)
|
||||
{
|
||||
@@ -300,9 +207,6 @@ void medianBlur( InputArray _src0, OutputArray _dst, int ksize )
|
||||
CALL_HAL(medianBlur, cv_hal_medianBlur, src0.data, src0.step, dst.data, dst.step, src0.cols, src0.rows, src0.depth(),
|
||||
src0.channels(), ksize);
|
||||
|
||||
CV_OVX_RUN(true,
|
||||
openvx_medianFilter(_src0, _dst, ksize))
|
||||
|
||||
//CV_IPP_RUN_FAST(ipp_medianFilter(src0, dst, ksize));
|
||||
|
||||
CV_CPU_DISPATCH(medianBlur, (src0, dst, ksize),
|
||||
|
||||
@@ -45,8 +45,6 @@
|
||||
#include "opencl_kernels_imgproc.hpp"
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@@ -1266,85 +1264,6 @@ static bool ocl_pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENVX
|
||||
namespace cv
|
||||
{
|
||||
static bool openvx_pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
|
||||
{
|
||||
using namespace ivx;
|
||||
|
||||
Mat srcMat = _src.getMat();
|
||||
|
||||
if (ovx::skipSmallImages<VX_KERNEL_HALFSCALE_GAUSSIAN>(srcMat.cols, srcMat.rows))
|
||||
return false;
|
||||
|
||||
CV_Assert(!srcMat.empty());
|
||||
|
||||
Size ssize = _src.size();
|
||||
Size acceptableSize = Size((ssize.width + 1) / 2, (ssize.height + 1) / 2);
|
||||
|
||||
// OpenVX limitations
|
||||
if((srcMat.type() != CV_8U) ||
|
||||
(borderType != BORDER_REPLICATE) ||
|
||||
(_dsz != acceptableSize && !_dsz.empty()))
|
||||
return false;
|
||||
|
||||
// The only border mode which is supported by both cv::pyrDown() and OpenVX
|
||||
// and produces predictable results
|
||||
ivx::border_t borderMode;
|
||||
borderMode.mode = VX_BORDER_REPLICATE;
|
||||
|
||||
_dst.create( acceptableSize, srcMat.type() );
|
||||
Mat dstMat = _dst.getMat();
|
||||
|
||||
CV_Assert( ssize.width > 0 && ssize.height > 0 &&
|
||||
std::abs(acceptableSize.width*2 - ssize.width) <= 2 &&
|
||||
std::abs(acceptableSize.height*2 - ssize.height) <= 2 );
|
||||
|
||||
try
|
||||
{
|
||||
Context context = ovx::getOpenVXContext();
|
||||
if(context.vendorID() == VX_ID_KHRONOS)
|
||||
{
|
||||
// This implementation performs floor-like rounding
|
||||
// (OpenCV uses floor(x+0.5)-like rounding)
|
||||
// and ignores border mode (and loses 1px size border)
|
||||
return false;
|
||||
}
|
||||
|
||||
Image srcImg = Image::createFromHandle(context, Image::matTypeToFormat(srcMat.type()),
|
||||
Image::createAddressing(srcMat), (void*)srcMat.data);
|
||||
Image dstImg = Image::createFromHandle(context, Image::matTypeToFormat(dstMat.type()),
|
||||
Image::createAddressing(dstMat), (void*)dstMat.data);
|
||||
|
||||
ivx::Scalar kernelSize = ivx::Scalar::create<VX_TYPE_INT32>(context, 5);
|
||||
Graph graph = Graph::create(context);
|
||||
ivx::Node halfNode = ivx::Node::create(graph, VX_KERNEL_HALFSCALE_GAUSSIAN, srcImg, dstImg, kernelSize);
|
||||
halfNode.setBorder(borderMode);
|
||||
graph.verify();
|
||||
graph.process();
|
||||
|
||||
#ifdef VX_VERSION_1_1
|
||||
//we should take user memory back before release
|
||||
//(it's not done automatically according to standard)
|
||||
srcImg.swapHandle(); dstImg.swapHandle();
|
||||
#endif
|
||||
}
|
||||
catch (const RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
@@ -1354,9 +1273,6 @@ void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borde
|
||||
CV_OCL_RUN(_src.dims() <= 2 && _dst.isUMat(),
|
||||
ocl_pyrDown(_src, _dst, _dsz, borderType))
|
||||
|
||||
CV_OVX_RUN(_src.dims() <= 2,
|
||||
openvx_pyrDown(_src, _dst, _dsz, borderType))
|
||||
|
||||
Mat src = _src.getMat();
|
||||
Size dsz = _dsz.empty() ? Size((src.cols + 1)/2, (src.rows + 1)/2) : _dsz;
|
||||
_dst.create( dsz, src.type() );
|
||||
|
||||
@@ -713,8 +713,6 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
||||
// IPP is not bit-exact to OpenCV implementation
|
||||
CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType));
|
||||
#endif
|
||||
CV_OVX_RUN(true,
|
||||
openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType))
|
||||
}
|
||||
|
||||
CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint16_t*)&fkx[0], (int)fkx.size(), (const uint16_t*)&fky[0], (int)fky.size(), borderType),
|
||||
@@ -783,8 +781,6 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
||||
// IPP is not bit-exact to OpenCV implementation
|
||||
CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType));
|
||||
#endif
|
||||
CV_OVX_RUN(true,
|
||||
openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType))
|
||||
}
|
||||
|
||||
CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint32_t*)&fkx[0], (int)fkx.size(), (const uint32_t*)&fky[0], (int)fky.size(), borderType),
|
||||
@@ -814,9 +810,6 @@ void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
||||
ofs.x, ofs.y, wsz.width - src.cols - ofs.x, wsz.height - src.rows - ofs.y, ksize.width, ksize.height,
|
||||
sigma1, sigma2, borderType & ~BORDER_ISOLATED);
|
||||
|
||||
CV_OVX_RUN(true,
|
||||
openvx_gaussianBlur(src, dst, ksize, sigma1, sigma2, borderType))
|
||||
|
||||
#if defined ENABLE_IPP_GAUSSIAN_BLUR
|
||||
// IPP is not bit-exact to OpenCV implementation
|
||||
CV_IPP_RUN_FAST(ipp_GaussianBlur(src, dst, ksize, sigma1, sigma2, borderType));
|
||||
|
||||
@@ -44,8 +44,6 @@
|
||||
#include "opencl_kernels_imgproc.hpp"
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@@ -1447,97 +1445,6 @@ 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 = ovx::getOpenVXContext();
|
||||
|
||||
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 (const ivx::RuntimeError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
catch (const ivx::WrapperError & e)
|
||||
{
|
||||
VX_DbgThrow(e.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type )
|
||||
@@ -1605,9 +1512,6 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
|
||||
return thresh;
|
||||
}
|
||||
|
||||
CV_OVX_RUN(!ovx::skipSmallImages<VX_KERNEL_THRESHOLD>(src.cols, src.rows),
|
||||
openvx_threshold(src, dst, ithresh, imaxval, type), (double)ithresh)
|
||||
|
||||
thresh = ithresh;
|
||||
maxval = imaxval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user