refactored Laplacian filter
This commit is contained in:
parent
1eedc6c42a
commit
ee7eb1b807
@ -113,17 +113,23 @@ inline void filter2D(InputArray src, OutputArray dst, int ddepth, InputArray ker
|
|||||||
f->apply(src, dst, stream);
|
f->apply(src, dst, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Laplacian Filter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! applies Laplacian operator to the image
|
//! applies Laplacian operator to the image
|
||||||
//! supports only ksize = 1 and ksize = 3
|
//! supports only ksize = 1 and ksize = 3
|
||||||
CV_EXPORTS void Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize = 1, double scale = 1, int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null());
|
CV_EXPORTS Ptr<Filter> createLaplacianFilter(int srcType, int dstType, int ksize = 1, double scale = 1,
|
||||||
|
int borderMode = BORDER_DEFAULT, Scalar borderVal = Scalar::all(0));
|
||||||
|
|
||||||
|
__OPENCV_GPUFILTERS_DEPR_BEFORE__ void Laplacian(InputArray src, OutputArray dst, int ddepth,
|
||||||
|
int ksize = 1, double scale = 1, int borderType = BORDER_DEFAULT,
|
||||||
|
Stream& stream = Stream::Null()) __OPENCV_GPUFILTERS_DEPR_AFTER__;
|
||||||
|
|
||||||
|
inline void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize, double scale, int borderType, Stream& stream)
|
||||||
|
{
|
||||||
|
Ptr<gpu::Filter> f = gpu::createLaplacianFilter(src.type(), ddepth, ksize, scale, borderType);
|
||||||
|
f->apply(src, dst, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,6 +124,41 @@ PERF_TEST_P(Sz_Type_KernelSz, Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// Laplacian
|
||||||
|
|
||||||
|
PERF_TEST_P(Sz_Type_KernelSz, Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3)))
|
||||||
|
{
|
||||||
|
declare.time(20.0);
|
||||||
|
|
||||||
|
const cv::Size size = GET_PARAM(0);
|
||||||
|
const int type = GET_PARAM(1);
|
||||||
|
const int ksize = GET_PARAM(2);
|
||||||
|
|
||||||
|
cv::Mat src(size, type);
|
||||||
|
declare.in(src, WARMUP_RNG);
|
||||||
|
|
||||||
|
if (PERF_RUN_GPU())
|
||||||
|
{
|
||||||
|
const cv::gpu::GpuMat d_src(src);
|
||||||
|
cv::gpu::GpuMat dst;
|
||||||
|
|
||||||
|
cv::Ptr<cv::gpu::Filter> laplacian = cv::gpu::createLaplacianFilter(d_src.type(), -1, ksize);
|
||||||
|
|
||||||
|
TEST_CYCLE() laplacian->apply(d_src, dst);
|
||||||
|
|
||||||
|
GPU_SANITY_CHECK(dst);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cv::Mat dst;
|
||||||
|
|
||||||
|
TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize);
|
||||||
|
|
||||||
|
CPU_SANITY_CHECK(dst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -232,39 +267,6 @@ PERF_TEST_P(Sz_Type_KernelSz, GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZES, Value
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Laplacian
|
|
||||||
|
|
||||||
PERF_TEST_P(Sz_Type_KernelSz, Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3)))
|
|
||||||
{
|
|
||||||
declare.time(20.0);
|
|
||||||
|
|
||||||
const cv::Size size = GET_PARAM(0);
|
|
||||||
const int type = GET_PARAM(1);
|
|
||||||
const int ksize = GET_PARAM(2);
|
|
||||||
|
|
||||||
cv::Mat src(size, type);
|
|
||||||
declare.in(src, WARMUP_RNG);
|
|
||||||
|
|
||||||
if (PERF_RUN_GPU())
|
|
||||||
{
|
|
||||||
const cv::gpu::GpuMat d_src(src);
|
|
||||||
cv::gpu::GpuMat dst;
|
|
||||||
|
|
||||||
TEST_CYCLE() cv::gpu::Laplacian(d_src, dst, -1, ksize);
|
|
||||||
|
|
||||||
GPU_SANITY_CHECK(dst);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cv::Mat dst;
|
|
||||||
|
|
||||||
TEST_CYCLE() cv::Laplacian(src, dst, -1, ksize);
|
|
||||||
|
|
||||||
CPU_SANITY_CHECK(dst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Erode
|
// Erode
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ Ptr<Filter> cv::gpu::createBoxFilter(int, int, Size, Point, int, Scalar) { throw
|
|||||||
|
|
||||||
Ptr<Filter> cv::gpu::createLinearFilter(int, int, InputArray, Point, int, Scalar) { throw_no_cuda(); return Ptr<Filter>(); }
|
Ptr<Filter> cv::gpu::createLinearFilter(int, int, InputArray, Point, int, Scalar) { throw_no_cuda(); return Ptr<Filter>(); }
|
||||||
|
|
||||||
|
Ptr<Filter> cv::gpu::createLaplacianFilter(int, int, int, double, int, Scalar) { throw_no_cuda(); return Ptr<Filter>(); }
|
||||||
|
|
||||||
Ptr<FilterEngine_GPU> cv::gpu::createFilter2D_GPU(const Ptr<BaseFilter_GPU>&, int, int) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
Ptr<FilterEngine_GPU> cv::gpu::createFilter2D_GPU(const Ptr<BaseFilter_GPU>&, int, int) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
||||||
Ptr<FilterEngine_GPU> cv::gpu::createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>&, const Ptr<BaseColumnFilter_GPU>&, int, int, int) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
Ptr<FilterEngine_GPU> cv::gpu::createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>&, const Ptr<BaseColumnFilter_GPU>&, int, int, int) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
||||||
Ptr<FilterEngine_GPU> cv::gpu::createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>&, const Ptr<BaseColumnFilter_GPU>&, int, int, int, GpuMat&) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
Ptr<FilterEngine_GPU> cv::gpu::createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>&, const Ptr<BaseColumnFilter_GPU>&, int, int, int, GpuMat&) { throw_no_cuda(); return Ptr<FilterEngine_GPU>(0); }
|
||||||
@ -84,7 +86,6 @@ void cv::gpu::Scharr(const GpuMat&, GpuMat&, int, int, int, double, int, int) {
|
|||||||
void cv::gpu::Scharr(const GpuMat&, GpuMat&, int, int, int, GpuMat&, double, int, int, Stream&) { throw_no_cuda(); }
|
void cv::gpu::Scharr(const GpuMat&, GpuMat&, int, int, int, GpuMat&, double, int, int, Stream&) { throw_no_cuda(); }
|
||||||
void cv::gpu::GaussianBlur(const GpuMat&, GpuMat&, Size, double, double, int, int) { throw_no_cuda(); }
|
void cv::gpu::GaussianBlur(const GpuMat&, GpuMat&, Size, double, double, int, int) { throw_no_cuda(); }
|
||||||
void cv::gpu::GaussianBlur(const GpuMat&, GpuMat&, Size, GpuMat&, double, double, int, int, Stream&) { throw_no_cuda(); }
|
void cv::gpu::GaussianBlur(const GpuMat&, GpuMat&, Size, GpuMat&, double, double, int, int, Stream&) { throw_no_cuda(); }
|
||||||
void cv::gpu::Laplacian(const GpuMat&, GpuMat&, int, int, double, int, Stream&) { throw_no_cuda(); }
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -293,30 +294,24 @@ Ptr<Filter> cv::gpu::createLinearFilter(int srcType, int dstType, InputArray ker
|
|||||||
return new LinearFilter(srcType, dstType, kernel, anchor, borderMode, borderVal);
|
return new LinearFilter(srcType, dstType, kernel, anchor, borderMode, borderVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Laplacian Filter
|
||||||
|
|
||||||
|
Ptr<Filter> cv::gpu::createLaplacianFilter(int srcType, int dstType, int ksize, double scale, int borderMode, Scalar borderVal)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cv::gpu::Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize, double scale, int borderType, Stream& stream)
|
|
||||||
{
|
{
|
||||||
CV_Assert(ksize == 1 || ksize == 3);
|
CV_Assert( ksize == 1 || ksize == 3 );
|
||||||
|
|
||||||
static const int K[2][9] =
|
static const float K[2][9] =
|
||||||
{
|
{
|
||||||
{0, 1, 0, 1, -4, 1, 0, 1, 0},
|
{0.0f, 1.0f, 0.0f, 1.0f, -4.0f, 1.0f, 0.0f, 1.0f, 0.0f},
|
||||||
{2, 0, 2, 0, -8, 0, 2, 0, 2}
|
{2.0f, 0.0f, 2.0f, 0.0f, -8.0f, 0.0f, 2.0f, 0.0f, 2.0f}
|
||||||
};
|
};
|
||||||
Mat kernel(3, 3, CV_32S, (void*)K[ksize == 3]);
|
|
||||||
|
Mat kernel(3, 3, CV_32FC1, (void*)K[ksize == 3]);
|
||||||
if (scale != 1)
|
if (scale != 1)
|
||||||
kernel *= scale;
|
kernel *= scale;
|
||||||
|
|
||||||
Ptr<gpu::Filter> f = gpu::createLinearFilter(src.type(), ddepth, kernel, Point(-1,-1), borderType);
|
return gpu::createLinearFilter(srcType, dstType, kernel, Point(-1,-1), borderMode, borderVal);
|
||||||
f->apply(src, dst, stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -347,6 +342,7 @@ void cv::gpu::Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize, d
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -170,18 +170,6 @@ INSTANTIATE_TEST_CASE_P(GPU_Filters, Filter2D, testing::Combine(
|
|||||||
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT)),
|
testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT)),
|
||||||
WHOLE_SUBMAT));
|
WHOLE_SUBMAT));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Laplacian
|
// Laplacian
|
||||||
|
|
||||||
@ -209,8 +197,10 @@ GPU_TEST_P(Laplacian, Accuracy)
|
|||||||
{
|
{
|
||||||
cv::Mat src = randomMat(size, type);
|
cv::Mat src = randomMat(size, type);
|
||||||
|
|
||||||
|
cv::Ptr<cv::gpu::Filter> laplacian = cv::gpu::createLaplacianFilter(src.type(), -1, ksize.width);
|
||||||
|
|
||||||
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
cv::gpu::GpuMat dst = createMat(size, type, useRoi);
|
||||||
cv::gpu::Laplacian(loadMat(src, useRoi), dst, -1, ksize.width);
|
laplacian->apply(loadMat(src, useRoi), dst);
|
||||||
|
|
||||||
cv::Mat dst_gold;
|
cv::Mat dst_gold;
|
||||||
cv::Laplacian(src, dst_gold, -1, ksize.width);
|
cv::Laplacian(src, dst_gold, -1, ksize.width);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user