2010-05-12 01:44:00 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
2015-01-12 15:59:30 +08:00
|
|
|
// Copyright (C) 2014-2015, Itseez Inc., all rights reserved.
|
2010-05-12 01:44:00 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
2018-01-22 18:26:32 +08:00
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
#include <opencv2/core/utils/logger.hpp>
|
|
|
|
|
|
|
|
#include <opencv2/core/utils/configuration.private.hpp>
|
|
|
|
|
2018-01-22 18:26:32 +08:00
|
|
|
#include <vector>
|
2020-06-27 06:31:02 +08:00
|
|
|
#include <iostream>
|
2018-01-22 18:26:32 +08:00
|
|
|
|
2017-05-24 01:04:35 +08:00
|
|
|
#include "opencv2/core/hal/intrin.hpp"
|
2014-08-01 22:11:20 +08:00
|
|
|
#include "opencl_kernels_imgproc.hpp"
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2016-12-14 22:31:41 +08:00
|
|
|
#include "opencv2/core/openvx/ovx_defs.hpp"
|
|
|
|
|
2017-11-14 17:57:02 +08:00
|
|
|
#include "filter.hpp"
|
|
|
|
|
2019-03-10 03:20:24 +08:00
|
|
|
#include "opencv2/core/softfloat.hpp"
|
|
|
|
|
|
|
|
namespace cv {
|
2018-01-22 18:26:32 +08:00
|
|
|
#include "fixedpoint.inl.hpp"
|
2019-03-10 03:20:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "smooth.simd.hpp"
|
|
|
|
#include "smooth.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
|
|
|
|
|
|
|
|
namespace cv {
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
Gaussian Blur
|
|
|
|
\****************************************************************************************/
|
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
/**
|
|
|
|
* Bit-exact in terms of softfloat computations
|
|
|
|
*
|
|
|
|
* returns sum of kernel values. Should be equal to 1.0
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
softdouble getGaussianKernelBitExact(std::vector<softdouble>& result, int n, double sigma)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2018-07-17 21:14:54 +08:00
|
|
|
CV_Assert(n > 0);
|
2019-11-18 06:39:27 +08:00
|
|
|
//TODO: incorrect SURF implementation requests kernel with n = 20 (PATCH_SZ): https://github.com/opencv/opencv/issues/15856
|
|
|
|
//CV_Assert((n & 1) == 1); // odd
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
if (sigma <= 0)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
if (n == 1)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
result = std::vector<softdouble>(1, softdouble::one());
|
|
|
|
return softdouble::one();
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
2019-11-18 06:39:27 +08:00
|
|
|
else if (n == 3)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble v3[] = {
|
|
|
|
softdouble::fromRaw(0x3fd0000000000000), // 0.25
|
|
|
|
softdouble::fromRaw(0x3fe0000000000000), // 0.5
|
|
|
|
softdouble::fromRaw(0x3fd0000000000000) // 0.25
|
|
|
|
};
|
|
|
|
result.assign(v3, v3 + 3);
|
|
|
|
return softdouble::one();
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
2019-11-18 06:39:27 +08:00
|
|
|
else if (n == 5)
|
2018-01-22 18:26:32 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble v5[] = {
|
|
|
|
softdouble::fromRaw(0x3fb0000000000000), // 0.0625
|
|
|
|
softdouble::fromRaw(0x3fd0000000000000), // 0.25
|
|
|
|
softdouble::fromRaw(0x3fd8000000000000), // 0.375
|
|
|
|
softdouble::fromRaw(0x3fd0000000000000), // 0.25
|
|
|
|
softdouble::fromRaw(0x3fb0000000000000) // 0.0625
|
|
|
|
};
|
|
|
|
result.assign(v5, v5 + 5);
|
|
|
|
return softdouble::one();
|
2018-01-22 18:26:32 +08:00
|
|
|
}
|
2019-11-18 06:39:27 +08:00
|
|
|
else if (n == 7)
|
2018-01-22 18:26:32 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble v7[] = {
|
|
|
|
softdouble::fromRaw(0x3fa0000000000000), // 0.03125
|
|
|
|
softdouble::fromRaw(0x3fbc000000000000), // 0.109375
|
|
|
|
softdouble::fromRaw(0x3fcc000000000000), // 0.21875
|
|
|
|
softdouble::fromRaw(0x3fd2000000000000), // 0.28125
|
|
|
|
softdouble::fromRaw(0x3fcc000000000000), // 0.21875
|
|
|
|
softdouble::fromRaw(0x3fbc000000000000), // 0.109375
|
|
|
|
softdouble::fromRaw(0x3fa0000000000000) // 0.03125
|
|
|
|
};
|
|
|
|
result.assign(v7, v7 + 7);
|
|
|
|
return softdouble::one();
|
2018-01-22 18:26:32 +08:00
|
|
|
}
|
2019-11-18 06:39:27 +08:00
|
|
|
else if (n == 9)
|
2018-01-22 18:26:32 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble v9[] = {
|
|
|
|
softdouble::fromRaw(0x3f90000000000000), // 4 / 256
|
|
|
|
softdouble::fromRaw(0x3faa000000000000), // 13 / 256
|
|
|
|
softdouble::fromRaw(0x3fbe000000000000), // 30 / 256
|
|
|
|
softdouble::fromRaw(0x3fc9800000000000), // 51 / 256
|
|
|
|
softdouble::fromRaw(0x3fce000000000000), // 60 / 256
|
|
|
|
softdouble::fromRaw(0x3fc9800000000000), // 51 / 256
|
|
|
|
softdouble::fromRaw(0x3fbe000000000000), // 30 / 256
|
|
|
|
softdouble::fromRaw(0x3faa000000000000), // 13 / 256
|
|
|
|
softdouble::fromRaw(0x3f90000000000000) // 4 / 256
|
|
|
|
};
|
|
|
|
result.assign(v9, v9 + 9);
|
|
|
|
return softdouble::one();
|
2018-01-22 18:26:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble sd_0_15 = softdouble::fromRaw(0x3fc3333333333333); // 0.15
|
|
|
|
softdouble sd_0_35 = softdouble::fromRaw(0x3fd6666666666666); // 0.35
|
|
|
|
softdouble sd_minus_0_125 = softdouble::fromRaw(0xbfc0000000000000); // -0.5*0.25
|
2018-01-22 18:26:32 +08:00
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble sigmaX = sigma > 0 ? softdouble(sigma) : mulAdd(softdouble(n), sd_0_15, sd_0_35);// softdouble(((n-1)*0.5 - 1)*0.3 + 0.8)
|
|
|
|
softdouble scale2X = sd_minus_0_125/(sigmaX*sigmaX);
|
|
|
|
|
|
|
|
int n2_ = (n - 1) / 2;
|
|
|
|
cv::AutoBuffer<softdouble> values(n2_ + 1);
|
|
|
|
softdouble sum = softdouble::zero();
|
|
|
|
for (int i = 0, x = 1 - n; i < n2_; i++, x+=2)
|
2018-01-22 18:26:32 +08:00
|
|
|
{
|
|
|
|
// x = i - (n - 1)*0.5
|
|
|
|
// t = std::exp(scale2X*x*x)
|
2019-11-18 06:39:27 +08:00
|
|
|
softdouble t = exp(softdouble(x*x)*scale2X);
|
|
|
|
values[i] = t;
|
|
|
|
sum += t;
|
|
|
|
}
|
|
|
|
sum *= softdouble(2);
|
|
|
|
//values[n2_] = softdouble::one(); // x=0 in exp(softdouble(x*x)*scale2X);
|
|
|
|
sum += softdouble::one();
|
|
|
|
if ((n & 1) == 0)
|
|
|
|
{
|
|
|
|
//values[n2_ + 1] = softdouble::one();
|
|
|
|
sum += softdouble::one();
|
2018-01-22 18:26:32 +08:00
|
|
|
}
|
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
// normalize: sum(k[i]) = 1
|
|
|
|
softdouble mul1 = softdouble::one()/sum;
|
|
|
|
|
|
|
|
result.resize(n);
|
|
|
|
|
|
|
|
softdouble sum2 = softdouble::zero();
|
|
|
|
for (int i = 0; i < n2_; i++ )
|
|
|
|
{
|
|
|
|
softdouble t = values[i] * mul1;
|
|
|
|
result[i] = t;
|
|
|
|
result[n - 1 - i] = t;
|
|
|
|
sum2 += t;
|
|
|
|
}
|
|
|
|
sum2 *= softdouble(2);
|
|
|
|
result[n2_] = /*values[n2_]*/ softdouble::one() * mul1;
|
|
|
|
sum2 += result[n2_];
|
|
|
|
if ((n & 1) == 0)
|
2018-01-22 18:26:32 +08:00
|
|
|
{
|
2019-11-18 06:39:27 +08:00
|
|
|
result[n2_ + 1] = result[n2_];
|
|
|
|
sum2 += result[n2_];
|
|
|
|
}
|
|
|
|
|
|
|
|
return sum2;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mat getGaussianKernel(int n, double sigma, int ktype)
|
|
|
|
{
|
|
|
|
CV_CheckDepth(ktype, ktype == CV_32F || ktype == CV_64F, "");
|
|
|
|
Mat kernel(n, 1, ktype);
|
|
|
|
|
|
|
|
std::vector<softdouble> kernel_bitexact;
|
|
|
|
getGaussianKernelBitExact(kernel_bitexact, n, sigma);
|
|
|
|
|
|
|
|
if (ktype == CV_32F)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
kernel.at<float>(i) = (float)kernel_bitexact[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CV_DbgAssert(ktype == CV_64F);
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
kernel.at<double>(i) = kernel_bitexact[i];
|
2018-01-22 18:26:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return kernel;
|
2019-11-18 06:39:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
softdouble getGaussianKernelFixedPoint_ED(CV_OUT std::vector<int64_t>& result, const std::vector<softdouble> kernel_bitexact, int fractionBits)
|
|
|
|
{
|
|
|
|
const int n = (int)kernel_bitexact.size();
|
|
|
|
CV_Assert((n & 1) == 1); // odd
|
|
|
|
|
|
|
|
CV_CheckGT(fractionBits, 0, "");
|
|
|
|
CV_CheckLE(fractionBits, 32, "");
|
|
|
|
|
|
|
|
int64_t fractionMultiplier = CV_BIG_INT(1) << fractionBits;
|
|
|
|
softdouble fractionMultiplier_sd(fractionMultiplier);
|
|
|
|
|
|
|
|
result.resize(n);
|
|
|
|
|
|
|
|
int n2_ = n / 2; // n is odd
|
|
|
|
softdouble err = softdouble::zero();
|
|
|
|
int64_t sum = 0;
|
|
|
|
for (int i = 0; i < n2_; i++)
|
|
|
|
{
|
|
|
|
//softdouble err0 = err;
|
|
|
|
softdouble adj_v = kernel_bitexact[i] * fractionMultiplier_sd + err;
|
|
|
|
int64_t v0 = cvRound(adj_v); // cvFloor() provides bad results
|
|
|
|
err = adj_v - softdouble(v0);
|
|
|
|
//printf("%3d: adj_v=%8.3f(%8.3f+%8.3f) v0=%d ed_err=%8.3f\n", i, (double)adj_v, (double)(kernel_bitexact[i] * fractionMultiplier_sd), (double)err0, (int)v0, (double)err);
|
|
|
|
|
|
|
|
result[i] = v0;
|
|
|
|
result[n - 1 - i] = v0;
|
|
|
|
sum += v0;
|
|
|
|
}
|
|
|
|
sum *= 2;
|
|
|
|
softdouble adj_v_center = kernel_bitexact[n2_] * fractionMultiplier_sd + err;
|
|
|
|
int64_t v_center = fractionMultiplier - sum;
|
|
|
|
result[n2_] = v_center;
|
|
|
|
//printf("center = %g ===> %g ===> %g\n", (double)(kernel_bitexact[n2_] * fractionMultiplier), (double)adj_v_center, (double)v_center);
|
|
|
|
return (adj_v_center - softdouble(v_center));
|
|
|
|
}
|
2018-01-22 18:26:32 +08:00
|
|
|
|
|
|
|
static void getGaussianKernel(int n, double sigma, int ktype, Mat& res) { res = getGaussianKernel(n, sigma, ktype); }
|
2020-09-01 18:28:25 +08:00
|
|
|
template <typename FT> static void getGaussianKernel(int n, double sigma, int, std::vector<FT>& res)
|
2019-11-18 06:39:27 +08:00
|
|
|
{
|
|
|
|
std::vector<softdouble> res_sd;
|
|
|
|
softdouble s0 = getGaussianKernelBitExact(res_sd, n, sigma);
|
|
|
|
CV_UNUSED(s0);
|
|
|
|
|
|
|
|
std::vector<int64_t> fixed_256;
|
2020-09-01 18:28:25 +08:00
|
|
|
softdouble approx_err = getGaussianKernelFixedPoint_ED(fixed_256, res_sd, FT::fixedShift);
|
2019-11-18 06:39:27 +08:00
|
|
|
CV_UNUSED(approx_err);
|
|
|
|
|
|
|
|
res.resize(n);
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
2020-09-01 18:28:25 +08:00
|
|
|
res[i] = FT::fromRaw((typename FT::raw_t)fixed_256[i]);
|
2019-11-18 06:39:27 +08:00
|
|
|
//printf("%03d: %d\n", i, res[i].raw());
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 18:26:32 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void createGaussianKernels( T & kx, T & ky, int type, Size &ksize,
|
2013-12-11 00:14:37 +08:00
|
|
|
double sigma1, double sigma2 )
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
int depth = CV_MAT_DEPTH(type);
|
|
|
|
if( sigma2 <= 0 )
|
|
|
|
sigma2 = sigma1;
|
|
|
|
|
|
|
|
// automatic detection of kernel size from sigma
|
|
|
|
if( ksize.width <= 0 && sigma1 > 0 )
|
|
|
|
ksize.width = cvRound(sigma1*(depth == CV_8U ? 3 : 4)*2 + 1)|1;
|
|
|
|
if( ksize.height <= 0 && sigma2 > 0 )
|
|
|
|
ksize.height = cvRound(sigma2*(depth == CV_8U ? 3 : 4)*2 + 1)|1;
|
|
|
|
|
2018-08-31 22:05:00 +08:00
|
|
|
CV_Assert( ksize.width > 0 && ksize.width % 2 == 1 &&
|
|
|
|
ksize.height > 0 && ksize.height % 2 == 1 );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
sigma1 = std::max( sigma1, 0. );
|
|
|
|
sigma2 = std::max( sigma2, 0. );
|
|
|
|
|
2018-01-22 18:26:32 +08:00
|
|
|
getGaussianKernel( ksize.width, sigma1, std::max(depth, CV_32F), kx );
|
2010-05-12 01:44:00 +08:00
|
|
|
if( ksize.height == ksize.width && std::abs(sigma1 - sigma2) < DBL_EPSILON )
|
|
|
|
ky = kx;
|
|
|
|
else
|
2018-01-22 18:26:32 +08:00
|
|
|
getGaussianKernel( ksize.height, sigma2, std::max(depth, CV_32F), ky );
|
2013-12-11 00:14:37 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 03:20:24 +08:00
|
|
|
Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
|
2013-12-11 00:14:37 +08:00
|
|
|
double sigma1, double sigma2,
|
|
|
|
int borderType )
|
|
|
|
{
|
|
|
|
Mat kx, ky;
|
|
|
|
createGaussianKernels(kx, ky, type, ksize, sigma1, sigma2);
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
return createSeparableLinearFilter( type, type, kx, ky, Point(-1,-1), 0, borderType );
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:17:45 +08:00
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
|
2016-11-30 17:06:05 +08:00
|
|
|
static bool ocl_GaussianBlur_8UC1(InputArray _src, OutputArray _dst, Size ksize, int ddepth,
|
|
|
|
InputArray _kernelX, InputArray _kernelY, int borderType)
|
2016-10-21 13:17:45 +08:00
|
|
|
{
|
|
|
|
const ocl::Device & dev = ocl::Device::getDefault();
|
|
|
|
int type = _src.type(), sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
|
|
|
|
|
|
|
if ( !(dev.isIntel() && (type == CV_8UC1) &&
|
|
|
|
(_src.offset() == 0) && (_src.step() % 4 == 0) &&
|
2016-11-30 17:06:05 +08:00
|
|
|
((ksize.width == 5 && (_src.cols() % 4 == 0)) ||
|
|
|
|
(ksize.width == 3 && (_src.cols() % 16 == 0) && (_src.rows() % 2 == 0)))) )
|
2016-10-21 13:17:45 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Mat kernelX = _kernelX.getMat().reshape(1, 1);
|
|
|
|
if (kernelX.cols % 2 != 1)
|
|
|
|
return false;
|
|
|
|
Mat kernelY = _kernelY.getMat().reshape(1, 1);
|
|
|
|
if (kernelY.cols % 2 != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ddepth < 0)
|
|
|
|
ddepth = sdepth;
|
|
|
|
|
|
|
|
Size size = _src.size();
|
|
|
|
size_t globalsize[2] = { 0, 0 };
|
|
|
|
size_t localsize[2] = { 0, 0 };
|
|
|
|
|
2016-11-30 17:06:05 +08:00
|
|
|
if (ksize.width == 3)
|
|
|
|
{
|
|
|
|
globalsize[0] = size.width / 16;
|
|
|
|
globalsize[1] = size.height / 2;
|
|
|
|
}
|
|
|
|
else if (ksize.width == 5)
|
|
|
|
{
|
|
|
|
globalsize[0] = size.width / 4;
|
|
|
|
globalsize[1] = size.height / 1;
|
|
|
|
}
|
2016-10-21 13:17:45 +08:00
|
|
|
|
|
|
|
const char * const borderMap[] = { "BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", 0, "BORDER_REFLECT_101" };
|
|
|
|
char build_opts[1024];
|
2022-06-25 11:48:22 +08:00
|
|
|
snprintf(build_opts, sizeof(build_opts), "-D %s %s%s", borderMap[borderType & ~BORDER_ISOLATED],
|
2016-10-21 13:17:45 +08:00
|
|
|
ocl::kernelToStr(kernelX, CV_32F, "KERNEL_MATRIX_X").c_str(),
|
|
|
|
ocl::kernelToStr(kernelY, CV_32F, "KERNEL_MATRIX_Y").c_str());
|
|
|
|
|
2016-11-30 17:06:05 +08:00
|
|
|
ocl::Kernel kernel;
|
|
|
|
|
|
|
|
if (ksize.width == 3)
|
|
|
|
kernel.create("gaussianBlur3x3_8UC1_cols16_rows2", cv::ocl::imgproc::gaussianBlur3x3_oclsrc, build_opts);
|
|
|
|
else if (ksize.width == 5)
|
|
|
|
kernel.create("gaussianBlur5x5_8UC1_cols4", cv::ocl::imgproc::gaussianBlur5x5_oclsrc, build_opts);
|
|
|
|
|
2016-10-21 13:17:45 +08:00
|
|
|
if (kernel.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
UMat src = _src.getUMat();
|
|
|
|
_dst.create(size, CV_MAKETYPE(ddepth, cn));
|
|
|
|
if (!(_dst.offset() == 0 && _dst.step() % 4 == 0))
|
|
|
|
return false;
|
|
|
|
UMat dst = _dst.getUMat();
|
|
|
|
|
|
|
|
int idxArg = kernel.set(0, ocl::KernelArg::PtrReadOnly(src));
|
|
|
|
idxArg = kernel.set(idxArg, (int)src.step);
|
|
|
|
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrWriteOnly(dst));
|
|
|
|
idxArg = kernel.set(idxArg, (int)dst.step);
|
|
|
|
idxArg = kernel.set(idxArg, (int)dst.rows);
|
|
|
|
idxArg = kernel.set(idxArg, (int)dst.cols);
|
|
|
|
|
|
|
|
return kernel.run(2, globalsize, (localsize[0] == 0) ? NULL : localsize, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-10-28 02:00:47 +08:00
|
|
|
#ifdef HAVE_OPENVX
|
|
|
|
|
2017-05-26 00:10:21 +08:00
|
|
|
namespace ovx {
|
|
|
|
template <> inline bool skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(int w, int h) { return w*h < 320 * 240; }
|
|
|
|
}
|
2016-10-28 02:00:47 +08:00
|
|
|
static bool openvx_gaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
|
|
|
double sigma1, double sigma2, int borderType)
|
|
|
|
{
|
|
|
|
if (sigma2 <= 0)
|
|
|
|
sigma2 = sigma1;
|
|
|
|
// automatic detection of kernel size from sigma
|
|
|
|
if (ksize.width <= 0 && sigma1 > 0)
|
|
|
|
ksize.width = cvRound(sigma1*6 + 1) | 1;
|
|
|
|
if (ksize.height <= 0 && sigma2 > 0)
|
|
|
|
ksize.height = cvRound(sigma2*6 + 1) | 1;
|
|
|
|
|
2017-04-11 18:22:38 +08:00
|
|
|
if (_src.type() != CV_8UC1 ||
|
2017-04-11 19:15:26 +08:00
|
|
|
_src.cols() < 3 || _src.rows() < 3 ||
|
2017-04-11 18:22:38 +08:00
|
|
|
ksize.width != 3 || ksize.height != 3)
|
2016-10-28 02:00:47 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
sigma1 = std::max(sigma1, 0.);
|
|
|
|
sigma2 = std::max(sigma2, 0.);
|
|
|
|
|
2017-04-11 18:22:38 +08:00
|
|
|
if (!(sigma1 == 0.0 || (sigma1 - 0.8) < DBL_EPSILON) || !(sigma2 == 0.0 || (sigma2 - 0.8) < DBL_EPSILON) ||
|
2017-04-11 19:15:26 +08:00
|
|
|
ovx::skipSmallImages<VX_KERNEL_GAUSSIAN_3x3>(_src.cols(), _src.rows()))
|
2017-03-28 23:02:42 +08:00
|
|
|
return false;
|
|
|
|
|
2016-10-28 02:00:47 +08:00
|
|
|
Mat src = _src.getMat();
|
|
|
|
Mat dst = _dst.getMat();
|
|
|
|
|
|
|
|
if ((borderType & BORDER_ISOLATED) == 0 && src.isSubmatrix())
|
|
|
|
return false; //Process isolated borders only
|
2016-12-21 21:19:06 +08:00
|
|
|
vx_enum border;
|
2016-10-28 02:00:47 +08:00
|
|
|
switch (borderType & ~BORDER_ISOLATED)
|
|
|
|
{
|
|
|
|
case BORDER_CONSTANT:
|
2016-12-21 21:19:06 +08:00
|
|
|
border = VX_BORDER_CONSTANT;
|
2016-10-28 02:00:47 +08:00
|
|
|
break;
|
|
|
|
case BORDER_REPLICATE:
|
2016-12-21 21:19:06 +08:00
|
|
|
border = VX_BORDER_REPLICATE;
|
2016-10-28 02:00:47 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-02-14 18:32:17 +08:00
|
|
|
ivx::Context ctx = ovx::getOpenVXContext();
|
2016-10-28 02:00:47 +08:00
|
|
|
|
|
|
|
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
|
2018-02-14 00:28:11 +08:00
|
|
|
//since OpenVX standard says nothing about thread-safety for now
|
2016-12-05 18:06:34 +08:00
|
|
|
ivx::border_t prevBorder = ctx.immediateBorder();
|
2016-12-21 21:19:06 +08:00
|
|
|
ctx.setImmediateBorder(border, (vx_uint8)(0));
|
2017-04-11 18:22:38 +08:00
|
|
|
ivx::IVX_CHECK_STATUS(vxuGaussian3x3(ctx, ia, ib));
|
2016-12-05 18:06:34 +08:00
|
|
|
ctx.setImmediateBorder(prevBorder);
|
2016-10-28 02:00:47 +08:00
|
|
|
}
|
2018-10-20 04:21:20 +08:00
|
|
|
catch (const ivx::RuntimeError & e)
|
2016-10-28 02:00:47 +08:00
|
|
|
{
|
2016-12-14 22:31:41 +08:00
|
|
|
VX_DbgThrow(e.what());
|
2016-10-28 02:00:47 +08:00
|
|
|
}
|
2018-10-20 04:21:20 +08:00
|
|
|
catch (const ivx::WrapperError & e)
|
2016-10-28 02:00:47 +08:00
|
|
|
{
|
2016-12-14 22:31:41 +08:00
|
|
|
VX_DbgThrow(e.what());
|
2016-10-28 02:00:47 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-04-17 02:17:22 +08:00
|
|
|
#if defined ENABLE_IPP_GAUSSIAN_BLUR // see CMake's OPENCV_IPP_GAUSSIAN_BLUR option
|
|
|
|
|
|
|
|
#define IPP_DISABLE_GAUSSIAN_BLUR_LARGE_KERNELS_1TH 1
|
|
|
|
#define IPP_DISABLE_GAUSSIAN_BLUR_16SC4_1TH 1
|
|
|
|
#define IPP_DISABLE_GAUSSIAN_BLUR_32FC4_1TH 1
|
|
|
|
|
2018-04-16 18:29:14 +08:00
|
|
|
// IW 2017u2 has bug which doesn't allow use of partial inMem with tiling
|
2020-04-17 02:17:22 +08:00
|
|
|
#if IPP_VERSION_X100 < 201900
|
2017-08-17 19:57:58 +08:00
|
|
|
#define IPP_GAUSSIANBLUR_PARALLEL 0
|
|
|
|
#else
|
2017-05-31 17:16:47 +08:00
|
|
|
#define IPP_GAUSSIANBLUR_PARALLEL 1
|
2017-08-17 19:57:58 +08:00
|
|
|
#endif
|
2017-05-31 17:16:47 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_IPP_IW
|
|
|
|
|
|
|
|
class ipp_gaussianBlurParallel: public ParallelLoopBody
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ipp_gaussianBlurParallel(::ipp::IwiImage &src, ::ipp::IwiImage &dst, int kernelSize, float sigma, ::ipp::IwiBorderType &border, bool *pOk):
|
|
|
|
m_src(src), m_dst(dst), m_kernelSize(kernelSize), m_sigma(sigma), m_border(border), m_pOk(pOk) {
|
|
|
|
*m_pOk = true;
|
|
|
|
}
|
|
|
|
~ipp_gaussianBlurParallel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-15 21:16:51 +08:00
|
|
|
virtual void operator() (const Range& range) const CV_OVERRIDE
|
2017-05-31 17:16:47 +08:00
|
|
|
{
|
2018-09-14 05:35:26 +08:00
|
|
|
CV_INSTRUMENT_REGION_IPP();
|
2017-05-31 17:16:47 +08:00
|
|
|
|
|
|
|
if(!*m_pOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-08-17 19:57:58 +08:00
|
|
|
::ipp::IwiTile tile = ::ipp::IwiRoi(0, range.start, m_dst.m_size.width, range.end - range.start);
|
|
|
|
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, m_src, m_dst, m_kernelSize, m_sigma, ::ipp::IwDefault(), m_border, tile);
|
2017-05-31 17:16:47 +08:00
|
|
|
}
|
2018-10-17 03:09:26 +08:00
|
|
|
catch(const ::ipp::IwException &)
|
2017-05-31 17:16:47 +08:00
|
|
|
{
|
|
|
|
*m_pOk = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
::ipp::IwiImage &m_src;
|
|
|
|
::ipp::IwiImage &m_dst;
|
|
|
|
|
|
|
|
int m_kernelSize;
|
|
|
|
float m_sigma;
|
|
|
|
::ipp::IwiBorderType &m_border;
|
|
|
|
|
|
|
|
volatile bool *m_pOk;
|
|
|
|
const ipp_gaussianBlurParallel& operator= (const ipp_gaussianBlurParallel&);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-04-13 20:50:23 +08:00
|
|
|
static bool ipp_GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
|
|
|
double sigma1, double sigma2, int borderType )
|
2015-05-15 16:15:00 +08:00
|
|
|
{
|
2017-04-13 20:50:23 +08:00
|
|
|
#ifdef HAVE_IPP_IW
|
2018-09-14 05:35:26 +08:00
|
|
|
CV_INSTRUMENT_REGION_IPP();
|
2016-08-18 14:53:00 +08:00
|
|
|
|
2017-08-17 19:57:58 +08:00
|
|
|
#if IPP_VERSION_X100 < 201800 && ((defined _MSC_VER && defined _M_IX86) || (defined __GNUC__ && defined __i386__))
|
2017-04-13 20:50:23 +08:00
|
|
|
CV_UNUSED(_src); CV_UNUSED(_dst); CV_UNUSED(ksize); CV_UNUSED(sigma1); CV_UNUSED(sigma2); CV_UNUSED(borderType);
|
|
|
|
return false; // bug on ia32
|
|
|
|
#else
|
|
|
|
if(sigma1 != sigma2)
|
2016-08-04 22:50:23 +08:00
|
|
|
return false;
|
|
|
|
|
2017-04-13 20:50:23 +08:00
|
|
|
if(sigma1 < FLT_EPSILON)
|
|
|
|
return false;
|
2015-05-15 16:15:00 +08:00
|
|
|
|
2017-04-13 20:50:23 +08:00
|
|
|
if(ksize.width != ksize.height)
|
|
|
|
return false;
|
2015-05-15 16:15:00 +08:00
|
|
|
|
2017-04-13 20:50:23 +08:00
|
|
|
// Acquire data and begin processing
|
|
|
|
try
|
2015-05-15 16:15:00 +08:00
|
|
|
{
|
2017-04-13 20:50:23 +08:00
|
|
|
Mat src = _src.getMat();
|
|
|
|
Mat dst = _dst.getMat();
|
2017-08-17 19:57:58 +08:00
|
|
|
::ipp::IwiImage iwSrc = ippiGetImage(src);
|
|
|
|
::ipp::IwiImage iwDst = ippiGetImage(dst);
|
|
|
|
::ipp::IwiBorderSize borderSize = ::ipp::iwiSizeToBorderSize(ippiGetSize(ksize));
|
2017-04-13 20:50:23 +08:00
|
|
|
::ipp::IwiBorderType ippBorder(ippiGetBorder(iwSrc, borderType, borderSize));
|
2017-08-17 19:57:58 +08:00
|
|
|
if(!ippBorder)
|
2017-04-13 20:50:23 +08:00
|
|
|
return false;
|
2015-05-15 16:15:00 +08:00
|
|
|
|
2017-05-31 17:16:47 +08:00
|
|
|
const int threads = ippiSuggestThreadsNum(iwDst, 2);
|
2020-04-17 02:17:22 +08:00
|
|
|
|
|
|
|
if (IPP_DISABLE_GAUSSIAN_BLUR_LARGE_KERNELS_1TH && (threads == 1 && ksize.width > 25))
|
|
|
|
return false;
|
|
|
|
if (IPP_DISABLE_GAUSSIAN_BLUR_16SC4_1TH && (threads == 1 && src.type() == CV_16SC4))
|
|
|
|
return false;
|
|
|
|
if (IPP_DISABLE_GAUSSIAN_BLUR_32FC4_1TH && (threads == 1 && src.type() == CV_32FC4))
|
|
|
|
return false;
|
|
|
|
|
2022-04-05 23:58:15 +08:00
|
|
|
if(IPP_GAUSSIANBLUR_PARALLEL && threads > 1 && iwSrc.m_size.height/(threads * 4) >= ksize.height/2) {
|
2017-06-01 12:34:50 +08:00
|
|
|
bool ok;
|
|
|
|
ipp_gaussianBlurParallel invoker(iwSrc, iwDst, ksize.width, (float) sigma1, ippBorder, &ok);
|
|
|
|
|
|
|
|
if(!ok)
|
|
|
|
return false;
|
|
|
|
const Range range(0, (int) iwDst.m_size.height);
|
2017-05-31 17:16:47 +08:00
|
|
|
parallel_for_(range, invoker, threads*4);
|
|
|
|
|
2017-06-01 12:34:50 +08:00
|
|
|
if(!ok)
|
|
|
|
return false;
|
|
|
|
} else {
|
2017-08-17 19:57:58 +08:00
|
|
|
CV_INSTRUMENT_FUN_IPP(::ipp::iwiFilterGaussian, iwSrc, iwDst, ksize.width, sigma1, ::ipp::IwDefault(), ippBorder);
|
2017-06-01 12:34:50 +08:00
|
|
|
}
|
2017-04-13 20:50:23 +08:00
|
|
|
}
|
2018-10-17 03:09:26 +08:00
|
|
|
catch (const ::ipp::IwException &)
|
2017-04-13 20:50:23 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-15 16:15:00 +08:00
|
|
|
|
2017-04-13 20:50:23 +08:00
|
|
|
return true;
|
2015-10-12 15:51:28 +08:00
|
|
|
#endif
|
2015-09-25 22:13:11 +08:00
|
|
|
#else
|
|
|
|
CV_UNUSED(_src); CV_UNUSED(_dst); CV_UNUSED(ksize); CV_UNUSED(sigma1); CV_UNUSED(sigma2); CV_UNUSED(borderType);
|
2015-05-15 16:15:00 +08:00
|
|
|
return false;
|
2017-04-13 20:50:23 +08:00
|
|
|
#endif
|
2015-05-15 16:15:00 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
template<typename T>
|
|
|
|
static bool validateGaussianBlurKernel(std::vector<T>& kernel)
|
|
|
|
{
|
|
|
|
softdouble validation_sum = softdouble::zero();
|
|
|
|
for (size_t i = 0; i < kernel.size(); i++)
|
|
|
|
{
|
|
|
|
validation_sum += softdouble((double)kernel[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid = validation_sum == softdouble::one();
|
|
|
|
return isValid;
|
|
|
|
}
|
|
|
|
|
2019-03-10 03:20:24 +08:00
|
|
|
void GaussianBlur(InputArray _src, OutputArray _dst, Size ksize,
|
|
|
|
double sigma1, double sigma2,
|
|
|
|
int borderType)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2018-09-14 05:35:26 +08:00
|
|
|
CV_INSTRUMENT_REGION();
|
2016-08-18 14:53:00 +08:00
|
|
|
|
2020-03-21 05:04:29 +08:00
|
|
|
CV_Assert(!_src.empty());
|
|
|
|
|
2013-12-11 00:14:37 +08:00
|
|
|
int type = _src.type();
|
|
|
|
Size size = _src.size();
|
|
|
|
_dst.create( size, type );
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2018-01-22 18:26:32 +08:00
|
|
|
if( (borderType & ~BORDER_ISOLATED) != BORDER_CONSTANT &&
|
|
|
|
((borderType & BORDER_ISOLATED) != 0 || !_src.getMat().isSubmatrix()) )
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2013-12-11 00:14:37 +08:00
|
|
|
if( size.height == 1 )
|
2010-05-12 01:44:00 +08:00
|
|
|
ksize.height = 1;
|
2013-12-11 00:14:37 +08:00
|
|
|
if( size.width == 1 )
|
2010-05-12 01:44:00 +08:00
|
|
|
ksize.width = 1;
|
|
|
|
}
|
2012-01-05 02:20:03 +08:00
|
|
|
|
|
|
|
if( ksize.width == 1 && ksize.height == 1 )
|
|
|
|
{
|
2013-12-11 00:14:37 +08:00
|
|
|
_src.copyTo(_dst);
|
2012-01-05 02:20:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-29 01:03:43 +08:00
|
|
|
if (sigma2 <= 0)
|
|
|
|
sigma2 = sigma1;
|
|
|
|
|
2020-06-27 06:31:02 +08:00
|
|
|
bool useOpenCL = ocl::isOpenCLActivated() && _dst.isUMat() && _src.dims() <= 2 &&
|
|
|
|
_src.rows() >= ksize.height && _src.cols() >= ksize.width &&
|
|
|
|
ksize.width > 1 && ksize.height > 1;
|
2018-09-07 19:33:52 +08:00
|
|
|
CV_UNUSED(useOpenCL);
|
2012-01-05 02:20:03 +08:00
|
|
|
|
2017-11-01 21:45:07 +08:00
|
|
|
int sdepth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
|
|
|
|
2017-11-14 17:57:02 +08:00
|
|
|
Mat kx, ky;
|
|
|
|
createGaussianKernels(kx, ky, type, ksize, sigma1, sigma2);
|
|
|
|
|
2020-06-27 06:31:02 +08:00
|
|
|
CV_OCL_RUN(useOpenCL && sdepth == CV_8U &&
|
|
|
|
((ksize.width == 3 && ksize.height == 3) ||
|
|
|
|
(ksize.width == 5 && ksize.height == 5)),
|
|
|
|
ocl_GaussianBlur_8UC1(_src, _dst, ksize, CV_MAT_DEPTH(type), kx, ky, borderType)
|
|
|
|
);
|
2017-11-14 17:57:02 +08:00
|
|
|
|
2020-06-27 06:31:02 +08:00
|
|
|
if(sdepth == CV_8U && ((borderType & BORDER_ISOLATED) || !_src.isSubmatrix()))
|
2018-09-03 23:39:42 +08:00
|
|
|
{
|
|
|
|
std::vector<ufixedpoint16> fkx, fky;
|
|
|
|
createGaussianKernels(fkx, fky, type, ksize, sigma1, sigma2);
|
2019-11-18 06:39:27 +08:00
|
|
|
|
|
|
|
static bool param_check_gaussian_blur_bitexact_kernels = utils::getConfigurationParameterBool("OPENCV_GAUSSIANBLUR_CHECK_BITEXACT_KERNELS", false);
|
|
|
|
if (param_check_gaussian_blur_bitexact_kernels && !validateGaussianBlurKernel(fkx))
|
|
|
|
{
|
|
|
|
CV_LOG_INFO(NULL, "GaussianBlur: bit-exact fx kernel can't be applied: ksize=" << ksize << " sigma=" << Size2d(sigma1, sigma2));
|
|
|
|
}
|
|
|
|
else if (param_check_gaussian_blur_bitexact_kernels && !validateGaussianBlurKernel(fky))
|
|
|
|
{
|
|
|
|
CV_LOG_INFO(NULL, "GaussianBlur: bit-exact fy kernel can't be applied: ksize=" << ksize << " sigma=" << Size2d(sigma1, sigma2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-27 06:31:02 +08:00
|
|
|
CV_OCL_RUN(useOpenCL,
|
|
|
|
ocl_sepFilter2D_BitExact(_src, _dst, sdepth,
|
|
|
|
ksize,
|
|
|
|
(const uint16_t*)&fkx[0], (const uint16_t*)&fky[0],
|
|
|
|
Point(-1, -1), 0, borderType,
|
|
|
|
8/*shift_bits*/)
|
|
|
|
);
|
|
|
|
|
|
|
|
Mat src = _src.getMat();
|
|
|
|
Mat dst = _dst.getMat();
|
|
|
|
|
2019-11-18 06:39:27 +08:00
|
|
|
if (src.data == dst.data)
|
|
|
|
src = src.clone();
|
|
|
|
CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint16_t*)&fkx[0], (int)fkx.size(), (const uint16_t*)&fky[0], (int)fky.size(), borderType),
|
|
|
|
CV_CPU_DISPATCH_MODES_ALL);
|
|
|
|
return;
|
|
|
|
}
|
2018-09-03 23:39:42 +08:00
|
|
|
}
|
2020-09-01 18:28:25 +08:00
|
|
|
if(sdepth == CV_16U && ((borderType & BORDER_ISOLATED) || !_src.isSubmatrix()))
|
|
|
|
{
|
|
|
|
CV_LOG_INFO(NULL, "GaussianBlur: running bit-exact version...");
|
|
|
|
|
|
|
|
std::vector<ufixedpoint32> fkx, fky;
|
|
|
|
createGaussianKernels(fkx, fky, type, ksize, sigma1, sigma2);
|
|
|
|
|
|
|
|
static bool param_check_gaussian_blur_bitexact_kernels = utils::getConfigurationParameterBool("OPENCV_GAUSSIANBLUR_CHECK_BITEXACT_KERNELS", false);
|
|
|
|
if (param_check_gaussian_blur_bitexact_kernels && !validateGaussianBlurKernel(fkx))
|
|
|
|
{
|
|
|
|
CV_LOG_INFO(NULL, "GaussianBlur: bit-exact fx kernel can't be applied: ksize=" << ksize << " sigma=" << Size2d(sigma1, sigma2));
|
|
|
|
}
|
|
|
|
else if (param_check_gaussian_blur_bitexact_kernels && !validateGaussianBlurKernel(fky))
|
|
|
|
{
|
|
|
|
CV_LOG_INFO(NULL, "GaussianBlur: bit-exact fy kernel can't be applied: ksize=" << ksize << " sigma=" << Size2d(sigma1, sigma2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: implement ocl_sepFilter2D_BitExact -- how to deal with bdepth?
|
|
|
|
// CV_OCL_RUN(useOpenCL,
|
|
|
|
// ocl_sepFilter2D_BitExact(_src, _dst, sdepth,
|
|
|
|
// ksize,
|
|
|
|
// (const uint32_t*)&fkx[0], (const uint32_t*)&fky[0],
|
|
|
|
// Point(-1, -1), 0, borderType,
|
|
|
|
// 16/*shift_bits*/)
|
|
|
|
// );
|
|
|
|
|
|
|
|
Mat src = _src.getMat();
|
|
|
|
Mat dst = _dst.getMat();
|
|
|
|
|
|
|
|
if (src.data == dst.data)
|
|
|
|
src = src.clone();
|
|
|
|
CV_CPU_DISPATCH(GaussianBlurFixedPoint, (src, dst, (const uint32_t*)&fkx[0], (int)fkx.size(), (const uint32_t*)&fky[0], (int)fky.size(), borderType),
|
|
|
|
CV_CPU_DISPATCH_MODES_ALL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-09-03 23:39:42 +08:00
|
|
|
|
2020-06-27 06:31:02 +08:00
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
if (useOpenCL)
|
|
|
|
{
|
|
|
|
sepFilter2D(_src, _dst, sdepth, kx, ky, Point(-1, -1), 0, borderType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Mat src = _src.getMat();
|
|
|
|
Mat dst = _dst.getMat();
|
|
|
|
|
|
|
|
Point ofs;
|
|
|
|
Size wsz(src.cols, src.rows);
|
|
|
|
if(!(borderType & BORDER_ISOLATED))
|
|
|
|
src.locateROI( wsz, ofs );
|
|
|
|
|
|
|
|
CALL_HAL(gaussianBlur, cv_hal_gaussianBlur, src.ptr(), src.step, dst.ptr(), dst.step, src.cols, src.rows, sdepth, cn,
|
|
|
|
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))
|
|
|
|
|
2020-04-17 02:17:22 +08:00
|
|
|
#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));
|
|
|
|
#endif
|
|
|
|
|
2017-11-28 22:11:16 +08:00
|
|
|
sepFilter2D(src, dst, sdepth, kx, ky, Point(-1, -1), 0, borderType);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
2019-03-10 03:20:24 +08:00
|
|
|
} // namespace
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CV_IMPL void
|
|
|
|
cvSmooth( const void* srcarr, void* dstarr, int smooth_type,
|
|
|
|
int param1, int param2, double param3, double param4 )
|
|
|
|
{
|
|
|
|
cv::Mat src = cv::cvarrToMat(srcarr), dst0 = cv::cvarrToMat(dstarr), dst = dst0;
|
|
|
|
|
|
|
|
CV_Assert( dst.size() == src.size() &&
|
|
|
|
(smooth_type == CV_BLUR_NO_SCALE || dst.type() == src.type()) );
|
|
|
|
|
|
|
|
if( param2 <= 0 )
|
|
|
|
param2 = param1;
|
|
|
|
|
|
|
|
if( smooth_type == CV_BLUR || smooth_type == CV_BLUR_NO_SCALE )
|
|
|
|
cv::boxFilter( src, dst, dst.depth(), cv::Size(param1, param2), cv::Point(-1,-1),
|
|
|
|
smooth_type == CV_BLUR, cv::BORDER_REPLICATE );
|
|
|
|
else if( smooth_type == CV_GAUSSIAN )
|
|
|
|
cv::GaussianBlur( src, dst, cv::Size(param1, param2), param3, param4, cv::BORDER_REPLICATE );
|
|
|
|
else if( smooth_type == CV_MEDIAN )
|
|
|
|
cv::medianBlur( src, dst, param1 );
|
|
|
|
else
|
|
|
|
cv::bilateralFilter( src, dst, param1, param3, param4, cv::BORDER_REPLICATE );
|
|
|
|
|
|
|
|
if( dst.data != dst0.data )
|
2024-03-04 20:51:05 +08:00
|
|
|
CV_Error( cv::Error::StsUnmatchedFormats, "The destination image does not have the proper type" );
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* End of file. */
|