Commit 87bb7431 authored by Vitaly Tuzov's avatar Vitaly Tuzov

Disabled vxuConvolution call for Sobel, GaussianBlur and Box filter evaluation

parent 0f1a56da
...@@ -32,7 +32,6 @@ template <> inline bool skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(int w, int h) { ...@@ -32,7 +32,6 @@ template <> inline bool skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(int w, int h) {
template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 640 * 480; } template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 640 * 480; }
template <> inline bool skipSmallImages<VX_KERNEL_HISTOGRAM>(int w, int h) { return w*h < 2048 * 1536; } template <> inline bool skipSmallImages<VX_KERNEL_HISTOGRAM>(int w, int h) { return w*h < 2048 * 1536; }
template <> inline bool skipSmallImages<VX_KERNEL_SOBEL_3x3>(int w, int h) { return w*h < 320 * 240; } template <> inline bool skipSmallImages<VX_KERNEL_SOBEL_3x3>(int w, int h) { return w*h < 320 * 240; }
template <> inline bool skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(int w, int h) { return w*h < 640 * 480; }
}} }}
......
...@@ -188,43 +188,17 @@ namespace cv ...@@ -188,43 +188,17 @@ namespace cv
int dx, int dy, int ksize, int dx, int dy, int ksize,
double scale, double delta, int borderType) double scale, double delta, int borderType)
{ {
int stype = _src.type(); if (_src.type() != CV_8UC1 || _dst.type() != CV_16SC1 ||
int dtype = _dst.type(); ksize != 3 || scale != 1.0 || delta != 0.0 ||
if (stype != CV_8UC1 || (dtype != CV_16SC1 && dtype != CV_8UC1) || (dx | dy) != 1 || (dx + dy) != 1 ||
ksize != 3 || delta != 0.0)//Restrict to 3x3 kernels since otherwise convolution would be slower than separable filter _src.cols < ksize || _src.rows < ksize ||
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(_src.cols, _src.rows)
)
return false; return false;
Mat src = _src.getMat(); Mat src = _src.getMat();
Mat dst = _dst.getMat(); Mat dst = _dst.getMat();
if (src.cols < ksize || src.rows < ksize)
return false;
if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1 ?
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(src.cols, src.rows) :
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
)
return false;
int iscale = 1;
vx_uint32 cscale = 1;
if(scale != 1.0)
{
iscale = static_cast<int>(scale);
if (std::abs(scale - iscale) >= DBL_EPSILON)
{
int exp = 0;
float significand = frexp(scale, &exp);
if ((significand == 0.5f) && (exp <= 0))
{
iscale = 1;
cscale = 1 << (exp = -exp + 1);
}
else
return false;
}
}
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
return false; //Process isolated borders only return false; //Process isolated borders only
vx_enum border; vx_enum border;
...@@ -255,40 +229,17 @@ namespace cv ...@@ -255,40 +229,17 @@ namespace cv
ivx::Image ivx::Image
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data), ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
ib = ivx::Image::createFromHandle(ctx, dtype == CV_16SC1 ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8, ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_S16,
ivx::Image::createAddressing(dst.cols, dst.rows, dtype == CV_16SC1 ? 2 : 1, (vx_int32)(dst.step)), dst.data); 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 //ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
//since OpenVX standart says nothing about thread-safety for now //since OpenVX standart says nothing about thread-safety for now
ivx::border_t prevBorder = ctx.immediateBorder(); ivx::border_t prevBorder = ctx.immediateBorder();
ctx.setImmediateBorder(border, (vx_uint8)(0)); ctx.setImmediateBorder(border, (vx_uint8)(0));
if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1) if(dx)
{ ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL));
if(dx)
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL));
else
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib));
}
else else
{ ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib));
#if VX_VERSION <= VX_VERSION_1_0
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension()))
{
ctx.setImmediateBorder(prevBorder);
return false;
}
#endif
Mat kx, ky;
getDerivKernels(kx, ky, dx, dy, ksize, false);
flip(kx, kx, 0);
flip(ky, ky, 0);
Mat convData;
cv::Mat(ky*kx.t()).convertTo(convData, CV_16SC1, iscale);
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
cnv.copyFrom(convData);
cnv.setScale(cscale);
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
}
ctx.setImmediateBorder(prevBorder); ctx.setImmediateBorder(prevBorder);
} }
catch (ivx::RuntimeError & e) catch (ivx::RuntimeError & e)
......
...@@ -1643,29 +1643,18 @@ namespace cv ...@@ -1643,29 +1643,18 @@ namespace cv
Size ksize, Point anchor, Size ksize, Point anchor,
bool normalize, int borderType) bool normalize, int borderType)
{ {
int stype = _src.type();
if (ddepth < 0) if (ddepth < 0)
ddepth = CV_8UC1; ddepth = CV_8UC1;
if (stype != CV_8UC1 || (ddepth != CV_8U && ddepth != CV_16S) || if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize ||
(anchor.x >= 0 && anchor.x != ksize.width / 2) || _src.cols < 3 || _src.rows < 3 ||
(anchor.y >= 0 && anchor.y != ksize.height / 2) || ksize.width != 3 || ksize.height != 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; return false;
Mat src = _src.getMat(); Mat src = _src.getMat();
if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize ?
ovx::skipSmallImages<VX_KERNEL_BOX_3x3>(src.cols, src.rows) :
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
)
return false;
_dst.create(src.size(), CV_MAKETYPE(ddepth, 1));
Mat dst = _dst.getMat();
if (src.cols < ksize.width || src.rows < ksize.height)
return false;
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
return false; //Process isolated borders only return false; //Process isolated borders only
vx_enum border; vx_enum border;
...@@ -1681,11 +1670,12 @@ namespace cv ...@@ -1681,11 +1670,12 @@ namespace cv
return false; return false;
} }
_dst.create(src.size(), CV_8UC1);
Mat dst = _dst.getMat();
try try
{ {
ivx::Context ctx = ovx::getOpenVXContext(); ivx::Context ctx = ovx::getOpenVXContext();
//if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
// return false;
Mat a; Mat a;
if (dst.data != src.data) if (dst.data != src.data)
...@@ -1696,34 +1686,14 @@ namespace cv ...@@ -1696,34 +1686,14 @@ namespace cv
ivx::Image ivx::Image
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8, ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data), ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
ib = ivx::Image::createFromHandle(ctx, ddepth == CV_16S ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8, ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
ivx::Image::createAddressing(dst.cols, dst.rows, ddepth == CV_16S ? 2 : 1, (vx_int32)(dst.step)), dst.data); 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 //ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
//since OpenVX standart says nothing about thread-safety for now //since OpenVX standart says nothing about thread-safety for now
ivx::border_t prevBorder = ctx.immediateBorder(); ivx::border_t prevBorder = ctx.immediateBorder();
ctx.setImmediateBorder(border, (vx_uint8)(0)); ctx.setImmediateBorder(border, (vx_uint8)(0));
if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize) ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
{
ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
}
else
{
#if VX_VERSION <= VX_VERSION_1_0
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension()))
{
ctx.setImmediateBorder(prevBorder);
return false;
}
#endif
Mat convData(ksize, CV_16SC1);
convData = normalize ? (1 << 15) / (ksize.width * ksize.height) : 1;
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
cnv.copyFrom(convData);
if (normalize)
cnv.setScale(1 << 15);
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
}
ctx.setImmediateBorder(prevBorder); ctx.setImmediateBorder(prevBorder);
} }
catch (ivx::RuntimeError & e) catch (ivx::RuntimeError & e)
...@@ -2205,7 +2175,6 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize, ...@@ -2205,7 +2175,6 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize,
static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
double sigma1, double sigma2, int borderType) double sigma1, double sigma2, int borderType)
{ {
int stype = _src.type();
if (sigma2 <= 0) if (sigma2 <= 0)
sigma2 = sigma1; sigma2 = sigma1;
// automatic detection of kernel size from sigma // automatic detection of kernel size from sigma
...@@ -2214,26 +2183,20 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, ...@@ -2214,26 +2183,20 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
if (ksize.height <= 0 && sigma2 > 0) if (ksize.height <= 0 && sigma2 > 0)
ksize.height = cvRound(sigma2*6 + 1) | 1; ksize.height = cvRound(sigma2*6 + 1) | 1;
if (stype != CV_8UC1 || if (_src.type() != CV_8UC1 ||
ksize.width < 3 || ksize.height < 3 || _src.cols < 3 || _src.rows < 3 ||
ksize.width > 5 || ksize.height > 5 || ksize.width != 3 || ksize.height != 3)
ksize.width % 2 != 1 || ksize.height % 2 != 1)
return false; return false;
sigma1 = std::max(sigma1, 0.); sigma1 = std::max(sigma1, 0.);
sigma2 = std::max(sigma2, 0.); sigma2 = std::max(sigma2, 0.);
Mat src = _src.getMat(); if (!(sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) || !(sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ||
Mat dst = _dst.getMat(); ovx::skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(_src.cols, _src.rows))
if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ?
ovx::skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(src.cols, src.rows) :
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
)
return false; return false;
if (src.cols < ksize.width || src.rows < ksize.height) Mat src = _src.getMat();
return false; Mat dst = _dst.getMat();
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix()) if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
return false; //Process isolated borders only return false; //Process isolated borders only
...@@ -2253,8 +2216,6 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, ...@@ -2253,8 +2216,6 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
try try
{ {
ivx::Context ctx = ovx::getOpenVXContext(); ivx::Context ctx = ovx::getOpenVXContext();
if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
return false;
Mat a; Mat a;
if (dst.data != src.data) if (dst.data != src.data)
...@@ -2272,26 +2233,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize, ...@@ -2272,26 +2233,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
//since OpenVX standart says nothing about thread-safety for now //since OpenVX standart says nothing about thread-safety for now
ivx::border_t prevBorder = ctx.immediateBorder(); ivx::border_t prevBorder = ctx.immediateBorder();
ctx.setImmediateBorder(border, (vx_uint8)(0)); ctx.setImmediateBorder(border, (vx_uint8)(0));
if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON)) ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib));
{
ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib));
}
else
{
#if VX_VERSION <= VX_VERSION_1_0
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(a.cols) <= ctx.convolutionMaxDimension() || (vx_size)(a.rows) <= ctx.convolutionMaxDimension()))
{
ctx.setImmediateBorder(prevBorder);
return false;
}
#endif
Mat convData;
cv::Mat(cv::getGaussianKernel(ksize.height, sigma2)*cv::getGaussianKernel(ksize.width, sigma1).t()).convertTo(convData, CV_16SC1, (1 << 15));
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
cnv.copyFrom(convData);
cnv.setScale(1 << 15);
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
}
ctx.setImmediateBorder(prevBorder); ctx.setImmediateBorder(prevBorder);
} }
catch (ivx::RuntimeError & e) catch (ivx::RuntimeError & e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment