OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) )
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
-OCV_OPTION(ENABLE_MULTI_PROCESSOR_COMPILATION "Enabling multi-processory compilation" OFF IF MSVC)
# uncategorized options
if(NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") #class 'std::XXX' needs to have dll-interface to be used by clients of YYY
endif()
-endif()
-
-
-if (MSVC AND ENABLE_MULTI_PROCESSOR_COMPILATION)
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
-endif()
+endif()
\ No newline at end of file
:param result: Destination image.
:param stream: Stream for the asynchronous version.
+
+
+gpu::bilateralFilter
+-------------------
+Performs bilateral filtering of passed image
+
+.. ocv:function:: void gpu::bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial, int borderMode, Stream& stream = Stream::Null());
+
+ :param src: Source image. Supports only (channles != 2 && depth() != CV_8S && depth() != CV_32S && depth() != CV_64F).
+
+ :param dst: Destination imagwe.
+
+ :param kernel_size: Kernel window size.
+
+ :param sigma_color: Filter sigma in the color space.
+
+ :param sigma_spatial: Filter sigma in the coordinate space.
+
+ :param borderMode: Border type. See :ocv:func:`borderInterpolate` for details. ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now.
+
+ :param stream: Stream for the asynchronous version.
+.. seealso::
+
+ :ocv:func:`bilateralFilter`,
+
+
+gpu::nonLocalMeans
+-------------------
+Performs pure non local means denoising without any simplification, and thus it is not fast.
+
+.. ocv:function:: void nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, int search_widow_size = 11, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null());
+
+ :param src: Source image. Supports only CV_8UC1, CV_8UC3.
+
+ :param dst: Destination imagwe.
+
+ :param h: Filter sigma regulating filter strength for color.
+
+ :param search_widow_size: Size of search window.
+
+ :param block_size: Size of block used for computing weights.
+
+ :param borderMode: Border type. See :ocv:func:`borderInterpolate` for details. ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now.
+
+ :param stream: Stream for the asynchronous version.
+.. seealso::
+ :ocv:func:`fastNlMeansDenoising`
+
gpu::alphaComp
-------------------
Composites two images using alpha opacity values contained in each image.
CV_EXPORTS void blendLinear(const GpuMat& img1, const GpuMat& img2, const GpuMat& weights1, const GpuMat& weights2,\r
GpuMat& result, Stream& stream = Stream::Null());\r
\r
+//! Performa bilateral filtering of passsed image\r
+CV_EXPORTS void bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial, \r
+ int borderMode = BORDER_DEFAULT, Stream& stream = Stream::Null());\r
+\r
+//! Brute force non-local means algorith (slow but universal)\r
+CV_EXPORTS void nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, \r
+ int search_widow_size = 11, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null());\r
+\r
\r
struct CV_EXPORTS CannyBuf;\r
\r
//////////////////////////////////////////////////////////////////////\r
// BitwiseAndScalar\r
\r
-PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseAndScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseAndScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), GPU_CHANNELS_1_3_4))\r
{\r
const cv::Size size = GET_PARAM(0);\r
const int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// BitwiseOrScalar\r
\r
-PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseOrScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseOrScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), GPU_CHANNELS_1_3_4))\r
{\r
const cv::Size size = GET_PARAM(0);\r
const int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// BitwiseXorScalar\r
\r
-PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseXorScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseXorScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), GPU_CHANNELS_1_3_4))\r
{\r
const cv::Size size = GET_PARAM(0);\r
const int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// RShift\r
\r
-PERF_TEST_P(Sz_Depth_Cn, Core_RShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, Core_RShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), GPU_CHANNELS_1_3_4))\r
{\r
const cv::Size size = GET_PARAM(0);\r
const int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// LShift\r
\r
-PERF_TEST_P(Sz_Depth_Cn, Core_LShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, Core_LShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), GPU_CHANNELS_1_3_4))\r
{\r
const cv::Size size = GET_PARAM(0);\r
const int depth = GET_PARAM(1);\r
PERF_TEST_P(Sz_Depth_Cn_Code, Core_Flip, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
ALL_FLIP_CODES))\r
{\r
cv::Size size = GET_PARAM(0);\r
PERF_TEST_P(Sz_Depth_Cn, Core_Sum, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4)))\r
+ GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
PERF_TEST_P(Sz_Depth_Cn, Core_SumAbs, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4)))\r
+ GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
PERF_TEST_P(Sz_Depth_Cn, Core_SumSqr, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values<MatDepth>(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4)))\r
+ GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
--- /dev/null
+#include "perf_precomp.hpp"
+
+using namespace std;
+using namespace testing;
+
+
+//////////////////////////////////////////////////////////////////////
+// BilateralFilter
+
+DEF_PARAM_TEST(Sz_Depth_Cn_KernelSz, cv::Size, MatDepth , int, int);
+
+PERF_TEST_P(Sz_Depth_Cn_KernelSz, Denoising_BilateralFilter,
+ Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), GPU_CHANNELS_1_3_4, Values(3, 5, 9)))
+{
+ declare.time(30.0);
+
+ cv::Size size = GET_PARAM(0);
+ int depth = GET_PARAM(1);
+ int channels = GET_PARAM(2);
+ int kernel_size = GET_PARAM(3);
+
+ float sigma_color = 7;
+ float sigma_spatial = 5;
+ int borderMode = cv::BORDER_REFLECT101;
+
+ int type = CV_MAKE_TYPE(depth, channels);
+
+ cv::Mat src(size, type);
+ fillRandom(src);
+
+ if (runOnGpu)
+ {
+ cv::gpu::GpuMat d_src(src);
+ cv::gpu::GpuMat d_dst;
+
+ cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode);
+
+ TEST_CYCLE()
+ {
+ cv::gpu::bilateralFilter(d_src, d_dst, kernel_size, sigma_color, sigma_spatial, borderMode);
+ }
+ }
+ else
+ {
+ cv::Mat dst;
+
+ cv::bilateralFilter(src, dst, kernel_size, sigma_color, sigma_spatial, borderMode);
+
+ TEST_CYCLE()
+ {
+ cv::bilateralFilter(src, dst, kernel_size, sigma_color, sigma_spatial, borderMode);
+ }
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////
+// nonLocalMeans
+
+DEF_PARAM_TEST(Sz_Depth_Cn_WinSz_BlockSz, cv::Size, MatDepth , int, int, int);
+
+PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, Denoising_NonLocalMeans,
+ Combine(GPU_TYPICAL_MAT_SIZES, Values<MatDepth>(CV_8U), Values(1), Values(21), Values(5, 7)))
+{
+ declare.time(30.0);
+
+ cv::Size size = GET_PARAM(0);
+ int depth = GET_PARAM(1);
+ int channels = GET_PARAM(2);
+
+ int search_widow_size = GET_PARAM(3);
+ int block_size = GET_PARAM(4);
+
+ float h = 10;
+ int borderMode = cv::BORDER_REFLECT101;
+
+ int type = CV_MAKE_TYPE(depth, channels);
+
+ cv::Mat src(size, type);
+ fillRandom(src);
+
+ if (runOnGpu)
+ {
+ cv::gpu::GpuMat d_src(src);
+ cv::gpu::GpuMat d_dst;
+
+ cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode);
+
+ TEST_CYCLE()
+ {
+ cv::gpu::nonLocalMeans(d_src, d_dst, h, search_widow_size, block_size, borderMode);
+ }
+ }
+ else
+ {
+ FAIL();
+ }
+}
\ No newline at end of file
PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, ImgProc_Remap, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),\r
ALL_BORDER_MODES,\r
ALL_REMAP_MODES))\r
PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
ALL_INTERPOLATIONS,\r
Values(0.5, 0.3, 2.0)))\r
{\r
PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(0.2, 0.1, 0.05)))\r
{\r
declare.time(1.0);\r
PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),\r
ALL_BORDER_MODES))\r
{\r
PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),\r
ALL_BORDER_MODES))\r
{\r
PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
ALL_BORDER_MODES))\r
{\r
cv::Size size = GET_PARAM(0);\r
//////////////////////////////////////////////////////////////////////\r
// BlendLinear\r
\r
-PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_32F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_32F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate8U, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
ALL_TEMPLATE_METHODS))\r
{\r
cv::Size size = GET_PARAM(0);\r
PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate32F, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR))))\r
{\r
cv::Size size = GET_PARAM(0);\r
PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4),\r
+ GPU_CHANNELS_1_3_4,\r
Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))))\r
{\r
cv::Size size = GET_PARAM(0);\r
PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrDown, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4)))\r
+ GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrUp, Combine(\r
GPU_TYPICAL_MAT_SIZES,\r
Values(CV_8U, CV_16U, CV_32F),\r
- Values(1, 3, 4)))\r
+ GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// ImagePyramidBuild\r
\r
-PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidBuild, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidBuild, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// ImagePyramidGetLayer\r
\r
-PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidGetLayer, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidGetLayer, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// SetTo\r
\r
-PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// SetToMasked\r
\r
-PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
//////////////////////////////////////////////////////////////////////\r
// CopyToMasked\r
\r
-PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))\r
+PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), GPU_CHANNELS_1_3_4))\r
{\r
cv::Size size = GET_PARAM(0);\r
int depth = GET_PARAM(1);\r
\r
DEF_PARAM_TEST(Video_Cn_LearningRate, string, int, double);\r
\r
-PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(0.0, 0.01)))\r
+PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4, Values(0.0, 0.01)))\r
{\r
string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));\r
int cn = GET_PARAM(1);\r
\r
DEF_PARAM_TEST(Video_Cn, string, int);\r
\r
-PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))\r
+PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4))\r
{\r
string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));\r
int cn = GET_PARAM(1);\r
//////////////////////////////////////////////////////\r
// MOG2GetBackgroundImage\r
\r
-PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))\r
+PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4))\r
{\r
string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));\r
int cn = GET_PARAM(1);\r
//////////////////////////////////////////////////////\r
// VIBE\r
\r
-PERF_TEST_P(Video_Cn, Video_VIBE, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))\r
+PERF_TEST_P(Video_Cn, Video_VIBE, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4))\r
{\r
string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));\r
int cn = GET_PARAM(1);\r
\r
DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, int, int);\r
\r
-PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(20, 40, 60)))\r
+PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), GPU_CHANNELS_1_3_4, Values(20, 40, 60)))\r
{\r
std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));\r
int cn = GET_PARAM(1);\r
DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, int);\r
\r
#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::sz720p, perf::szSXGA, perf::sz1080p)\r
+#define GPU_CHANNELS_1_3_4 testing::Values(1, 3, 4)\r
\r
#endif // __OPENCV_PERF_GPU_UTILITY_HPP__\r
//\r
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.\r
+// Copyright (C) 1993-2011, NVIDIA Corporation, all rights reserved.\r
// Third party copyrights are property of their respective owners.\r
//\r
// Redistribution and use in source and binary forms, with or without modification,\r
// derived from this software without specific prior written permission.\r
//\r
// This software is provided by the copyright holders and contributors "as is" and\r
-// any express or implied warranties, including, but not limited to, the implied\r
+// any express or bpied warranties, including, but not limited to, the bpied\r
// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
// In no event shall the Intel Corporation or contributors be liable for any direct,\r
// indirect, incidental, special, exemplary, or consequential damages\r
//M*/\r
\r
#include "internal_shared.hpp"\r
-#include "opencv2/gpu/device/limits.hpp"\r
\r
-namespace cv { namespace gpu { namespace device\r
-{\r
- namespace bilateral_filter\r
- {\r
- __constant__ float* ctable_color;\r
- __constant__ float* ctable_space;\r
- __constant__ size_t ctable_space_step;\r
+#include "opencv2/gpu/device/vec_traits.hpp"\r
+#include "opencv2/gpu/device/vec_math.hpp"\r
+#include "opencv2/gpu/device/border_interpolate.hpp"\r
\r
- __constant__ int cndisp;\r
- __constant__ int cradius;\r
+using namespace cv::gpu;\r
\r
- __constant__ short cedge_disc;\r
- __constant__ short cmax_disc;\r
+typedef unsigned char uchar;\r
+typedef unsigned short ushort;\r
\r
- void load_constants(float* table_color, PtrStepSzf table_space, int ndisp, int radius, short edge_disc, short max_disc)\r
- {\r
- cudaSafeCall( cudaMemcpyToSymbol(ctable_color, &table_color, sizeof(table_color)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(ctable_space, &table_space.data, sizeof(table_space.data)) );\r
- size_t table_space_step = table_space.step / sizeof(float);\r
- cudaSafeCall( cudaMemcpyToSymbol(ctable_space_step, &table_space_step, sizeof(size_t)) );\r
-\r
- cudaSafeCall( cudaMemcpyToSymbol(cndisp, &ndisp, sizeof(int)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cradius, &radius, sizeof(int)) );\r
+//////////////////////////////////////////////////////////////////////////////////\r
+/// Bilateral filtering\r
\r
- cudaSafeCall( cudaMemcpyToSymbol(cedge_disc, &edge_disc, sizeof(short)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmax_disc, &max_disc, sizeof(short)) );\r
- }\r
-\r
- template <int channels>\r
- struct DistRgbMax\r
- {\r
- static __device__ __forceinline__ uchar calc(const uchar* a, const uchar* b)\r
- {\r
- uchar x = ::abs(a[0] - b[0]);\r
- uchar y = ::abs(a[1] - b[1]);\r
- uchar z = ::abs(a[2] - b[2]);\r
- return (::max(::max(x, y), z));\r
- }\r
- };\r
+namespace cv { namespace gpu { namespace device\r
+{\r
+ namespace imgproc\r
+ {\r
+ __device__ __forceinline__ float norm_l1(const float& a) { return ::fabs(a); }\r
+ __device__ __forceinline__ float norm_l1(const float2& a) { return ::fabs(a.x) + ::fabs(a.y); }\r
+ __device__ __forceinline__ float norm_l1(const float3& a) { return ::fabs(a.x) + ::fabs(a.y) + ::fabs(a.z); }\r
+ __device__ __forceinline__ float norm_l1(const float4& a) { return ::fabs(a.x) + ::fabs(a.y) + ::fabs(a.z) + ::fabs(a.w); }\r
\r
- template <>\r
- struct DistRgbMax<1>\r
- {\r
- static __device__ __forceinline__ uchar calc(const uchar* a, const uchar* b)\r
- {\r
- return ::abs(a[0] - b[0]);\r
- }\r
- };\r
+ __device__ __forceinline__ float sqr(const float& a) { return a * a; }\r
\r
- template <int channels, typename T>\r
- __global__ void bilateral_filter(int t, T* disp, size_t disp_step, const uchar* img, size_t img_step, int h, int w)\r
+ template<typename T, typename B> \r
+ __global__ void bilateral_kernel(const PtrStepSz<T> src, PtrStep<T> dst, const B b, const int ksz, const float sigma_spatial2_inv_half, const float sigma_color2_inv_half)\r
{\r
- const int y = blockIdx.y * blockDim.y + threadIdx.y;\r
- const int x = ((blockIdx.x * blockDim.x + threadIdx.x) << 1) + ((y + t) & 1);\r
+ typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type value_type;\r
+ \r
+ int x = threadIdx.x + blockIdx.x * blockDim.x;\r
+ int y = threadIdx.y + blockIdx.y * blockDim.y;\r
\r
- T dp[5];\r
+ if (x >= src.cols || y >= src.rows)\r
+ return;\r
\r
- if (y > 0 && y < h - 1 && x > 0 && x < w - 1)\r
- {\r
- dp[0] = *(disp + (y ) * disp_step + x + 0);\r
- dp[1] = *(disp + (y-1) * disp_step + x + 0);\r
- dp[2] = *(disp + (y ) * disp_step + x - 1);\r
- dp[3] = *(disp + (y+1) * disp_step + x + 0);\r
- dp[4] = *(disp + (y ) * disp_step + x + 1);\r
+ value_type center = saturate_cast<value_type>(src(y, x));\r
\r
- if(::abs(dp[1] - dp[0]) >= cedge_disc || ::abs(dp[2] - dp[0]) >= cedge_disc || ::abs(dp[3] - dp[0]) >= cedge_disc || ::abs(dp[4] - dp[0]) >= cedge_disc)\r
- {\r
- const int ymin = ::max(0, y - cradius);\r
- const int xmin = ::max(0, x - cradius);\r
- const int ymax = ::min(h - 1, y + cradius);\r
- const int xmax = ::min(w - 1, x + cradius);\r
+ value_type sum1 = VecTraits<value_type>::all(0);\r
+ float sum2 = 0;\r
\r
- float cost[] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f};\r
+ int r = ksz / 2;\r
+ float r2 = (float)(r * r);\r
\r
- const uchar* ic = img + y * img_step + channels * x;\r
+ int tx = x - r + ksz;\r
+ int ty = y - r + ksz;\r
\r
- for(int yi = ymin; yi <= ymax; yi++)\r
+ if (x - ksz/2 >=0 && y - ksz/2 >=0 && tx < src.cols && ty < src.rows)\r
+ {\r
+ for (int cy = y - r; cy < ty; ++cy)\r
+ for (int cx = x - r; cx < tx; ++cx)\r
{\r
- const T* disp_y = disp + yi * disp_step;\r
-\r
- for(int xi = xmin; xi <= xmax; xi++)\r
- {\r
- const uchar* in = img + yi * img_step + channels * xi;\r
-\r
- uchar dist_rgb = DistRgbMax<channels>::calc(in, ic);\r
-\r
- const float weight = ctable_color[dist_rgb] * (ctable_space + ::abs(y-yi)* ctable_space_step)[::abs(x-xi)];\r
+ float space2 = (x - cx) * (x - cx) + (y - cy) * (y - cy);\r
+ if (space2 > r2)\r
+ continue;\r
\r
- const T disp_reg = disp_y[xi];\r
+ value_type value = saturate_cast<value_type>(src(cy, cx));\r
\r
- cost[0] += ::min(cmax_disc, ::abs(disp_reg - dp[0])) * weight;\r
- cost[1] += ::min(cmax_disc, ::abs(disp_reg - dp[1])) * weight;\r
- cost[2] += ::min(cmax_disc, ::abs(disp_reg - dp[2])) * weight;\r
- cost[3] += ::min(cmax_disc, ::abs(disp_reg - dp[3])) * weight;\r
- cost[4] += ::min(cmax_disc, ::abs(disp_reg - dp[4])) * weight;\r
- }\r
+ float weight = ::exp(space2 * sigma_spatial2_inv_half + sqr(norm_l1(value - center)) * sigma_color2_inv_half);\r
+ sum1 = sum1 + weight * value;\r
+ sum2 = sum2 + weight;\r
}\r
+ }\r
+ else\r
+ {\r
+ for (int cy = y - r; cy < ty; ++cy)\r
+ for (int cx = x - r; cx < tx; ++cx)\r
+ {\r
+ float space2 = (x - cx) * (x - cx) + (y - cy) * (y - cy);\r
+ if (space2 > r2)\r
+ continue;\r
\r
- float minimum = numeric_limits<float>::max();\r
- int id = 0;\r
+ value_type value = saturate_cast<value_type>(b.at(cy, cx, src.data, src.step));\r
\r
- if (cost[0] < minimum)\r
- {\r
- minimum = cost[0];\r
- id = 0;\r
- }\r
- if (cost[1] < minimum)\r
- {\r
- minimum = cost[1];\r
- id = 1;\r
- }\r
- if (cost[2] < minimum)\r
- {\r
- minimum = cost[2];\r
- id = 2;\r
- }\r
- if (cost[3] < minimum)\r
- {\r
- minimum = cost[3];\r
- id = 3;\r
- }\r
- if (cost[4] < minimum)\r
- {\r
- minimum = cost[4];\r
- id = 4;\r
- }\r
+ float weight = ::exp(space2 * sigma_spatial2_inv_half + sqr(norm_l1(value - center)) * sigma_color2_inv_half);\r
\r
- *(disp + y * disp_step + x) = dp[id];\r
- }\r
+ sum1 = sum1 + weight * value;\r
+ sum2 = sum2 + weight;\r
+ }\r
}\r
+ dst(y, x) = saturate_cast<T>(sum1 / sum2);\r
}\r
\r
- template <typename T>\r
- void bilateral_filter_caller(PtrStepSz<T> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream)\r
+ template<typename T, template <typename> class B>\r
+ void bilateral_caller(const PtrStepSzb& src, PtrStepSzb dst, int kernel_size, float sigma_spatial, float sigma_color, cudaStream_t stream)\r
{\r
- dim3 threads(32, 8, 1);\r
- dim3 grid(1, 1, 1);\r
- grid.x = divUp(disp.cols, threads.x << 1);\r
- grid.y = divUp(disp.rows, threads.y);\r
+ dim3 block (32, 8);\r
+ dim3 grid (divUp (src.cols, block.x), divUp (src.rows, block.y));\r
\r
- switch (channels)\r
- {\r
- case 1:\r
- for (int i = 0; i < iters; ++i)\r
- {\r
- bilateral_filter<1><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);\r
- cudaSafeCall( cudaGetLastError() );\r
-\r
- bilateral_filter<1><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);\r
- cudaSafeCall( cudaGetLastError() );\r
- }\r
- break;\r
- case 3:\r
- for (int i = 0; i < iters; ++i)\r
- {\r
- bilateral_filter<3><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);\r
- cudaSafeCall( cudaGetLastError() );\r
-\r
- bilateral_filter<3><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);\r
- cudaSafeCall( cudaGetLastError() );\r
- }\r
- break;\r
- default:\r
- cv::gpu::error("Unsupported channels count", __FILE__, __LINE__, "bilateral_filter_caller");\r
- }\r
+ B<T> b(src.rows, src.cols);\r
+\r
+ float sigma_spatial2_inv_half = -0.5f/(sigma_spatial * sigma_spatial);\r
+ float sigma_color2_inv_half = -0.5f/(sigma_color * sigma_color);\r
+\r
+ cudaSafeCall( cudaFuncSetCacheConfig (bilateral_kernel<T, B<T> >, cudaFuncCachePreferL1) );\r
+ bilateral_kernel<<<grid, block>>>((PtrStepSz<T>)src, (PtrStepSz<T>)dst, b, kernel_size, sigma_spatial2_inv_half, sigma_color2_inv_half);\r
+ cudaSafeCall ( cudaGetLastError () );\r
\r
if (stream == 0)\r
cudaSafeCall( cudaDeviceSynchronize() );\r
}\r
\r
- void bilateral_filter_gpu(PtrStepSzb disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream)\r
+ template<typename T>\r
+ void bilateral_filter_gpu(const PtrStepSzb& src, PtrStepSzb dst, int kernel_size, float gauss_spatial_coeff, float gauss_color_coeff, int borderMode, cudaStream_t stream)\r
{\r
- bilateral_filter_caller(disp, img, channels, iters, stream);\r
- }\r
+ typedef void (*caller_t)(const PtrStepSzb& src, PtrStepSzb dst, int kernel_size, float sigma_spatial, float sigma_color, cudaStream_t stream);\r
\r
- void bilateral_filter_gpu(PtrStepSz<short> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream)\r
- {\r
- bilateral_filter_caller(disp, img, channels, iters, stream);\r
+ static caller_t funcs[] = \r
+ {\r
+ bilateral_caller<T, BrdReflect101>,\r
+ bilateral_caller<T, BrdReplicate>,\r
+ bilateral_caller<T, BrdConstant>,\r
+ bilateral_caller<T, BrdReflect>,\r
+ bilateral_caller<T, BrdWrap>,\r
+ };\r
+ funcs[borderMode](src, dst, kernel_size, gauss_spatial_coeff, gauss_color_coeff, stream);\r
}\r
- } // namespace bilateral_filter\r
-}}} // namespace cv { namespace gpu { namespace device\r
+ }\r
+}}}\r
+\r
+\r
+#define OCV_INSTANTIATE_BILATERAL_FILTER(T) \\r
+ template void cv::gpu::device::imgproc::bilateral_filter_gpu<T>(const PtrStepSzb&, PtrStepSzb, int, float, float, int, cudaStream_t);\r
+\r
+OCV_INSTANTIATE_BILATERAL_FILTER(uchar)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(uchar2)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(uchar3)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(uchar4)\r
+\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(schar)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(schar2)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(schar3)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(schar4)\r
+\r
+OCV_INSTANTIATE_BILATERAL_FILTER(short)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(short2)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(short3)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(short4)\r
+\r
+OCV_INSTANTIATE_BILATERAL_FILTER(ushort)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(ushort2)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(ushort3)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(ushort4)\r
+\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(int)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(int2)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(int3)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(int4)\r
+\r
+OCV_INSTANTIATE_BILATERAL_FILTER(float)\r
+//OCV_INSTANTIATE_BILATERAL_FILTER(float2)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(float3)\r
+OCV_INSTANTIATE_BILATERAL_FILTER(float4)\r
--- /dev/null
+/*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.
+// Copyright (C) 1993-2011, NVIDIA Corporation, all rights reserved.
+// 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 bpied warranties, including, but not limited to, the bpied
+// 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 "internal_shared.hpp"
+
+#include "opencv2/gpu/device/vec_traits.hpp"
+#include "opencv2/gpu/device/vec_math.hpp"
+#include "opencv2/gpu/device/border_interpolate.hpp"
+
+using namespace cv::gpu;
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+
+//////////////////////////////////////////////////////////////////////////////////
+/// Non local means denosings
+
+namespace cv { namespace gpu { namespace device
+{
+ namespace imgproc
+ {
+ __device__ __forceinline__ float norm2(const float& v) { return v*v; }
+ __device__ __forceinline__ float norm2(const float2& v) { return v.x*v.x + v.y*v.y; }
+ __device__ __forceinline__ float norm2(const float3& v) { return v.x*v.x + v.y*v.y + v.z*v.z; }
+ __device__ __forceinline__ float norm2(const float4& v) { return v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; }
+
+ template<typename T, typename B>
+ __global__ void nlm_kernel(const PtrStepSz<T> src, PtrStep<T> dst, const B b, int search_radius, int block_radius, float h2_inv_half)
+ {
+ typedef typename TypeVec<float, VecTraits<T>::cn>::vec_type value_type;
+
+ const int x = blockDim.x * blockIdx.x + threadIdx.x;
+ const int y = blockDim.y * blockIdx.y + threadIdx.y;
+
+ if (x >= src.cols || y >= src.rows)
+ return;
+
+ float block_radius2_inv = -1.f/(block_radius * block_radius);
+
+ value_type sum1 = VecTraits<value_type>::all(0);
+ float sum2 = 0.f;
+
+ for(float cy = -search_radius; cy <= search_radius; ++cy)
+ for(float cx = -search_radius; cx <= search_radius; ++cx)
+ {
+ float color2 = 0;
+ for(float by = -block_radius; by <= block_radius; ++by)
+ for(float bx = -block_radius; bx <= block_radius; ++bx)
+ {
+ value_type v1 = saturate_cast<value_type>(src(y + by, x + bx));
+ value_type v2 = saturate_cast<value_type>(src(y + cy + by, x + cx + bx));
+ color2 += norm2(v1 - v2);
+ }
+
+ float dist2 = cx * cx + cy * cy;
+ float w = __expf(color2 * h2_inv_half + dist2 * block_radius2_inv);
+
+ sum1 = sum1 + saturate_cast<value_type>(src(y + cy, x + cy)) * w;
+ sum2 += w;
+ }
+
+ dst(y, x) = saturate_cast<T>(sum1 / sum2);
+
+ }
+
+ template<typename T, template <typename> class B>
+ void nlm_caller(const PtrStepSzb src, PtrStepSzb dst, int search_radius, int block_radius, float h, cudaStream_t stream)
+ {
+ dim3 block (32, 8);
+ dim3 grid (divUp (src.cols, block.x), divUp (src.rows, block.y));
+
+ B<T> b(src.rows, src.cols);
+
+ float h2_inv_half = -0.5f/(h * h * VecTraits<T>::cn);
+
+ cudaSafeCall( cudaFuncSetCacheConfig (nlm_kernel<T, B<T> >, cudaFuncCachePreferL1) );
+ nlm_kernel<<<grid, block>>>((PtrStepSz<T>)src, (PtrStepSz<T>)dst, b, search_radius, block_radius, h2_inv_half);
+ cudaSafeCall ( cudaGetLastError () );
+
+ if (stream == 0)
+ cudaSafeCall( cudaDeviceSynchronize() );
+ }
+
+ template<typename T>
+ void nlm_bruteforce_gpu(const PtrStepSzb& src, PtrStepSzb dst, int search_radius, int block_radius, float h, int borderMode, cudaStream_t stream)
+ {
+ typedef void (*func_t)(const PtrStepSzb src, PtrStepSzb dst, int search_radius, int block_radius, float h, cudaStream_t stream);
+
+ static func_t funcs[] =
+ {
+ nlm_caller<T, BrdReflect101>,
+ nlm_caller<T, BrdReplicate>,
+ nlm_caller<T, BrdConstant>,
+ nlm_caller<T, BrdReflect>,
+ nlm_caller<T, BrdWrap>,
+ };
+ funcs[borderMode](src, dst, search_radius, block_radius, h, stream);
+ }
+
+ template void nlm_bruteforce_gpu<uchar>(const PtrStepSzb&, PtrStepSzb, int, int, float, int, cudaStream_t);
+ template void nlm_bruteforce_gpu<uchar3>(const PtrStepSzb&, PtrStepSzb, int, int, float, int, cudaStream_t);
+ }
+}}}
--- /dev/null
+/*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.
+// 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 GpuMaterials 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 bpied warranties, including, but not limited to, the bpied
+// 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"
+
+using namespace cv;
+using namespace cv::gpu;
+
+#if !defined (HAVE_CUDA)
+
+cv::gpu::bilateralFilter(const GpuMat&, GpuMat&, int, float, float, int, Stream&) { throw_nogpu(); }
+
+#else
+
+
+namespace cv { namespace gpu { namespace device
+{
+ namespace imgproc
+ {
+ template<typename T>
+ void bilateral_filter_gpu(const PtrStepSzb& src, PtrStepSzb dst, int kernel_size, float sigma_spatial, float sigma_color, int borderMode, cudaStream_t stream);
+
+ template<typename T>
+ void nlm_bruteforce_gpu(const PtrStepSzb& src, PtrStepSzb dst, int search_radius, int block_radius, float h, int borderMode, cudaStream_t stream);
+ }
+}}}
+
+void cv::gpu::bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial, int borderMode, Stream& s)
+{
+ using cv::gpu::device::imgproc::bilateral_filter_gpu;
+
+ typedef void (*func_t)(const PtrStepSzb& src, PtrStepSzb dst, int kernel_size, float sigma_spatial, float sigma_color, int borderMode, cudaStream_t s);
+
+ static const func_t funcs[6][4] =
+ {
+ {bilateral_filter_gpu<uchar> , 0 /*bilateral_filter_gpu<uchar2>*/ , bilateral_filter_gpu<uchar3> , bilateral_filter_gpu<uchar4> },
+ {0 /*bilateral_filter_gpu<schar>*/, 0 /*bilateral_filter_gpu<schar2>*/ , 0 /*bilateral_filter_gpu<schar3>*/, 0 /*bilateral_filter_gpu<schar4>*/},
+ {bilateral_filter_gpu<ushort> , 0 /*bilateral_filter_gpu<ushort2>*/, bilateral_filter_gpu<ushort3> , bilateral_filter_gpu<ushort4> },
+ {bilateral_filter_gpu<short> , 0 /*bilateral_filter_gpu<short2>*/ , bilateral_filter_gpu<short3> , bilateral_filter_gpu<short4> },
+ {0 /*bilateral_filter_gpu<int>*/ , 0 /*bilateral_filter_gpu<int2>*/ , 0 /*bilateral_filter_gpu<int3>*/ , 0 /*bilateral_filter_gpu<int4>*/ },
+ {bilateral_filter_gpu<float> , 0 /*bilateral_filter_gpu<float2>*/ , bilateral_filter_gpu<float3> , bilateral_filter_gpu<float4> }
+ };
+
+ sigma_color = (sigma_color <= 0 ) ? 1 : sigma_color;
+ sigma_spatial = (sigma_spatial <= 0 ) ? 1 : sigma_spatial;
+
+
+ int radius = (kernel_size <= 0) ? cvRound(sigma_spatial*1.5) : kernel_size/2;
+ kernel_size = std::max(radius, 1)*2 + 1;
+
+ CV_Assert(src.depth() <= CV_32F && src.channels() <= 4);
+ const func_t func = funcs[src.depth()][src.channels() - 1];
+ CV_Assert(func != 0);
+
+ CV_Assert(borderMode == BORDER_REFLECT101 || borderMode == BORDER_REPLICATE || borderMode == BORDER_CONSTANT || borderMode == BORDER_REFLECT || borderMode == BORDER_WRAP);
+
+ int gpuBorderType;
+ CV_Assert(tryConvertToGpuBorderType(borderMode, gpuBorderType));
+
+ dst.create(src.size(), src.type());
+ func(src, dst, kernel_size, sigma_spatial, sigma_color, gpuBorderType, StreamAccessor::getStream(s));
+}
+
+void cv::gpu::nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, int search_window_size, int block_size, int borderMode, Stream& s)
+{
+ using cv::gpu::device::imgproc::nlm_bruteforce_gpu;
+ typedef void (*func_t)(const PtrStepSzb& src, PtrStepSzb dst, int search_radius, int block_radius, float h, int borderMode, cudaStream_t stream);
+
+ static const func_t funcs[4] = { nlm_bruteforce_gpu<uchar>, 0 /*nlm_bruteforce_gpu<uchar2>*/ , nlm_bruteforce_gpu<uchar3>, 0/*nlm_bruteforce_gpu<uchar4>,*/ };
+
+ CV_Assert(src.type() == CV_8U || src.type() == CV_8UC3);
+
+ const func_t func = funcs[src.channels() - 1];
+ CV_Assert(func != 0);
+
+ int b = borderMode;
+ CV_Assert(b == BORDER_REFLECT101 || b == BORDER_REPLICATE || b == BORDER_CONSTANT || b == BORDER_REFLECT || b == BORDER_WRAP);
+
+ int gpuBorderType;
+ CV_Assert(tryConvertToGpuBorderType(borderMode, gpuBorderType));
+
+ int search_radius = search_window_size/2;
+ int block_radius = block_size/2;
+
+ dst.create(src.size(), src.type());
+ func(src, dst, search_radius, block_radius, h, gpuBorderType, StreamAccessor::getStream(s));
+}
+
+
+
+
+
+
+
+
+#endif
\ No newline at end of file
for(size_t j = 0; j < m.size(); ++j)
{
- float dx = p.x - m[j].x;
- float dy = p.y - m[j].y;
+ float dx = (float)(p.x - m[j].x);
+ float dy = (float)(p.y - m[j].y);
if (dx * dx + dy * dy < minDist)
{
#include "saturate_cast.hpp"\r
#include "vec_traits.hpp"\r
#include "type_traits.hpp"\r
+#include "device_functions.h"\r
\r
namespace cv { namespace gpu { namespace device\r
{\r
OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(pow, ::pow)\r
\r
#undef OPENCV_GPU_IMPLEMENT_UN_FUNCTOR\r
+ #undef OPENCV_GPU_IMPLEMENT_UN_FUNCTOR_NO_DOUBLE\r
#undef OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR\r
\r
template<typename T> struct hypot_sqr_func : binary_function<T, T, float>\r
--- /dev/null
+/*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.
+//
+//
+// Intel License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2000, Intel Corporation, all rights reserved.
+// 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 Intel Corporation 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 "test_precomp.hpp"
+
+#ifdef HAVE_CUDA
+
+////////////////////////////////////////////////////////
+// BilateralFilter
+
+PARAM_TEST_CASE(BilateralFilter, cv::gpu::DeviceInfo, cv::Size, MatType)
+{
+ cv::gpu::DeviceInfo devInfo;
+ cv::Size size;
+ int type;
+ int kernel_size;
+ float sigma_color;
+ float sigma_spatial;
+
+ virtual void SetUp()
+ {
+ devInfo = GET_PARAM(0);
+ size = GET_PARAM(1);
+ type = GET_PARAM(2);
+
+ kernel_size = 5;
+ sigma_color = 10.f;
+ sigma_spatial = 3.5f;
+
+ cv::gpu::setDevice(devInfo.deviceID());
+ }
+};
+
+TEST_P(BilateralFilter, Accuracy)
+{
+ cv::Mat src = randomMat(size, type);
+ //cv::Mat src = readImage("hog/road.png", cv::IMREAD_GRAYSCALE);
+ //cv::Mat src = readImage("csstereobp/aloe-R.png", cv::IMREAD_GRAYSCALE);
+
+ src.convertTo(src, type);
+ cv::gpu::GpuMat dst;
+
+ cv::gpu::bilateralFilter(loadMat(src), dst, kernel_size, sigma_color, sigma_spatial);
+
+ cv::Mat dst_gold;
+ cv::bilateralFilter(src, dst_gold, kernel_size, sigma_color, sigma_spatial);
+
+ EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-3 : 1.0);
+}
+
+INSTANTIATE_TEST_CASE_P(GPU_ImgProc, BilateralFilter, testing::Combine(
+ ALL_DEVICES,
+ testing::Values(cv::Size(128, 128), cv::Size(113, 113), cv::Size(639, 481)),
+ testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_32FC1), MatType(CV_32FC3))
+ ));
+
+
+////////////////////////////////////////////////////////
+// Brute Force Non local means
+
+struct NonLocalMeans: testing::TestWithParam<cv::gpu::DeviceInfo>
+{
+ cv::gpu::DeviceInfo devInfo;
+
+ virtual void SetUp()
+ {
+ devInfo = GetParam();
+ cv::gpu::setDevice(devInfo.deviceID());
+ }
+};
+
+TEST_P(NonLocalMeans, Regression)
+{
+ using cv::gpu::GpuMat;
+
+ cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
+ ASSERT_FALSE(bgr.empty());
+
+ cv::Mat gray;
+ cv::cvtColor(bgr, gray, CV_BGR2GRAY);
+
+ GpuMat dbgr, dgray;
+ cv::gpu::nonLocalMeans(GpuMat(bgr), dbgr, 10);
+ cv::gpu::nonLocalMeans(GpuMat(gray), dgray, 10);
+
+#if 0
+ dumpImage("denoising/denoised_lena_bgr.png", cv::Mat(dbgr));
+ dumpImage("denoising/denoised_lena_gray.png", cv::Mat(dgray));
+#endif
+
+ cv::Mat bgr_gold = readImage("denoising/denoised_lena_bgr.png", cv::IMREAD_COLOR);
+ cv::Mat gray_gold = readImage("denoising/denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
+ ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
+
+ EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4);
+ EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4);
+}
+
+INSTANTIATE_TEST_CASE_P(GPU_ImgProc, NonLocalMeans, ALL_DEVICES);
+
+
+#endif // HAVE_CUDA
\ No newline at end of file
}\r
\r
//////////////////////////////////////////////////////////////////////\r
+// Image dumping\r
+\r
+void dumpImage(const std::string& fileName, const cv::Mat& image)\r
+{\r
+ cv::imwrite(TS::ptr()->get_data_path() + fileName, image);\r
+}\r
+\r
+//////////////////////////////////////////////////////////////////////\r
// Gpu devices\r
\r
bool supportFeature(const DeviceInfo& info, FeatureSet feature)\r
cv::Mat readImageType(const std::string& fname, int type);\r
\r
//////////////////////////////////////////////////////////////////////\r
+// Image dumping\r
+\r
+void dumpImage(const std::string& fileName, const cv::Mat& image);\r
+\r
+//////////////////////////////////////////////////////////////////////\r
// Gpu devices\r
\r
//! return true if device supports specified feature and gpu module was built with support the feature.\r
Bilateral Filtering
\****************************************************************************************/
+#undef CV_SSE3
+
namespace cv
{