Skip to content

Commit 87bb743

Browse files
committed
Disabled vxuConvolution call for Sobel, GaussianBlur and Box filter evaluation
1 parent 0f1a56d commit 87bb743

File tree

3 files changed

+31
-139
lines changed

3 files changed

+31
-139
lines changed

modules/core/include/opencv2/core/openvx/ovx_defs.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ template <> inline bool skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(int w, int h) {
3232
template <> inline bool skipSmallImages<VX_KERNEL_BOX_3x3>(int w, int h) { return w*h < 640 * 480; }
3333
template <> inline bool skipSmallImages<VX_KERNEL_HISTOGRAM>(int w, int h) { return w*h < 2048 * 1536; }
3434
template <> inline bool skipSmallImages<VX_KERNEL_SOBEL_3x3>(int w, int h) { return w*h < 320 * 240; }
35-
template <> inline bool skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(int w, int h) { return w*h < 640 * 480; }
3635

3736
}}
3837

modules/imgproc/src/deriv.cpp

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -188,43 +188,17 @@ namespace cv
188188
int dx, int dy, int ksize,
189189
double scale, double delta, int borderType)
190190
{
191-
int stype = _src.type();
192-
int dtype = _dst.type();
193-
if (stype != CV_8UC1 || (dtype != CV_16SC1 && dtype != CV_8UC1) ||
194-
ksize != 3 || delta != 0.0)//Restrict to 3x3 kernels since otherwise convolution would be slower than separable filter
191+
if (_src.type() != CV_8UC1 || _dst.type() != CV_16SC1 ||
192+
ksize != 3 || scale != 1.0 || delta != 0.0 ||
193+
(dx | dy) != 1 || (dx + dy) != 1 ||
194+
_src.cols < ksize || _src.rows < ksize ||
195+
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(_src.cols, _src.rows)
196+
)
195197
return false;
196198

197199
Mat src = _src.getMat();
198200
Mat dst = _dst.getMat();
199201

200-
if (src.cols < ksize || src.rows < ksize)
201-
return false;
202-
203-
if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1 ?
204-
ovx::skipSmallImages<VX_KERNEL_SOBEL_3x3>(src.cols, src.rows) :
205-
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
206-
)
207-
return false;
208-
209-
int iscale = 1;
210-
vx_uint32 cscale = 1;
211-
if(scale != 1.0)
212-
{
213-
iscale = static_cast<int>(scale);
214-
if (std::abs(scale - iscale) >= DBL_EPSILON)
215-
{
216-
int exp = 0;
217-
float significand = frexp(scale, &exp);
218-
if ((significand == 0.5f) && (exp <= 0))
219-
{
220-
iscale = 1;
221-
cscale = 1 << (exp = -exp + 1);
222-
}
223-
else
224-
return false;
225-
}
226-
}
227-
228202
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
229203
return false; //Process isolated borders only
230204
vx_enum border;
@@ -255,40 +229,17 @@ namespace cv
255229
ivx::Image
256230
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
257231
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
258-
ib = ivx::Image::createFromHandle(ctx, dtype == CV_16SC1 ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8,
259-
ivx::Image::createAddressing(dst.cols, dst.rows, dtype == CV_16SC1 ? 2 : 1, (vx_int32)(dst.step)), dst.data);
232+
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_S16,
233+
ivx::Image::createAddressing(dst.cols, dst.rows, 2, (vx_int32)(dst.step)), dst.data);
260234

261235
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
262236
//since OpenVX standart says nothing about thread-safety for now
263237
ivx::border_t prevBorder = ctx.immediateBorder();
264238
ctx.setImmediateBorder(border, (vx_uint8)(0));
265-
if (dtype == CV_16SC1 && ksize == 3 && ((dx | dy) == 1) && (dx + dy) == 1)
266-
{
267-
if(dx)
268-
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL));
269-
else
270-
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib));
271-
}
239+
if(dx)
240+
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, ib, NULL));
272241
else
273-
{
274-
#if VX_VERSION <= VX_VERSION_1_0
275-
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension()))
276-
{
277-
ctx.setImmediateBorder(prevBorder);
278-
return false;
279-
}
280-
#endif
281-
Mat kx, ky;
282-
getDerivKernels(kx, ky, dx, dy, ksize, false);
283-
flip(kx, kx, 0);
284-
flip(ky, ky, 0);
285-
Mat convData;
286-
cv::Mat(ky*kx.t()).convertTo(convData, CV_16SC1, iscale);
287-
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
288-
cnv.copyFrom(convData);
289-
cnv.setScale(cscale);
290-
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
291-
}
242+
ivx::IVX_CHECK_STATUS(vxuSobel3x3(ctx, ia, NULL, ib));
292243
ctx.setImmediateBorder(prevBorder);
293244
}
294245
catch (ivx::RuntimeError & e)

modules/imgproc/src/smooth.cpp

Lines changed: 20 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,29 +1643,18 @@ namespace cv
16431643
Size ksize, Point anchor,
16441644
bool normalize, int borderType)
16451645
{
1646-
int stype = _src.type();
16471646
if (ddepth < 0)
16481647
ddepth = CV_8UC1;
1649-
if (stype != CV_8UC1 || (ddepth != CV_8U && ddepth != CV_16S) ||
1650-
(anchor.x >= 0 && anchor.x != ksize.width / 2) ||
1651-
(anchor.y >= 0 && anchor.y != ksize.height / 2) ||
1652-
ksize.width != 3 || ksize.height != 3)
1648+
if (_src.type() != CV_8UC1 || ddepth != CV_8U || !normalize ||
1649+
_src.cols < 3 || _src.rows < 3 ||
1650+
ksize.width != 3 || ksize.height != 3 ||
1651+
(anchor.x >= 0 && anchor.x != 1) ||
1652+
(anchor.y >= 0 && anchor.y != 1) ||
1653+
ovx::skipSmallImages<VX_KERNEL_BOX_3x3>(_src.cols, _src.rows))
16531654
return false;
16541655

16551656
Mat src = _src.getMat();
16561657

1657-
if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize ?
1658-
ovx::skipSmallImages<VX_KERNEL_BOX_3x3>(src.cols, src.rows) :
1659-
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
1660-
)
1661-
return false;
1662-
1663-
_dst.create(src.size(), CV_MAKETYPE(ddepth, 1));
1664-
Mat dst = _dst.getMat();
1665-
1666-
if (src.cols < ksize.width || src.rows < ksize.height)
1667-
return false;
1668-
16691658
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
16701659
return false; //Process isolated borders only
16711660
vx_enum border;
@@ -1681,11 +1670,12 @@ namespace cv
16811670
return false;
16821671
}
16831672

1673+
_dst.create(src.size(), CV_8UC1);
1674+
Mat dst = _dst.getMat();
1675+
16841676
try
16851677
{
16861678
ivx::Context ctx = ovx::getOpenVXContext();
1687-
//if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
1688-
// return false;
16891679

16901680
Mat a;
16911681
if (dst.data != src.data)
@@ -1696,34 +1686,14 @@ namespace cv
16961686
ivx::Image
16971687
ia = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
16981688
ivx::Image::createAddressing(a.cols, a.rows, 1, (vx_int32)(a.step)), a.data),
1699-
ib = ivx::Image::createFromHandle(ctx, ddepth == CV_16S ? VX_DF_IMAGE_S16 : VX_DF_IMAGE_U8,
1700-
ivx::Image::createAddressing(dst.cols, dst.rows, ddepth == CV_16S ? 2 : 1, (vx_int32)(dst.step)), dst.data);
1689+
ib = ivx::Image::createFromHandle(ctx, VX_DF_IMAGE_U8,
1690+
ivx::Image::createAddressing(dst.cols, dst.rows, 1, (vx_int32)(dst.step)), dst.data);
17011691

17021692
//ATTENTION: VX_CONTEXT_IMMEDIATE_BORDER attribute change could lead to strange issues in multi-threaded environments
17031693
//since OpenVX standart says nothing about thread-safety for now
17041694
ivx::border_t prevBorder = ctx.immediateBorder();
17051695
ctx.setImmediateBorder(border, (vx_uint8)(0));
1706-
if (ddepth == CV_8U && ksize.width == 3 && ksize.height == 3 && normalize)
1707-
{
1708-
ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
1709-
}
1710-
else
1711-
{
1712-
#if VX_VERSION <= VX_VERSION_1_0
1713-
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(src.cols) <= ctx.convolutionMaxDimension() || (vx_size)(src.rows) <= ctx.convolutionMaxDimension()))
1714-
{
1715-
ctx.setImmediateBorder(prevBorder);
1716-
return false;
1717-
}
1718-
#endif
1719-
Mat convData(ksize, CV_16SC1);
1720-
convData = normalize ? (1 << 15) / (ksize.width * ksize.height) : 1;
1721-
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
1722-
cnv.copyFrom(convData);
1723-
if (normalize)
1724-
cnv.setScale(1 << 15);
1725-
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
1726-
}
1696+
ivx::IVX_CHECK_STATUS(vxuBox3x3(ctx, ia, ib));
17271697
ctx.setImmediateBorder(prevBorder);
17281698
}
17291699
catch (ivx::RuntimeError & e)
@@ -2205,7 +2175,6 @@ static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize,
22052175
static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22062176
double sigma1, double sigma2, int borderType)
22072177
{
2208-
int stype = _src.type();
22092178
if (sigma2 <= 0)
22102179
sigma2 = sigma1;
22112180
// automatic detection of kernel size from sigma
@@ -2214,26 +2183,20 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22142183
if (ksize.height <= 0 && sigma2 > 0)
22152184
ksize.height = cvRound(sigma2*6 + 1) | 1;
22162185

2217-
if (stype != CV_8UC1 ||
2218-
ksize.width < 3 || ksize.height < 3 ||
2219-
ksize.width > 5 || ksize.height > 5 ||
2220-
ksize.width % 2 != 1 || ksize.height % 2 != 1)
2186+
if (_src.type() != CV_8UC1 ||
2187+
_src.cols < 3 || _src.rows < 3 ||
2188+
ksize.width != 3 || ksize.height != 3)
22212189
return false;
22222190

22232191
sigma1 = std::max(sigma1, 0.);
22242192
sigma2 = std::max(sigma2, 0.);
22252193

2226-
Mat src = _src.getMat();
2227-
Mat dst = _dst.getMat();
2228-
2229-
if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ?
2230-
ovx::skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(src.cols, src.rows) :
2231-
ovx::skipSmallImages<VX_KERNEL_CUSTOM_CONVOLUTION>(src.cols, src.rows)
2232-
)
2194+
if (!(sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) || !(sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ||
2195+
ovx::skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(_src.cols, _src.rows))
22332196
return false;
22342197

2235-
if (src.cols < ksize.width || src.rows < ksize.height)
2236-
return false;
2198+
Mat src = _src.getMat();
2199+
Mat dst = _dst.getMat();
22372200

22382201
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
22392202
return false; //Process isolated borders only
@@ -2253,8 +2216,6 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22532216
try
22542217
{
22552218
ivx::Context ctx = ovx::getOpenVXContext();
2256-
if ((vx_size)(ksize.width) > ctx.convolutionMaxDimension() || (vx_size)(ksize.height) > ctx.convolutionMaxDimension())
2257-
return false;
22582219

22592220
Mat a;
22602221
if (dst.data != src.data)
@@ -2272,26 +2233,7 @@ static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
22722233
//since OpenVX standart says nothing about thread-safety for now
22732234
ivx::border_t prevBorder = ctx.immediateBorder();
22742235
ctx.setImmediateBorder(border, (vx_uint8)(0));
2275-
if (ksize.width == 3 && ksize.height == 3 && (sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) && (sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON))
2276-
{
2277-
ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib));
2278-
}
2279-
else
2280-
{
2281-
#if VX_VERSION <= VX_VERSION_1_0
2282-
if (ctx.vendorID() == VX_ID_KHRONOS && ((vx_size)(a.cols) <= ctx.convolutionMaxDimension() || (vx_size)(a.rows) <= ctx.convolutionMaxDimension()))
2283-
{
2284-
ctx.setImmediateBorder(prevBorder);
2285-
return false;
2286-
}
2287-
#endif
2288-
Mat convData;
2289-
cv::Mat(cv::getGaussianKernel(ksize.height, sigma2)*cv::getGaussianKernel(ksize.width, sigma1).t()).convertTo(convData, CV_16SC1, (1 << 15));
2290-
ivx::Convolution cnv = ivx::Convolution::create(ctx, convData.cols, convData.rows);
2291-
cnv.copyFrom(convData);
2292-
cnv.setScale(1 << 15);
2293-
ivx::IVX_CHECK_STATUS(vxuConvolve(ctx, ia, cnv, ib));
2294-
}
2236+
ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib));
22952237
ctx.setImmediateBorder(prevBorder);
22962238
}
22972239
catch (ivx::RuntimeError & e)

0 commit comments

Comments
 (0)