From: Vladislav Vinogradov Date: Tue, 4 Jun 2013 09:32:35 +0000 (+0400) Subject: Revert "Revert "Merge pull request #836 from jet47:gpu-modules"" X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3882^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3eeaa9189c3fc771f098ff162f673c506db2bbe7;p=platform%2Fupstream%2Fopencv.git Revert "Revert "Merge pull request #836 from jet47:gpu-modules"" --- diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index 8db6677..3233d65 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -37,6 +37,9 @@ if(CUDA_FOUND) if(WITH_NVCUVID) find_cuda_helper_libs(nvcuvid) + if(WIN32) + find_cuda_helper_libs(nvcuvenc) + endif() set(HAVE_NVCUVID 1) endif() diff --git a/modules/core/include/opencv2/core/cuda/border_interpolate.hpp b/modules/core/include/opencv2/core/cuda/border_interpolate.hpp index 1347a2f..6c53f09 100644 --- a/modules/core/include/opencv2/core/cuda/border_interpolate.hpp +++ b/modules/core/include/opencv2/core/cuda/border_interpolate.hpp @@ -73,8 +73,8 @@ namespace cv { namespace gpu { namespace cudev return (x >= 0 && x < width) ? saturate_cast(data[x]) : val; } - const int width; - const D val; + int width; + D val; }; template struct BrdColConstant @@ -98,8 +98,8 @@ namespace cv { namespace gpu { namespace cudev return (y >= 0 && y < height) ? saturate_cast(*(const T*)((const char*)data + y * step)) : val; } - const int height; - const D val; + int height; + D val; }; template struct BrdConstant @@ -120,9 +120,9 @@ namespace cv { namespace gpu { namespace cudev return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast(src(y, x)) : val; } - const int height; - const int width; - const D val; + int height; + int width; + D val; }; ////////////////////////////////////////////////////////////// @@ -165,7 +165,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(data[idx_col(x)]); } - const int last_col; + int last_col; }; template struct BrdColReplicate @@ -205,7 +205,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(*(const T*)((const char*)data + idx_row(y) * step)); } - const int last_row; + int last_row; }; template struct BrdReplicate @@ -255,8 +255,8 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(src(idx_row(y), idx_col(x))); } - const int last_row; - const int last_col; + int last_row; + int last_col; }; ////////////////////////////////////////////////////////////// @@ -299,7 +299,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(data[idx_col(x)]); } - const int last_col; + int last_col; }; template struct BrdColReflect101 @@ -339,7 +339,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); } - const int last_row; + int last_row; }; template struct BrdReflect101 @@ -389,8 +389,8 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(src(idx_row(y), idx_col(x))); } - const int last_row; - const int last_col; + int last_row; + int last_col; }; ////////////////////////////////////////////////////////////// @@ -433,7 +433,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(data[idx_col(x)]); } - const int last_col; + int last_col; }; template struct BrdColReflect @@ -473,7 +473,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); } - const int last_row; + int last_row; }; template struct BrdReflect @@ -523,8 +523,8 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(src(idx_row(y), idx_col(x))); } - const int last_row; - const int last_col; + int last_row; + int last_col; }; ////////////////////////////////////////////////////////////// @@ -567,7 +567,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(data[idx_col(x)]); } - const int width; + int width; }; template struct BrdColWrap @@ -607,7 +607,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); } - const int height; + int height; }; template struct BrdWrap @@ -664,8 +664,8 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(src(idx_row(y), idx_col(x))); } - const int height; - const int width; + int height; + int width; }; ////////////////////////////////////////////////////////////// @@ -683,8 +683,8 @@ namespace cv { namespace gpu { namespace cudev return b.at(y, x, ptr); } - const Ptr2D ptr; - const B b; + Ptr2D ptr; + B b; }; // under win32 there is some bug with templated types that passed as kernel parameters @@ -704,10 +704,10 @@ namespace cv { namespace gpu { namespace cudev return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast(src(y, x)) : val; } - const Ptr2D src; - const int height; - const int width; - const D val; + Ptr2D src; + int height; + int width; + D val; }; }}} // namespace cv { namespace gpu { namespace cudev diff --git a/modules/core/include/opencv2/core/cuda/common.hpp b/modules/core/include/opencv2/core/cuda/common.hpp index 774500e..434a3eb 100644 --- a/modules/core/include/opencv2/core/cuda/common.hpp +++ b/modules/core/include/opencv2/core/cuda/common.hpp @@ -87,15 +87,6 @@ namespace cv { namespace gpu namespace cv { namespace gpu { - enum - { - BORDER_REFLECT101_GPU = 0, - BORDER_REPLICATE_GPU, - BORDER_CONSTANT_GPU, - BORDER_REFLECT_GPU, - BORDER_WRAP_GPU - }; - namespace cudev { __host__ __device__ __forceinline__ int divUp(int total, int grain) diff --git a/modules/core/include/opencv2/core/cuda/emulation.hpp b/modules/core/include/opencv2/core/cuda/emulation.hpp index 3df2646..b484f23 100644 --- a/modules/core/include/opencv2/core/cuda/emulation.hpp +++ b/modules/core/include/opencv2/core/cuda/emulation.hpp @@ -43,6 +43,7 @@ #ifndef OPENCV_GPU_EMULATION_HPP_ #define OPENCV_GPU_EMULATION_HPP_ +#include "common.hpp" #include "warp_reduce.hpp" namespace cv { namespace gpu { namespace cudev @@ -131,8 +132,130 @@ namespace cv { namespace gpu { namespace cudev return ::atomicMin(address, val); #endif } + }; // struct cmem + + struct glob + { + static __device__ __forceinline__ int atomicAdd(int* address, int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ unsigned int atomicAdd(unsigned int* address, unsigned int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ float atomicAdd(float* address, float val) + { + #if __CUDA_ARCH__ >= 200 + return ::atomicAdd(address, val); + #else + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(val + __int_as_float(assumed))); + } while (assumed != old); + return __int_as_float(old); + #endif + } + static __device__ __forceinline__ double atomicAdd(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(val + __longlong_as_double(assumed))); + } while (assumed != old); + return __longlong_as_double(old); + #else + (void) address; + (void) val; + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMin(int* address, int val) + { + return ::atomicMin(address, val); + } + static __device__ __forceinline__ float atomicMin(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fminf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + (void) address; + (void) val; + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMin(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmin(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + (void) address; + (void) val; + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMax(int* address, int val) + { + return ::atomicMax(address, val); + } + static __device__ __forceinline__ float atomicMax(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fmaxf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + (void) address; + (void) val; + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMax(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmax(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + (void) address; + (void) val; + return 0.0; + #endif + } }; - }; + }; //struct Emulation }}} // namespace cv { namespace gpu { namespace cudev #endif /* OPENCV_GPU_EMULATION_HPP_ */ diff --git a/modules/core/include/opencv2/core/cuda/filters.hpp b/modules/core/include/opencv2/core/cuda/filters.hpp index 19a8c58..f35f662 100644 --- a/modules/core/include/opencv2/core/cuda/filters.hpp +++ b/modules/core/include/opencv2/core/cuda/filters.hpp @@ -67,7 +67,7 @@ namespace cv { namespace gpu { namespace cudev return src(__float2int_rz(y), __float2int_rz(x)); } - const Ptr2D src; + Ptr2D src; }; template struct LinearFilter @@ -107,7 +107,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(out); } - const Ptr2D src; + Ptr2D src; }; template struct CubicFilter @@ -166,7 +166,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(res); } - const Ptr2D src; + Ptr2D src; }; // for integer scaling template struct IntegerAreaFilter @@ -203,7 +203,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(out); } - const Ptr2D src; + Ptr2D src; float scale_x, scale_y ,scale; }; @@ -269,7 +269,7 @@ namespace cv { namespace gpu { namespace cudev return saturate_cast(out); } - const Ptr2D src; + Ptr2D src; float scale_x, scale_y; int width, haight; }; diff --git a/modules/core/include/opencv2/core/cuda/functional.hpp b/modules/core/include/opencv2/core/cuda/functional.hpp index cb665fb..d6c0192 100644 --- a/modules/core/include/opencv2/core/cuda/functional.hpp +++ b/modules/core/include/opencv2/core/cuda/functional.hpp @@ -554,8 +554,8 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ thresh_binary_func(const thresh_binary_func& other) : thresh(other.thresh), maxVal(other.maxVal) {} - const T thresh; - const T maxVal; + T thresh; + T maxVal; }; template struct thresh_binary_inv_func : unary_function @@ -571,8 +571,8 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ thresh_binary_inv_func(const thresh_binary_inv_func& other) : thresh(other.thresh), maxVal(other.maxVal) {} - const T thresh; - const T maxVal; + T thresh; + T maxVal; }; template struct thresh_trunc_func : unary_function @@ -588,7 +588,7 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ thresh_trunc_func(const thresh_trunc_func& other) : thresh(other.thresh) {} - const T thresh; + T thresh; }; template struct thresh_to_zero_func : unary_function @@ -604,7 +604,7 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ thresh_to_zero_func(const thresh_to_zero_func& other) : thresh(other.thresh) {} - const T thresh; + T thresh; }; template struct thresh_to_zero_inv_func : unary_function @@ -620,7 +620,7 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ thresh_to_zero_inv_func(const thresh_to_zero_inv_func& other) : thresh(other.thresh) {} - const T thresh; + T thresh; }; // Function Object Adaptors @@ -636,7 +636,7 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ unary_negate() {} __host__ __device__ __forceinline__ unary_negate(const unary_negate& other) : pred(other.pred) {} - const Predicate pred; + Predicate pred; }; template __host__ __device__ __forceinline__ unary_negate not1(const Predicate& pred) @@ -657,7 +657,7 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ binary_negate() {} __host__ __device__ __forceinline__ binary_negate(const binary_negate& other) : pred(other.pred) {} - const Predicate pred; + Predicate pred; }; template __host__ __device__ __forceinline__ binary_negate not2(const BinaryPredicate& pred) @@ -677,8 +677,8 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ binder1st() {} __host__ __device__ __forceinline__ binder1st(const binder1st& other) : op(other.op), arg1(other.arg1) {} - const Op op; - const typename Op::first_argument_type arg1; + Op op; + typename Op::first_argument_type arg1; }; template __host__ __device__ __forceinline__ binder1st bind1st(const Op& op, const T& x) @@ -698,8 +698,8 @@ namespace cv { namespace gpu { namespace cudev __host__ __device__ __forceinline__ binder2nd() {} __host__ __device__ __forceinline__ binder2nd(const binder2nd& other) : op(other.op), arg2(other.arg2) {} - const Op op; - const typename Op::second_argument_type arg2; + Op op; + typename Op::second_argument_type arg2; }; template __host__ __device__ __forceinline__ binder2nd bind2nd(const Op& op, const T& x) diff --git a/modules/core/include/opencv2/core/gpu_private.hpp b/modules/core/include/opencv2/core/gpu_private.hpp index be194f5..7692bc2 100644 --- a/modules/core/include/opencv2/core/gpu_private.hpp +++ b/modules/core/include/opencv2/core/gpu_private.hpp @@ -74,10 +74,6 @@ namespace cv { namespace gpu { CV_EXPORTS cv::String getNppErrorMessage(int code); CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code); - - // Converts CPU border extrapolation mode into GPU internal analogue. - // Returns true if the GPU analogue exists, false otherwise. - CV_EXPORTS bool tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType); }} #ifndef HAVE_CUDA diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index c5d4d7a..11bb419 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -1678,33 +1678,3 @@ String cv::gpu::getCudaDriverApiErrorMessage(int code) return getErrorString(code, cu_errors, cu_errors_num); #endif } - -bool cv::gpu::tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType) -{ -#ifndef HAVE_CUDA - (void) cpuBorderType; - (void) gpuBorderType; - return false; -#else - switch (cpuBorderType) - { - case IPL_BORDER_REFLECT_101: - gpuBorderType = cv::gpu::BORDER_REFLECT101_GPU; - return true; - case IPL_BORDER_REPLICATE: - gpuBorderType = cv::gpu::BORDER_REPLICATE_GPU; - return true; - case IPL_BORDER_CONSTANT: - gpuBorderType = cv::gpu::BORDER_CONSTANT_GPU; - return true; - case IPL_BORDER_REFLECT: - gpuBorderType = cv::gpu::BORDER_REFLECT_GPU; - return true; - case IPL_BORDER_WRAP: - gpuBorderType = cv::gpu::BORDER_WRAP_GPU; - return true; - default: - return false; - }; -#endif -} diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 1df8358..1460568 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -3,101 +3,10 @@ if(ANDROID OR IOS) endif() set(the_description "GPU-accelerated Computer Vision") -ocv_add_module(gpu opencv_imgproc opencv_calib3d opencv_objdetect opencv_video opencv_photo opencv_legacy) -ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cuda") +ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4100 /wd4324 /wd4512 /wd4515 -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter) -file(GLOB lib_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") -file(GLOB lib_int_hdrs "src/*.hpp" "src/*.h") -file(GLOB lib_cuda_hdrs "src/cuda/*.hpp" "src/cuda/*.h") -file(GLOB lib_srcs "src/*.cpp") -file(GLOB lib_cuda "src/cuda/*.cu*") - -source_group("Include" FILES ${lib_hdrs}) -source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs}) -source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs}) - -if(HAVE_CUDA) - file(GLOB_RECURSE ncv_srcs "src/nvidia/*.cpp" "src/nvidia/*.h*") - file(GLOB_RECURSE ncv_cuda "src/nvidia/*.cu") - set(ncv_files ${ncv_srcs} ${ncv_cuda}) - - source_group("Src\\NVidia" FILES ${ncv_files}) - ocv_include_directories("src/nvidia" "src/nvidia/core" "src/nvidia/NPP_staging" ${CUDA_INCLUDE_DIRS}) - ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations -Wshadow -Wunused-parameter /wd4211 /wd4201 /wd4100 /wd4505 /wd4408) - - if(MSVC) - if(NOT ENABLE_NOISY_WARNINGS) - foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG) - string(REPLACE "/W4" "/W3" ${var} "${${var}}") - endforeach() - - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler /wd4251) - endif() - endif() - - ocv_cuda_compile(cuda_objs ${lib_cuda} ${ncv_cuda}) - - set(cuda_link_libs ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} ${CUDA_npp_LIBRARY}) - - if(WITH_NVCUVID) - set(cuda_link_libs ${cuda_link_libs} ${CUDA_nvcuvid_LIBRARY}) - endif() - - if(WIN32) - find_cuda_helper_libs(nvcuvenc) - set(cuda_link_libs ${cuda_link_libs} ${CUDA_nvcuvenc_LIBRARY}) - endif() - - if(WITH_FFMPEG) - set(cuda_link_libs ${cuda_link_libs} ${HIGHGUI_LIBRARIES}) - endif() -else() - set(lib_cuda "") - set(cuda_objs "") - set(cuda_link_libs "") - set(ncv_files "") -endif() - -ocv_set_module_sources( - HEADERS ${lib_hdrs} - SOURCES ${lib_int_hdrs} ${lib_cuda_hdrs} ${lib_srcs} ${lib_cuda} ${ncv_files} ${cuda_objs} - ) - -ocv_create_module(${cuda_link_libs}) - -if(HAVE_CUDA) - if(HAVE_CUFFT) - CUDA_ADD_CUFFT_TO_TARGET(${the_module}) - endif() - - if(HAVE_CUBLAS) - CUDA_ADD_CUBLAS_TO_TARGET(${the_module}) - endif() - - install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp - DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2/${name} - COMPONENT main) -endif() - -ocv_add_precompiled_headers(${the_module}) - -################################################################################################################ -################################ GPU Module Tests ##################################################### -################################################################################################################ -file(GLOB test_srcs "test/*.cpp") -file(GLOB test_hdrs "test/*.hpp" "test/*.h") - -set(nvidia "") -if(HAVE_CUDA) - file(GLOB nvidia "test/nvidia/*.cpp" "test/nvidia/*.hpp" "test/nvidia/*.h") - set(nvidia FILES "Src\\\\\\\\NVidia" ${nvidia}) # 8 ugly backslashes :'( -endif() - -ocv_add_accuracy_tests(FILES "Include" ${test_hdrs} - FILES "Src" ${test_srcs} - ${nvidia}) -ocv_add_perf_tests() +ocv_define_module(gpu opencv_calib3d opencv_objdetect opencv_gpuarithm opencv_gpuwarping OPTIONAL opencv_gpulegacy) if(HAVE_CUDA) add_subdirectory(perf4au) diff --git a/modules/gpu/app/nv_perf_test/CMakeLists.txt b/modules/gpu/app/nv_perf_test/CMakeLists.txt deleted file mode 100644 index c13f5ef..0000000 --- a/modules/gpu/app/nv_perf_test/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) - -project(nv_perf_test) - -find_package(OpenCV REQUIRED) -include_directories(${OpenCV_INCLUDE_DIR}) - -add_executable(${PROJECT_NAME} main.cpp) - -target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) diff --git a/modules/gpu/app/nv_perf_test/im1_1280x800.jpg b/modules/gpu/app/nv_perf_test/im1_1280x800.jpg deleted file mode 100644 index bdbbd4a..0000000 Binary files a/modules/gpu/app/nv_perf_test/im1_1280x800.jpg and /dev/null differ diff --git a/modules/gpu/app/nv_perf_test/im2_1280x800.jpg b/modules/gpu/app/nv_perf_test/im2_1280x800.jpg deleted file mode 100644 index ae49640..0000000 Binary files a/modules/gpu/app/nv_perf_test/im2_1280x800.jpg and /dev/null differ diff --git a/modules/gpu/app/nv_perf_test/main.cpp b/modules/gpu/app/nv_perf_test/main.cpp deleted file mode 100644 index a0363be..0000000 --- a/modules/gpu/app/nv_perf_test/main.cpp +++ /dev/null @@ -1,486 +0,0 @@ -#include -#define HAVE_CUDA 1 -#include -#include -#include -#include -#include - -static void printOsInfo() -{ -#if defined _WIN32 -# if defined _WIN64 - printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x64.\n[----------]\n"); fflush(stdout); -# else - printf("[----------]\n[ GPU INFO ] \tRun on OS Windows x32.\n[----------]\n"); fflush(stdout); -# endif -#elif defined linux -# if defined _LP64 - printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x64.\n[----------]\n"); fflush(stdout); -# else - printf("[----------]\n[ GPU INFO ] \tRun on OS Linux x32.\n[----------]\n"); fflush(stdout); -# endif -#elif defined __APPLE__ -# if defined _LP64 - printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x64.\n[----------]\n"); fflush(stdout); -# else - printf("[----------]\n[ GPU INFO ] \tRun on OS Apple x32.\n[----------]\n"); fflush(stdout); -# endif -#endif -} - -static void printCudaInfo() -{ - const int deviceCount = cv::gpu::getCudaEnabledDeviceCount(); - - printf("[----------]\n"); fflush(stdout); - printf("[ GPU INFO ] \tCUDA device count:: %d.\n", deviceCount); fflush(stdout); - printf("[----------]\n"); fflush(stdout); - - for (int i = 0; i < deviceCount; ++i) - { - cv::gpu::DeviceInfo info(i); - - printf("[----------]\n"); fflush(stdout); - printf("[ DEVICE ] \t# %d %s.\n", i, info.name().c_str()); fflush(stdout); - printf("[ ] \tCompute capability: %d.%d\n", info.majorVersion(), info.minorVersion()); fflush(stdout); - printf("[ ] \tMulti Processor Count: %d\n", info.multiProcessorCount()); fflush(stdout); - printf("[ ] \tTotal memory: %d Mb\n", static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0)); fflush(stdout); - printf("[ ] \tFree memory: %d Mb\n", static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0)); fflush(stdout); - if (!info.isCompatible()) - printf("[ GPU INFO ] \tThis device is NOT compatible with current GPU module build\n"); - printf("[----------]\n"); fflush(stdout); - } -} - -int main(int argc, char* argv[]) -{ - printOsInfo(); - printCudaInfo(); - - perf::Regression::Init("nv_perf_test"); - perf::TestBase::Init(argc, argv); - testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} - -#define DEF_PARAM_TEST(name, ...) typedef ::perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > name -#define DEF_PARAM_TEST_1(name, param_type) typedef ::perf::TestBaseWithParam< param_type > name - -////////////////////////////////////////////////////////// -// HoughLinesP - -DEF_PARAM_TEST_1(Image, std::string); - -GPU_PERF_TEST_P(Image, HoughLinesP, testing::Values(std::string("im1_1280x800.jpg"))) -{ - declare.time(30.0); - - std::string fileName = GetParam(); - - const float rho = 1.f; - const float theta = 1.f; - const int threshold = 40; - const int minLineLenght = 20; - const int maxLineGap = 5; - - cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat d_lines; - cv::gpu::HoughLinesBuf d_buf; - - cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); - - TEST_CYCLE() - { - cv::gpu::HoughLinesP(d_image, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); - } - } - else - { - cv::Mat mask; - cv::Canny(image, mask, 50, 100); - - std::vector lines; - cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLenght, maxLineGap); - - TEST_CYCLE() - { - cv::HoughLinesP(mask, lines, rho, theta, threshold, minLineLenght, maxLineGap); - } - } - - SANITY_CHECK(0); -} - -////////////////////////////////////////////////////////// -// GoodFeaturesToTrack - -DEF_PARAM_TEST(Image_Depth, std::string, perf::MatDepth); - -GPU_PERF_TEST_P(Image_Depth, GoodFeaturesToTrack, - testing::Combine( - testing::Values(std::string("im1_1280x800.jpg")), - testing::Values(CV_8U, CV_16U) - )) -{ - declare.time(60); - - const std::string fileName = std::tr1::get<0>(GetParam()); - const int depth = std::tr1::get<1>(GetParam()); - - const int maxCorners = 5000; - const double qualityLevel = 0.05; - const int minDistance = 5; - const int blockSize = 3; - const bool useHarrisDetector = true; - const double k = 0.05; - - cv::Mat src = cv::imread(fileName, cv::IMREAD_GRAYSCALE); - if (src.empty()) - FAIL() << "Unable to load source image [" << fileName << "]"; - - if (depth != CV_8U) - src.convertTo(src, depth); - - cv::Mat mask(src.size(), CV_8UC1, cv::Scalar::all(1)); - mask(cv::Rect(0, 0, 100, 100)).setTo(cv::Scalar::all(0)); - - if (PERF_RUN_GPU()) - { - cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector, k); - - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_mask(mask); - cv::gpu::GpuMat d_pts; - - d_detector(d_src, d_pts, d_mask); - - TEST_CYCLE() - { - d_detector(d_src, d_pts, d_mask); - } - } - else - { - if (depth != CV_8U) - FAIL() << "Unsupported depth"; - - cv::Mat pts; - - cv::goodFeaturesToTrack(src, pts, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k); - - TEST_CYCLE() - { - cv::goodFeaturesToTrack(src, pts, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k); - } - } - - SANITY_CHECK(0); -} - -////////////////////////////////////////////////////////// -// OpticalFlowPyrLKSparse - -typedef std::pair string_pair; - -DEF_PARAM_TEST(ImagePair_Depth_GraySource, string_pair, perf::MatDepth, bool); - -GPU_PERF_TEST_P(ImagePair_Depth_GraySource, OpticalFlowPyrLKSparse, - testing::Combine( - testing::Values(string_pair("im1_1280x800.jpg", "im2_1280x800.jpg")), - testing::Values(CV_8U, CV_16U), - testing::Bool() - )) -{ - declare.time(60); - - const string_pair fileNames = std::tr1::get<0>(GetParam()); - const int depth = std::tr1::get<1>(GetParam()); - const bool graySource = std::tr1::get<2>(GetParam()); - - // PyrLK params - const cv::Size winSize(15, 15); - const int maxLevel = 5; - const cv::TermCriteria criteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 30, 0.01); - - // GoodFeaturesToTrack params - const int maxCorners = 5000; - const double qualityLevel = 0.05; - const int minDistance = 5; - const int blockSize = 3; - const bool useHarrisDetector = true; - const double k = 0.05; - - cv::Mat src1 = cv::imread(fileNames.first, graySource ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - if (src1.empty()) - FAIL() << "Unable to load source image [" << fileNames.first << "]"; - - cv::Mat src2 = cv::imread(fileNames.second, graySource ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - if (src2.empty()) - FAIL() << "Unable to load source image [" << fileNames.second << "]"; - - cv::Mat gray_src; - if (graySource) - gray_src = src1; - else - cv::cvtColor(src1, gray_src, cv::COLOR_BGR2GRAY); - - cv::Mat pts; - cv::goodFeaturesToTrack(gray_src, pts, maxCorners, qualityLevel, minDistance, cv::noArray(), blockSize, useHarrisDetector, k); - - if (depth != CV_8U) - { - src1.convertTo(src1, depth); - src2.convertTo(src2, depth); - } - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_pts(pts.reshape(2, 1)); - cv::gpu::GpuMat d_nextPts; - cv::gpu::GpuMat d_status; - - cv::gpu::PyrLKOpticalFlow d_pyrLK; - d_pyrLK.winSize = winSize; - d_pyrLK.maxLevel = maxLevel; - d_pyrLK.iters = criteria.maxCount; - d_pyrLK.useInitialFlow = false; - - d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status); - - TEST_CYCLE() - { - d_pyrLK.sparse(d_src1, d_src2, d_pts, d_nextPts, d_status); - } - } - else - { - if (depth != CV_8U) - FAIL() << "Unsupported depth"; - - cv::Mat nextPts; - cv::Mat status; - - cv::calcOpticalFlowPyrLK(src1, src2, pts, nextPts, status, cv::noArray(), winSize, maxLevel, criteria); - - TEST_CYCLE() - { - cv::calcOpticalFlowPyrLK(src1, src2, pts, nextPts, status, cv::noArray(), winSize, maxLevel, criteria); - } - } - - SANITY_CHECK(0); -} - -////////////////////////////////////////////////////////// -// OpticalFlowFarneback - -DEF_PARAM_TEST(ImagePair_Depth, string_pair, perf::MatDepth); - -GPU_PERF_TEST_P(ImagePair_Depth, OpticalFlowFarneback, - testing::Combine( - testing::Values(string_pair("im1_1280x800.jpg", "im2_1280x800.jpg")), - testing::Values(CV_8U, CV_16U) - )) -{ - declare.time(500); - - const string_pair fileNames = std::tr1::get<0>(GetParam()); - const int depth = std::tr1::get<1>(GetParam()); - - const double pyrScale = 0.5; - const int numLevels = 6; - const int winSize = 7; - const int numIters = 15; - const int polyN = 7; - const double polySigma = 1.5; - const int flags = cv::OPTFLOW_USE_INITIAL_FLOW; - - cv::Mat src1 = cv::imread(fileNames.first, cv::IMREAD_GRAYSCALE); - if (src1.empty()) - FAIL() << "Unable to load source image [" << fileNames.first << "]"; - - cv::Mat src2 = cv::imread(fileNames.second, cv::IMREAD_GRAYSCALE); - if (src2.empty()) - FAIL() << "Unable to load source image [" << fileNames.second << "]"; - - if (depth != CV_8U) - { - src1.convertTo(src1, depth); - src2.convertTo(src2, depth); - } - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_u(src1.size(), CV_32FC1, cv::Scalar::all(0)); - cv::gpu::GpuMat d_v(src1.size(), CV_32FC1, cv::Scalar::all(0)); - - cv::gpu::FarnebackOpticalFlow d_farneback; - d_farneback.pyrScale = pyrScale; - d_farneback.numLevels = numLevels; - d_farneback.winSize = winSize; - d_farneback.numIters = numIters; - d_farneback.polyN = polyN; - d_farneback.polySigma = polySigma; - d_farneback.flags = flags; - - d_farneback(d_src1, d_src2, d_u, d_v); - - TEST_CYCLE_N(10) - { - d_farneback(d_src1, d_src2, d_u, d_v); - } - } - else - { - if (depth != CV_8U) - FAIL() << "Unsupported depth"; - - cv::Mat flow(src1.size(), CV_32FC2, cv::Scalar::all(0)); - - cv::calcOpticalFlowFarneback(src1, src2, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); - - TEST_CYCLE_N(10) - { - cv::calcOpticalFlowFarneback(src1, src2, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); - } - } - - SANITY_CHECK(0); -} - -////////////////////////////////////////////////////////// -// OpticalFlowBM - -void calcOpticalFlowBM(const cv::Mat& prev, const cv::Mat& curr, - cv::Size bSize, cv::Size shiftSize, cv::Size maxRange, int usePrevious, - cv::Mat& velx, cv::Mat& vely) -{ - cv::Size sz((curr.cols - bSize.width + shiftSize.width)/shiftSize.width, (curr.rows - bSize.height + shiftSize.height)/shiftSize.height); - - velx.create(sz, CV_32FC1); - vely.create(sz, CV_32FC1); - - CvMat cvprev = prev; - CvMat cvcurr = curr; - - CvMat cvvelx = velx; - CvMat cvvely = vely; - - cvCalcOpticalFlowBM(&cvprev, &cvcurr, bSize, shiftSize, maxRange, usePrevious, &cvvelx, &cvvely); -} - -DEF_PARAM_TEST(ImagePair_BlockSize_ShiftSize_MaxRange, string_pair, cv::Size, cv::Size, cv::Size); - -GPU_PERF_TEST_P(ImagePair_BlockSize_ShiftSize_MaxRange, OpticalFlowBM, - testing::Combine( - testing::Values(string_pair("im1_1280x800.jpg", "im2_1280x800.jpg")), - testing::Values(cv::Size(16, 16)), - testing::Values(cv::Size(2, 2)), - testing::Values(cv::Size(16, 16)) - )) -{ - declare.time(3000); - - const string_pair fileNames = std::tr1::get<0>(GetParam()); - const cv::Size block_size = std::tr1::get<1>(GetParam()); - const cv::Size shift_size = std::tr1::get<2>(GetParam()); - const cv::Size max_range = std::tr1::get<3>(GetParam()); - - cv::Mat src1 = cv::imread(fileNames.first, cv::IMREAD_GRAYSCALE); - if (src1.empty()) - FAIL() << "Unable to load source image [" << fileNames.first << "]"; - - cv::Mat src2 = cv::imread(fileNames.second, cv::IMREAD_GRAYSCALE); - if (src2.empty()) - FAIL() << "Unable to load source image [" << fileNames.second << "]"; - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_velx, d_vely, buf; - - cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf); - - TEST_CYCLE_N(10) - { - cv::gpu::calcOpticalFlowBM(d_src1, d_src2, block_size, shift_size, max_range, false, d_velx, d_vely, buf); - } - } - else - { - cv::Mat velx, vely; - - calcOpticalFlowBM(src1, src2, block_size, shift_size, max_range, false, velx, vely); - - TEST_CYCLE_N(10) - { - calcOpticalFlowBM(src1, src2, block_size, shift_size, max_range, false, velx, vely); - } - } - - SANITY_CHECK(0); -} - -GPU_PERF_TEST_P(ImagePair_BlockSize_ShiftSize_MaxRange, FastOpticalFlowBM, - testing::Combine( - testing::Values(string_pair("im1_1280x800.jpg", "im2_1280x800.jpg")), - testing::Values(cv::Size(16, 16)), - testing::Values(cv::Size(1, 1)), - testing::Values(cv::Size(16, 16)) - )) -{ - declare.time(3000); - - const string_pair fileNames = std::tr1::get<0>(GetParam()); - const cv::Size block_size = std::tr1::get<1>(GetParam()); - const cv::Size shift_size = std::tr1::get<2>(GetParam()); - const cv::Size max_range = std::tr1::get<3>(GetParam()); - - cv::Mat src1 = cv::imread(fileNames.first, cv::IMREAD_GRAYSCALE); - if (src1.empty()) - FAIL() << "Unable to load source image [" << fileNames.first << "]"; - - cv::Mat src2 = cv::imread(fileNames.second, cv::IMREAD_GRAYSCALE); - if (src2.empty()) - FAIL() << "Unable to load source image [" << fileNames.second << "]"; - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_velx, d_vely; - - cv::gpu::FastOpticalFlowBM fastBM; - - fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width); - - TEST_CYCLE_N(10) - { - fastBM(d_src1, d_src2, d_velx, d_vely, max_range.width, block_size.width); - } - } - else - { - cv::Mat velx, vely; - - calcOpticalFlowBM(src1, src2, block_size, shift_size, max_range, false, velx, vely); - - TEST_CYCLE_N(10) - { - calcOpticalFlowBM(src1, src2, block_size, shift_size, max_range, false, velx, vely); - } - } - - SANITY_CHECK(0); -} diff --git a/modules/gpu/doc/calib3d.rst b/modules/gpu/doc/calib3d.rst new file mode 100644 index 0000000..faa6c0f --- /dev/null +++ b/modules/gpu/doc/calib3d.rst @@ -0,0 +1,36 @@ +Camera Calibration and 3D Reconstruction +======================================== + +.. highlight:: cpp + + + +gpu::solvePnPRansac +------------------- +Finds the object pose from 3D-2D point correspondences. + +.. ocv:function:: void gpu::solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat, const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false, int num_iters=100, float max_dist=8.0, int min_inlier_count=100, vector* inliers=NULL) + + :param object: Single-row matrix of object points. + + :param image: Single-row matrix of image points. + + :param camera_mat: 3x3 matrix of intrinsic camera parameters. + + :param dist_coef: Distortion coefficients. See :ocv:func:`undistortPoints` for details. + + :param rvec: Output 3D rotation vector. + + :param tvec: Output 3D translation vector. + + :param use_extrinsic_guess: Flag to indicate that the function must use ``rvec`` and ``tvec`` as an initial transformation guess. It is not supported for now. + + :param num_iters: Maximum number of RANSAC iterations. + + :param max_dist: Euclidean distance threshold to detect whether point is inlier or not. + + :param min_inlier_count: Flag to indicate that the function must stop if greater or equal number of inliers is achieved. It is not supported for now. + + :param inliers: Output vector of inlier indices. + +.. seealso:: :ocv:func:`solvePnPRansac` diff --git a/modules/gpu/doc/gpu.rst b/modules/gpu/doc/gpu.rst index b21e2ab..2a0358e 100644 --- a/modules/gpu/doc/gpu.rst +++ b/modules/gpu/doc/gpu.rst @@ -8,12 +8,5 @@ gpu. GPU-accelerated Computer Vision introduction initalization_and_information data_structures - operations_on_matrices - per_element_operations - image_processing - matrix_reductions object_detection - feature_detection_and_description - image_filtering - camera_calibration_and_3d_reconstruction - video + calib3d diff --git a/modules/gpu/doc/image_processing.rst b/modules/gpu/doc/image_processing.rst deleted file mode 100644 index 7b404c8..0000000 --- a/modules/gpu/doc/image_processing.rst +++ /dev/null @@ -1,1087 +0,0 @@ -Image Processing -================ - -.. highlight:: cpp - - - -gpu::meanShiftFiltering ---------------------------- -Performs mean-shift filtering for each point of the source image. - -.. ocv:function:: void gpu::meanShiftFiltering( const GpuMat& src, GpuMat& dst, int sp, int sr, TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1), Stream& stream=Stream::Null() ) - - :param src: Source image. Only ``CV_8UC4`` images are supported for now. - - :param dst: Destination image containing the color of mapped points. It has the same size and type as ``src`` . - - :param sp: Spatial window radius. - - :param sr: Color window radius. - - :param criteria: Termination criteria. See :ocv:class:`TermCriteria`. - -It maps each point of the source image into another point. As a result, you have a new color and new position of each point. - - - -gpu::meanShiftProc ----------------------- -Performs a mean-shift procedure and stores information about processed points (their colors and positions) in two images. - -.. ocv:function:: void gpu::meanShiftProc( const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr, TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1), Stream& stream=Stream::Null() ) - - :param src: Source image. Only ``CV_8UC4`` images are supported for now. - - :param dstr: Destination image containing the color of mapped points. The size and type is the same as ``src`` . - - :param dstsp: Destination image containing the position of mapped points. The size is the same as ``src`` size. The type is ``CV_16SC2`` . - - :param sp: Spatial window radius. - - :param sr: Color window radius. - - :param criteria: Termination criteria. See :ocv:class:`TermCriteria`. - -.. seealso:: :ocv:func:`gpu::meanShiftFiltering` - - - -gpu::meanShiftSegmentation ------------------------------- -Performs a mean-shift segmentation of the source image and eliminates small segments. - -.. ocv:function:: void gpu::meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize, TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1)) - - :param src: Source image. Only ``CV_8UC4`` images are supported for now. - - :param dst: Segmented image with the same size and type as ``src`` . - - :param sp: Spatial window radius. - - :param sr: Color window radius. - - :param minsize: Minimum segment size. Smaller segments are merged. - - :param criteria: Termination criteria. See :ocv:class:`TermCriteria`. - - - -gpu::integral ------------------ -Computes an integral image. - -.. ocv:function:: void gpu::integral(const GpuMat& src, GpuMat& sum, Stream& stream = Stream::Null()) - - :param src: Source image. Only ``CV_8UC1`` images are supported for now. - - :param sum: Integral image containing 32-bit unsigned integer values packed into ``CV_32SC1`` . - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`integral` - - - -gpu::sqrIntegral --------------------- -Computes a squared integral image. - -.. ocv:function:: void gpu::sqrIntegral(const GpuMat& src, GpuMat& sqsum, Stream& stream = Stream::Null()) - - :param src: Source image. Only ``CV_8UC1`` images are supported for now. - - :param sqsum: Squared integral image containing 64-bit unsigned integer values packed into ``CV_64FC1`` . - - :param stream: Stream for the asynchronous version. - - - -gpu::columnSum ------------------- -Computes a vertical (column) sum. - -.. ocv:function:: void gpu::columnSum(const GpuMat& src, GpuMat& sum) - - :param src: Source image. Only ``CV_32FC1`` images are supported for now. - - :param sum: Destination image of the ``CV_32FC1`` type. - - - -gpu::cornerHarris ---------------------- -Computes the Harris cornerness criteria at each image pixel. - -.. ocv:function:: void gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101) - - :param src: Source image. Only ``CV_8UC1`` and ``CV_32FC1`` images are supported for now. - - :param dst: Destination image containing cornerness values. It has the same size as ``src`` and ``CV_32FC1`` type. - - :param blockSize: Neighborhood size. - - :param ksize: Aperture parameter for the Sobel operator. - - :param k: Harris detector free parameter. - - :param borderType: Pixel extrapolation method. Only ``BORDER_REFLECT101`` and ``BORDER_REPLICATE`` are supported for now. - -.. seealso:: :ocv:func:`cornerHarris` - - - -gpu::cornerMinEigenVal --------------------------- -Computes the minimum eigen value of a 2x2 derivative covariation matrix at each pixel (the cornerness criteria). - -.. ocv:function:: void gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101) - -.. ocv:function:: void gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType=BORDER_REFLECT101) - -.. ocv:function:: void gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null()) - - :param src: Source image. Only ``CV_8UC1`` and ``CV_32FC1`` images are supported for now. - - :param dst: Destination image containing cornerness values. The size is the same. The type is ``CV_32FC1`` . - - :param blockSize: Neighborhood size. - - :param ksize: Aperture parameter for the Sobel operator. - - :param borderType: Pixel extrapolation method. Only ``BORDER_REFLECT101`` and ``BORDER_REPLICATE`` are supported for now. - -.. seealso:: :ocv:func:`cornerMinEigenVal` - - - -gpu::mulSpectrums ---------------------- -Performs a per-element multiplication of two Fourier spectrums. - -.. ocv:function:: void gpu::mulSpectrums( const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false, Stream& stream=Stream::Null() ) - - :param a: First spectrum. - - :param b: Second spectrum with the same size and type as ``a`` . - - :param c: Destination spectrum. - - :param flags: Mock parameter used for CPU/GPU interfaces similarity. - - :param conjB: Optional flag to specify if the second spectrum needs to be conjugated before the multiplication. - - Only full (not packed) ``CV_32FC2`` complex spectrums in the interleaved format are supported for now. - -.. seealso:: :ocv:func:`mulSpectrums` - - - -gpu::mulAndScaleSpectrums ------------------------------ -Performs a per-element multiplication of two Fourier spectrums and scales the result. - -.. ocv:function:: void gpu::mulAndScaleSpectrums( const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false, Stream& stream=Stream::Null() ) - - :param a: First spectrum. - - :param b: Second spectrum with the same size and type as ``a`` . - - :param c: Destination spectrum. - - :param flags: Mock parameter used for CPU/GPU interfaces similarity. - - :param scale: Scale constant. - - :param conjB: Optional flag to specify if the second spectrum needs to be conjugated before the multiplication. - - Only full (not packed) ``CV_32FC2`` complex spectrums in the interleaved format are supported for now. - -.. seealso:: :ocv:func:`mulSpectrums` - - - -gpu::dft ------------- -Performs a forward or inverse discrete Fourier transform (1D or 2D) of the floating point matrix. - -.. ocv:function:: void gpu::dft( const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0, Stream& stream=Stream::Null() ) - - :param src: Source matrix (real or complex). - - :param dst: Destination matrix (real or complex). - - :param dft_size: Size of a discrete Fourier transform. - - :param flags: Optional flags: - - * **DFT_ROWS** transforms each individual row of the source matrix. - - * **DFT_SCALE** scales the result: divide it by the number of elements in the transform (obtained from ``dft_size`` ). - - * **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real cases are always forward and inverse, respectively). - - * **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of real-complex transform, so the destination matrix must be real. - -Use to handle real matrices ( ``CV32FC1`` ) and complex matrices in the interleaved format ( ``CV32FC2`` ). - -The source matrix should be continuous, otherwise reallocation and data copying is performed. The function chooses an operation mode depending on the flags, size, and channel count of the source matrix: - - * If the source matrix is complex and the output is not specified as real, the destination matrix is complex and has the ``dft_size`` size and ``CV_32FC2`` type. The destination matrix contains a full result of the DFT (forward or inverse). - - * If the source matrix is complex and the output is specified as real, the function assumes that its input is the result of the forward transform (see the next item). The destination matrix has the ``dft_size`` size and ``CV_32FC1`` type. It contains the result of the inverse DFT. - - * If the source matrix is real (its type is ``CV_32FC1`` ), forward DFT is performed. The result of the DFT is packed into complex ( ``CV_32FC2`` ) matrix. So, the width of the destination matrix is ``dft_size.width / 2 + 1`` . But if the source is a single column, the height is reduced instead of the width. - -.. seealso:: :ocv:func:`dft` - - -gpu::ConvolveBuf ----------------- -.. ocv:struct:: gpu::ConvolveBuf - -Class providing a memory buffer for :ocv:func:`gpu::convolve` function, plus it allows to adjust some specific parameters. :: - - struct CV_EXPORTS ConvolveBuf - { - Size result_size; - Size block_size; - Size user_block_size; - Size dft_size; - int spect_len; - - GpuMat image_spect, templ_spect, result_spect; - GpuMat image_block, templ_block, result_data; - - void create(Size image_size, Size templ_size); - static Size estimateBlockSize(Size result_size, Size templ_size); - }; - -You can use field `user_block_size` to set specific block size for :ocv:func:`gpu::convolve` function. If you leave its default value `Size(0,0)` then automatic estimation of block size will be used (which is optimized for speed). By varying `user_block_size` you can reduce memory requirements at the cost of speed. - -gpu::ConvolveBuf::create ------------------------- -.. ocv:function:: gpu::ConvolveBuf::create(Size image_size, Size templ_size) - -Constructs a buffer for :ocv:func:`gpu::convolve` function with respective arguments. - - -gpu::convolve ------------------ -Computes a convolution (or cross-correlation) of two images. - -.. ocv:function:: void gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr=false) - -.. ocv:function:: void gpu::convolve( const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf, Stream& stream=Stream::Null() ) - - :param image: Source image. Only ``CV_32FC1`` images are supported for now. - - :param templ: Template image. The size is not greater than the ``image`` size. The type is the same as ``image`` . - - :param result: Result image. If ``image`` is *W x H* and ``templ`` is *w x h*, then ``result`` must be *W-w+1 x H-h+1*. - - :param ccorr: Flags to evaluate cross-correlation instead of convolution. - - :param buf: Optional buffer to avoid extra memory allocations and to adjust some specific parameters. See :ocv:struct:`gpu::ConvolveBuf`. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`gpu::filter2D` - -gpu::MatchTemplateBuf ---------------------- -.. ocv:struct:: gpu::MatchTemplateBuf - -Class providing memory buffers for :ocv:func:`gpu::matchTemplate` function, plus it allows to adjust some specific parameters. :: - - struct CV_EXPORTS MatchTemplateBuf - { - Size user_block_size; - GpuMat imagef, templf; - std::vector images; - std::vector image_sums; - std::vector image_sqsums; - }; - -You can use field `user_block_size` to set specific block size for :ocv:func:`gpu::matchTemplate` function. If you leave its default value `Size(0,0)` then automatic estimation of block size will be used (which is optimized for speed). By varying `user_block_size` you can reduce memory requirements at the cost of speed. - -gpu::matchTemplate ----------------------- -Computes a proximity map for a raster template and an image where the template is searched for. - -.. ocv:function:: void gpu::matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, Stream &stream = Stream::Null()) - -.. ocv:function:: void gpu::matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, MatchTemplateBuf &buf, Stream& stream = Stream::Null()) - - :param image: Source image. ``CV_32F`` and ``CV_8U`` depth images (1..4 channels) are supported for now. - - :param templ: Template image with the size and type the same as ``image`` . - - :param result: Map containing comparison results ( ``CV_32FC1`` ). If ``image`` is *W x H* and ``templ`` is *w x h*, then ``result`` must be *W-w+1 x H-h+1*. - - :param method: Specifies the way to compare the template with the image. - - :param buf: Optional buffer to avoid extra memory allocations and to adjust some specific parameters. See :ocv:struct:`gpu::MatchTemplateBuf`. - - :param stream: Stream for the asynchronous version. - - The following methods are supported for the ``CV_8U`` depth images for now: - - * ``CV_TM_SQDIFF`` - * ``CV_TM_SQDIFF_NORMED`` - * ``CV_TM_CCORR`` - * ``CV_TM_CCORR_NORMED`` - * ``CV_TM_CCOEFF`` - * ``CV_TM_CCOEFF_NORMED`` - - The following methods are supported for the ``CV_32F`` images for now: - - * ``CV_TM_SQDIFF`` - * ``CV_TM_CCORR`` - -.. seealso:: :ocv:func:`matchTemplate` - - -gpu::remap --------------- -Applies a generic geometrical transformation to an image. - -.. ocv:function:: void gpu::remap( const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() ) - - :param src: Source image. - - :param dst: Destination image with the size the same as ``xmap`` and the type the same as ``src`` . - - :param xmap: X values. Only ``CV_32FC1`` type is supported. - - :param ymap: Y values. Only ``CV_32FC1`` type is supported. - - :param interpolation: Interpolation method (see :ocv:func:`resize` ). ``INTER_NEAREST`` , ``INTER_LINEAR`` and ``INTER_CUBIC`` are supported for now. - - :param borderMode: Pixel extrapolation method (see :ocv:func:`borderInterpolate` ). ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. - - :param borderValue: Value used in case of a constant border. By default, it is 0. - - :param stream: Stream for the asynchronous version. - -The function transforms the source image using the specified map: - -.. math:: - - \texttt{dst} (x,y) = \texttt{src} (xmap(x,y), ymap(x,y)) - -Values of pixels with non-integer coordinates are computed using the bilinear interpolation. - -.. seealso:: :ocv:func:`remap` - - - -gpu::cvtColor ------------------ -Converts an image from one color space to another. - -.. ocv:function:: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0, Stream& stream = Stream::Null()) - - :param src: Source image with ``CV_8U`` , ``CV_16U`` , or ``CV_32F`` depth and 1, 3, or 4 channels. - - :param dst: Destination image with the same size and depth as ``src`` . - - :param code: Color space conversion code. For details, see :ocv:func:`cvtColor` . Conversion to/from Luv and Bayer color spaces is not supported. - - :param dcn: Number of channels in the destination image. If the parameter is 0, the number of the channels is derived automatically from ``src`` and the ``code`` . - - :param stream: Stream for the asynchronous version. - -3-channel color spaces (like ``HSV``, ``XYZ``, and so on) can be stored in a 4-channel image for better performance. - -.. seealso:: :ocv:func:`cvtColor` - - - -gpu::swapChannels ------------------ -Exchanges the color channels of an image in-place. - -.. ocv:function:: void gpu::swapChannels(GpuMat& image, const int dstOrder[4], Stream& stream = Stream::Null()) - - :param image: Source image. Supports only ``CV_8UC4`` type. - - :param dstOrder: Integer array describing how channel values are permutated. The n-th entry of the array contains the number of the channel that is stored in the n-th channel of the output image. E.g. Given an RGBA image, aDstOrder = [3,2,1,0] converts this to ABGR channel order. - - :param stream: Stream for the asynchronous version. - -The methods support arbitrary permutations of the original channels, including replication. - - - -gpu::threshold ------------------- -Applies a fixed-level threshold to each array element. - -.. ocv:function:: double gpu::threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, Stream& stream = Stream::Null()) - - :param src: Source array (single-channel). - - :param dst: Destination array with the same size and type as ``src`` . - - :param thresh: Threshold value. - - :param maxval: Maximum value to use with ``THRESH_BINARY`` and ``THRESH_BINARY_INV`` threshold types. - - :param type: Threshold type. For details, see :ocv:func:`threshold` . The ``THRESH_OTSU`` threshold type is not supported. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`threshold` - - - -gpu::resize ---------------- -Resizes an image. - -.. ocv:function:: void gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image with the same type as ``src`` . The size is ``dsize`` (when it is non-zero) or the size is computed from ``src.size()`` , ``fx`` , and ``fy`` . - - :param dsize: Destination image size. If it is zero, it is computed as: - - .. math:: - \texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))} - - Either ``dsize`` or both ``fx`` and ``fy`` must be non-zero. - - :param fx: Scale factor along the horizontal axis. If it is zero, it is computed as: - - .. math:: - - \texttt{(double)dsize.width/src.cols} - - :param fy: Scale factor along the vertical axis. If it is zero, it is computed as: - - .. math:: - - \texttt{(double)dsize.height/src.rows} - - :param interpolation: Interpolation method. ``INTER_NEAREST`` , ``INTER_LINEAR`` and ``INTER_CUBIC`` are supported for now. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`resize` - - - -gpu::warpAffine -------------------- -Applies an affine transformation to an image. - -.. ocv:function:: void gpu::warpAffine( const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() ) - - :param src: Source image. ``CV_8U`` , ``CV_16U`` , ``CV_32S`` , or ``CV_32F`` depth and 1, 3, or 4 channels are supported. - - :param dst: Destination image with the same type as ``src`` . The size is ``dsize`` . - - :param M: *2x3* transformation matrix. - - :param dsize: Size of the destination image. - - :param flags: Combination of interpolation methods (see :ocv:func:`resize`) and the optional flag ``WARP_INVERSE_MAP`` specifying that ``M`` is an inverse transformation ( ``dst=>src`` ). Only ``INTER_NEAREST`` , ``INTER_LINEAR`` , and ``INTER_CUBIC`` interpolation methods are supported. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`warpAffine` - - - -gpu::buildWarpAffineMaps ------------------------- -Builds transformation maps for affine transformation. - -.. ocv:function:: void gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null()) - - :param M: *2x3* transformation matrix. - - :param inverse: Flag specifying that ``M`` is an inverse transformation ( ``dst=>src`` ). - - :param dsize: Size of the destination image. - - :param xmap: X values with ``CV_32FC1`` type. - - :param ymap: Y values with ``CV_32FC1`` type. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`gpu::warpAffine` , :ocv:func:`gpu::remap` - - - -gpu::warpPerspective ------------------------- -Applies a perspective transformation to an image. - -.. ocv:function:: void gpu::warpPerspective( const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, Scalar borderValue=Scalar(), Stream& stream=Stream::Null() ) - - :param src: Source image. ``CV_8U`` , ``CV_16U`` , ``CV_32S`` , or ``CV_32F`` depth and 1, 3, or 4 channels are supported. - - :param dst: Destination image with the same type as ``src`` . The size is ``dsize`` . - - :param M: *3x3* transformation matrix. - - :param dsize: Size of the destination image. - - :param flags: Combination of interpolation methods (see :ocv:func:`resize` ) and the optional flag ``WARP_INVERSE_MAP`` specifying that ``M`` is the inverse transformation ( ``dst => src`` ). Only ``INTER_NEAREST`` , ``INTER_LINEAR`` , and ``INTER_CUBIC`` interpolation methods are supported. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`warpPerspective` - - - -gpu::buildWarpPerspectiveMaps ------------------------------ -Builds transformation maps for perspective transformation. - -.. ocv:function:: void gpu::buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null()) - - :param M: *3x3* transformation matrix. - - :param inverse: Flag specifying that ``M`` is an inverse transformation ( ``dst=>src`` ). - - :param dsize: Size of the destination image. - - :param xmap: X values with ``CV_32FC1`` type. - - :param ymap: Y values with ``CV_32FC1`` type. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`gpu::warpPerspective` , :ocv:func:`gpu::remap` - - - -gpu::rotate ---------------- -Rotates an image around the origin (0,0) and then shifts it. - -.. ocv:function:: void gpu::rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()) - - :param src: Source image. Supports 1, 3 or 4 channels images with ``CV_8U`` , ``CV_16U`` or ``CV_32F`` depth. - - :param dst: Destination image with the same type as ``src`` . The size is ``dsize`` . - - :param dsize: Size of the destination image. - - :param angle: Angle of rotation in degrees. - - :param xShift: Shift along the horizontal axis. - - :param yShift: Shift along the vertical axis. - - :param interpolation: Interpolation method. Only ``INTER_NEAREST`` , ``INTER_LINEAR`` , and ``INTER_CUBIC`` are supported. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`gpu::warpAffine` - - - -gpu::copyMakeBorder ------------------------ -Forms a border around an image. - -.. ocv:function:: void gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType, const Scalar& value = Scalar(), Stream& stream = Stream::Null()) - - :param src: Source image. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` types are supported. - - :param dst: Destination image with the same type as ``src``. The size is ``Size(src.cols+left+right, src.rows+top+bottom)`` . - - :param top: - - :param bottom: - - :param left: - - :param right: Number of pixels in each direction from the source image rectangle to extrapolate. For example: ``top=1, bottom=1, left=1, right=1`` mean that 1 pixel-wide border needs to be built. - - :param borderType: Border type. See :ocv:func:`borderInterpolate` for details. ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. - - :param value: Border value. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`copyMakeBorder` - - - -gpu::rectStdDev -------------------- -Computes a standard deviation of integral images. - -.. ocv:function:: void gpu::rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect, Stream& stream = Stream::Null()) - - :param src: Source image. Only the ``CV_32SC1`` type is supported. - - :param sqr: Squared source image. Only the ``CV_32FC1`` type is supported. - - :param dst: Destination image with the same type and size as ``src`` . - - :param rect: Rectangular window. - - :param stream: Stream for the asynchronous version. - - - -gpu::evenLevels -------------------- -Computes levels with even distribution. - -.. ocv:function:: void gpu::evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel) - - :param levels: Destination array. ``levels`` has 1 row, ``nLevels`` columns, and the ``CV_32SC1`` type. - - :param nLevels: Number of computed levels. ``nLevels`` must be at least 2. - - :param lowerLevel: Lower boundary value of the lowest level. - - :param upperLevel: Upper boundary value of the greatest level. - - - -gpu::histEven ------------------ -Calculates a histogram with evenly distributed bins. - -.. ocv:function:: void gpu::histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::histEven(const GpuMat& src, GpuMat& hist, GpuMat& buf, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::histEven( const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream=Stream::Null() ) - -.. ocv:function:: void gpu::histEven( const GpuMat& src, GpuMat hist[4], GpuMat& buf, int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream=Stream::Null() ) - - :param src: Source image. ``CV_8U``, ``CV_16U``, or ``CV_16S`` depth and 1 or 4 channels are supported. For a four-channel image, all channels are processed separately. - - :param hist: Destination histogram with one row, ``histSize`` columns, and the ``CV_32S`` type. - - :param histSize: Size of the histogram. - - :param lowerLevel: Lower boundary of lowest-level bin. - - :param upperLevel: Upper boundary of highest-level bin. - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - - :param stream: Stream for the asynchronous version. - - - -gpu::histRange ------------------- -Calculates a histogram with bins determined by the ``levels`` array. - -.. ocv:function:: void gpu::histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, GpuMat& buf, Stream& stream = Stream::Null()) - - :param src: Source image. ``CV_8U`` , ``CV_16U`` , or ``CV_16S`` depth and 1 or 4 channels are supported. For a four-channel image, all channels are processed separately. - - :param hist: Destination histogram with one row, ``(levels.cols-1)`` columns, and the ``CV_32SC1`` type. - - :param levels: Number of levels in the histogram. - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - - :param stream: Stream for the asynchronous version. - - - -gpu::calcHist ------------------- -Calculates histogram for one channel 8-bit image. - -.. ocv:function:: void gpu::calcHist(const GpuMat& src, GpuMat& hist, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param hist: Destination histogram with one row, 256 columns, and the ``CV_32SC1`` type. - - :param stream: Stream for the asynchronous version. - - - -gpu::equalizeHist ------------------- -Equalizes the histogram of a grayscale image. - -.. ocv:function:: void gpu::equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image. - - :param hist: Destination histogram with one row, 256 columns, and the ``CV_32SC1`` type. - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`equalizeHist` - - - -gpu::buildWarpPlaneMaps ------------------------ -Builds plane warping maps. - -.. ocv:function:: void gpu::buildWarpPlaneMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, const Mat & T, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() ) - - :param stream: Stream for the asynchronous version. - - - -gpu::buildWarpCylindricalMaps ------------------------------ -Builds cylindrical warping maps. - -.. ocv:function:: void gpu::buildWarpCylindricalMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() ) - - :param stream: Stream for the asynchronous version. - - - -gpu::buildWarpSphericalMaps ---------------------------- -Builds spherical warping maps. - -.. ocv:function:: void gpu::buildWarpSphericalMaps( Size src_size, Rect dst_roi, const Mat & K, const Mat& R, float scale, GpuMat& map_x, GpuMat& map_y, Stream& stream=Stream::Null() ) - - :param stream: Stream for the asynchronous version. - - - -gpu::pyrDown -------------------- -Smoothes an image and downsamples it. - -.. ocv:function:: void gpu::pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image. Will have ``Size((src.cols+1)/2, (src.rows+1)/2)`` size and the same type as ``src`` . - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`pyrDown` - - - -gpu::pyrUp -------------------- -Upsamples an image and then smoothes it. - -.. ocv:function:: void gpu::pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image. Will have ``Size(src.cols*2, src.rows*2)`` size and the same type as ``src`` . - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`pyrUp` - - - -gpu::blendLinear -------------------- -Performs linear blending of two images. - -.. ocv:function:: void gpu::blendLinear(const GpuMat& img1, const GpuMat& img2, const GpuMat& weights1, const GpuMat& weights2, GpuMat& result, Stream& stream = Stream::Null()) - - :param img1: First image. Supports only ``CV_8U`` and ``CV_32F`` depth. - - :param img2: Second image. Must have the same size and the same type as ``img1`` . - - :param weights1: Weights for first image. Must have tha same size as ``img1`` . Supports only ``CV_32F`` type. - - :param weights2: Weights for second image. Must have tha same size as ``img2`` . Supports only ``CV_32F`` type. - - :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=BORDER_DEFAULT, 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 gpu::nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null()) - - :param src: Source image. Supports only CV_8UC1, CV_8UC2 and CV_8UC3. - - :param dst: Destination image. - - :param h: Filter sigma regulating filter strength for color. - - :param search_window: 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::FastNonLocalMeansDenoising -------------------------------- -.. ocv:class:: gpu::FastNonLocalMeansDenoising - - :: - - class FastNonLocalMeansDenoising - { - public: - //! Simple method, recommended for grayscale images (though it supports multichannel images) - void simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) - //! Processes luminance and color components separatelly - void labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) - }; - -The class implements fast approximate Non Local Means Denoising algorithm. - -gpu::FastNonLocalMeansDenoising::simpleMethod() ------------------------------------------------ -Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising with several computational optimizations. Noise expected to be a gaussian white noise - -.. ocv:function:: void gpu::FastNonLocalMeansDenoising::simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) - - :param src: Input 8-bit 1-channel, 2-channel or 3-channel image. - - :param dst: Output image with the same size and type as ``src`` . - - :param h: Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise - - :param search_window: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels - - :param block_size: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels - - :param stream: Stream for the asynchronous invocations. - -This function expected to be applied to grayscale images. For colored images look at ``FastNonLocalMeansDenoising::labMethod``. - -.. seealso:: - - :ocv:func:`fastNlMeansDenoising` - -gpu::FastNonLocalMeansDenoising::labMethod() --------------------------------------------- -Modification of ``FastNonLocalMeansDenoising::simpleMethod`` for color images - -.. ocv:function:: void gpu::FastNonLocalMeansDenoising::labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) - - :param src: Input 8-bit 3-channel image. - - :param dst: Output image with the same size and type as ``src`` . - - :param h_luminance: Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise - - :param float: The same as h but for color components. For most images value equals 10 will be enought to remove colored noise and do not distort colors - - :param search_window: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels - - :param block_size: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels - - :param stream: Stream for the asynchronous invocations. - -The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``FastNonLocalMeansDenoising::simpleMethod`` function. - -.. seealso:: - - :ocv:func:`fastNlMeansDenoisingColored` - -gpu::alphaComp -------------------- -Composites two images using alpha opacity values contained in each image. - -.. ocv:function:: void gpu::alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream = Stream::Null()) - - :param img1: First image. Supports ``CV_8UC4`` , ``CV_16UC4`` , ``CV_32SC4`` and ``CV_32FC4`` types. - - :param img2: Second image. Must have the same size and the same type as ``img1`` . - - :param dst: Destination image. - - :param alpha_op: Flag specifying the alpha-blending operation: - - * **ALPHA_OVER** - * **ALPHA_IN** - * **ALPHA_OUT** - * **ALPHA_ATOP** - * **ALPHA_XOR** - * **ALPHA_PLUS** - * **ALPHA_OVER_PREMUL** - * **ALPHA_IN_PREMUL** - * **ALPHA_OUT_PREMUL** - * **ALPHA_ATOP_PREMUL** - * **ALPHA_XOR_PREMUL** - * **ALPHA_PLUS_PREMUL** - * **ALPHA_PREMUL** - - :param stream: Stream for the asynchronous version. - - - -gpu::Canny -------------------- -Finds edges in an image using the [Canny86]_ algorithm. - -.. ocv:function:: void gpu::Canny(const GpuMat& image, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false) - -.. ocv:function:: void gpu::Canny(const GpuMat& image, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false) - -.. ocv:function:: void gpu::Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false) - -.. ocv:function:: void gpu::Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false) - - :param image: Single-channel 8-bit input image. - - :param dx: First derivative of image in the vertical direction. Support only ``CV_32S`` type. - - :param dy: First derivative of image in the horizontal direction. Support only ``CV_32S`` type. - - :param edges: Output edge map. It has the same size and type as ``image`` . - - :param low_thresh: First threshold for the hysteresis procedure. - - :param high_thresh: Second threshold for the hysteresis procedure. - - :param apperture_size: Aperture size for the :ocv:func:`Sobel` operator. - - :param L2gradient: Flag indicating whether a more accurate :math:`L_2` norm :math:`=\sqrt{(dI/dx)^2 + (dI/dy)^2}` should be used to compute the image gradient magnitude ( ``L2gradient=true`` ), or a faster default :math:`L_1` norm :math:`=|dI/dx|+|dI/dy|` is enough ( ``L2gradient=false`` ). - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - -.. seealso:: :ocv:func:`Canny` - - - -gpu::HoughLines ---------------- -Finds lines in a binary image using the classical Hough transform. - -.. ocv:function:: void gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096) - -.. ocv:function:: void gpu::HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096) - - :param src: 8-bit, single-channel binary source image. - - :param lines: Output vector of lines. Each line is represented by a two-element vector :math:`(\rho, \theta)` . :math:`\rho` is the distance from the coordinate origin :math:`(0,0)` (top-left corner of the image). :math:`\theta` is the line rotation angle in radians ( :math:`0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}` ). - - :param rho: Distance resolution of the accumulator in pixels. - - :param theta: Angle resolution of the accumulator in radians. - - :param threshold: Accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` ). - - :param doSort: Performs lines sort by votes. - - :param maxLines: Maximum number of output lines. - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - -.. seealso:: :ocv:func:`HoughLines` - - - -gpu::HoughLinesDownload ------------------------ -Downloads results from :ocv:func:`gpu::HoughLines` to host memory. - -.. ocv:function:: void gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray()) - - :param d_lines: Result of :ocv:func:`gpu::HoughLines` . - - :param h_lines: Output host array. - - :param h_votes: Optional output array for line's votes. - -.. seealso:: :ocv:func:`gpu::HoughLines` - - - -gpu::HoughCircles ------------------ -Finds circles in a grayscale image using the Hough transform. - -.. ocv:function:: void gpu::HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096) - -.. ocv:function:: void gpu::HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096) - - :param src: 8-bit, single-channel grayscale input image. - - :param circles: Output vector of found circles. Each vector is encoded as a 3-element floating-point vector :math:`(x, y, radius)` . - - :param method: Detection method to use. Currently, the only implemented method is ``CV_HOUGH_GRADIENT`` , which is basically *21HT* , described in [Yuen90]_. - - :param dp: Inverse ratio of the accumulator resolution to the image resolution. For example, if ``dp=1`` , the accumulator has the same resolution as the input image. If ``dp=2`` , the accumulator has half as big width and height. - - :param minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed. - - :param cannyThreshold: The higher threshold of the two passed to the :ocv:func:`gpu::Canny` edge detector (the lower one is twice smaller). - - :param votesThreshold: The accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. - - :param minRadius: Minimum circle radius. - - :param maxRadius: Maximum circle radius. - - :param maxCircles: Maximum number of output circles. - - :param buf: Optional buffer to avoid extra memory allocations (for many calls with the same sizes). - -.. seealso:: :ocv:func:`HoughCircles` - - - -gpu::HoughCirclesDownload -------------------------- -Downloads results from :ocv:func:`gpu::HoughCircles` to host memory. - -.. ocv:function:: void gpu::HoughCirclesDownload(const GpuMat& d_circles, OutputArray h_circles) - - :param d_circles: Result of :ocv:func:`gpu::HoughCircles` . - - :param h_circles: Output host array. - -.. seealso:: :ocv:func:`gpu::HoughCircles` diff --git a/modules/gpu/doc/operations_on_matrices.rst b/modules/gpu/doc/operations_on_matrices.rst deleted file mode 100644 index d1762f4..0000000 --- a/modules/gpu/doc/operations_on_matrices.rst +++ /dev/null @@ -1,274 +0,0 @@ -Operations on Matrices -====================== - -.. highlight:: cpp - - - -gpu::gemm ------------------- -Performs generalized matrix multiplication. - -.. ocv:function:: void gpu::gemm(const GpuMat& src1, const GpuMat& src2, double alpha, const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null()) - - :param src1: First multiplied input matrix that should have ``CV_32FC1`` , ``CV_64FC1`` , ``CV_32FC2`` , or ``CV_64FC2`` type. - - :param src2: Second multiplied input matrix of the same type as ``src1`` . - - :param alpha: Weight of the matrix product. - - :param src3: Third optional delta matrix added to the matrix product. It should have the same type as ``src1`` and ``src2`` . - - :param beta: Weight of ``src3`` . - - :param dst: Destination matrix. It has the proper size and the same type as input matrices. - - :param flags: Operation flags: - - * **GEMM_1_T** transpose ``src1`` - * **GEMM_2_T** transpose ``src2`` - * **GEMM_3_T** transpose ``src3`` - - :param stream: Stream for the asynchronous version. - -The function performs generalized matrix multiplication similar to the ``gemm`` functions in BLAS level 3. For example, ``gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`` corresponds to - -.. math:: - - \texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T - -.. note:: Transposition operation doesn't support ``CV_64FC2`` input type. - -.. seealso:: :ocv:func:`gemm` - - - -gpu::transpose ------------------- -Transposes a matrix. - -.. ocv:function:: void gpu::transpose( const GpuMat& src1, GpuMat& dst, Stream& stream=Stream::Null() ) - - :param src1: Source matrix. 1-, 4-, 8-byte element sizes are supported for now (CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, etc). - - :param dst: Destination matrix. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`transpose` - - - -gpu::flip -------------- -Flips a 2D matrix around vertical, horizontal, or both axes. - -.. ocv:function:: void gpu::flip( const GpuMat& a, GpuMat& b, int flipCode, Stream& stream=Stream::Null() ) - - :param a: Source matrix. Supports 1, 3 and 4 channels images with ``CV_8U``, ``CV_16U``, ``CV_32S`` or ``CV_32F`` depth. - - :param b: Destination matrix. - - :param flipCode: Flip mode for the source: - - * ``0`` Flips around x-axis. - - * ``>0`` Flips around y-axis. - - * ``<0`` Flips around both axes. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`flip` - - - -gpu::LUT ------------- -Transforms the source matrix into the destination matrix using the given look-up table: ``dst(I) = lut(src(I))`` - -.. ocv:function:: void gpu::LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Source matrix. ``CV_8UC1`` and ``CV_8UC3`` matrices are supported for now. - - :param lut: Look-up table of 256 elements. It is a continuous ``CV_8U`` matrix. - - :param dst: Destination matrix with the same depth as ``lut`` and the same number of channels as ``src`` . - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`LUT` - - - -gpu::merge --------------- -Makes a multi-channel matrix out of several single-channel matrices. - -.. ocv:function:: void gpu::merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::merge(const vector& src, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Array/vector of source matrices. - - :param n: Number of source matrices. - - :param dst: Destination matrix. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`merge` - - - -gpu::split --------------- -Copies each plane of a multi-channel matrix into an array. - -.. ocv:function:: void gpu::split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null()) - -.. ocv:function:: void gpu::split(const GpuMat& src, vector& dst, Stream& stream = Stream::Null()) - - :param src: Source matrix. - - :param dst: Destination array/vector of single-channel matrices. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`split` - - - -gpu::magnitude ------------------- -Computes magnitudes of complex matrix elements. - -.. ocv:function:: void gpu::magnitude( const GpuMat& xy, GpuMat& magnitude, Stream& stream=Stream::Null() ) - -.. ocv:function:: void gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null()) - - :param xy: Source complex matrix in the interleaved format ( ``CV_32FC2`` ). - - :param x: Source matrix containing real components ( ``CV_32FC1`` ). - - :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ). - - :param magnitude: Destination matrix of float magnitudes ( ``CV_32FC1`` ). - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`magnitude` - - - -gpu::magnitudeSqr ---------------------- -Computes squared magnitudes of complex matrix elements. - -.. ocv:function:: void gpu::magnitudeSqr( const GpuMat& xy, GpuMat& magnitude, Stream& stream=Stream::Null() ) - -.. ocv:function:: void gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null()) - - :param xy: Source complex matrix in the interleaved format ( ``CV_32FC2`` ). - - :param x: Source matrix containing real components ( ``CV_32FC1`` ). - - :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ). - - :param magnitude: Destination matrix of float magnitude squares ( ``CV_32FC1`` ). - - :param stream: Stream for the asynchronous version. - - - -gpu::phase --------------- -Computes polar angles of complex matrix elements. - -.. ocv:function:: void gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees=false, Stream& stream = Stream::Null()) - - :param x: Source matrix containing real components ( ``CV_32FC1`` ). - - :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ). - - :param angle: Destination matrix of angles ( ``CV_32FC1`` ). - - :param angleInDegrees: Flag for angles that must be evaluated in degrees. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`phase` - - - -gpu::cartToPolar --------------------- -Converts Cartesian coordinates into polar. - -.. ocv:function:: void gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees=false, Stream& stream = Stream::Null()) - - :param x: Source matrix containing real components ( ``CV_32FC1`` ). - - :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ). - - :param magnitude: Destination matrix of float magnitudes ( ``CV_32FC1`` ). - - :param angle: Destination matrix of angles ( ``CV_32FC1`` ). - - :param angleInDegrees: Flag for angles that must be evaluated in degrees. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`cartToPolar` - - - -gpu::polarToCart --------------------- -Converts polar coordinates into Cartesian. - -.. ocv:function:: void gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees=false, Stream& stream = Stream::Null()) - - :param magnitude: Source matrix containing magnitudes ( ``CV_32FC1`` ). - - :param angle: Source matrix containing angles ( ``CV_32FC1`` ). - - :param x: Destination matrix of real components ( ``CV_32FC1`` ). - - :param y: Destination matrix of imaginary components ( ``CV_32FC1`` ). - - :param angleInDegrees: Flag that indicates angles in degrees. - - :param stream: Stream for the asynchronous version. - -.. seealso:: :ocv:func:`polarToCart` - - - -gpu::normalize --------------- -Normalizes the norm or value range of an array. - -.. ocv:function:: void gpu::normalize(const GpuMat& src, GpuMat& dst, double alpha = 1, double beta = 0, int norm_type = NORM_L2, int dtype = -1, const GpuMat& mask = GpuMat()) - -.. ocv:function:: void gpu::normalize(const GpuMat& src, GpuMat& dst, double a, double b, int norm_type, int dtype, const GpuMat& mask, GpuMat& norm_buf, GpuMat& cvt_buf) - - :param src: input array. - - :param dst: output array of the same size as ``src`` . - - :param alpha: norm value to normalize to or the lower range boundary in case of the range normalization. - - :param beta: upper range boundary in case of the range normalization; it is not used for the norm normalization. - - :param normType: normalization type (see the details below). - - :param dtype: when negative, the output array has the same type as ``src``; otherwise, it has the same number of channels as ``src`` and the depth ``=CV_MAT_DEPTH(dtype)``. - - :param mask: optional operation mask. - - :param norm_buf: Optional buffer to avoid extra memory allocations. It is resized automatically. - - :param cvt_buf: Optional buffer to avoid extra memory allocations. It is resized automatically. - -.. seealso:: :ocv:func:`normalize` diff --git a/modules/gpu/doc/video.rst b/modules/gpu/doc/video.rst deleted file mode 100644 index f964100..0000000 --- a/modules/gpu/doc/video.rst +++ /dev/null @@ -1,1142 +0,0 @@ -Video Analysis -============== - -.. highlight:: cpp - - - -gpu::BroxOpticalFlow --------------------- -.. ocv:class:: gpu::BroxOpticalFlow - -Class computing the optical flow for two images using Brox et al Optical Flow algorithm ([Brox2004]_). :: - - class BroxOpticalFlow - { - public: - BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_); - - //! Compute optical flow - //! frame0 - source frame (supports only CV_32FC1 type) - //! frame1 - frame to track (with the same size and type as frame0) - //! u - flow horizontal component (along x axis) - //! v - flow vertical component (along y axis) - void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); - - //! flow smoothness - float alpha; - - //! gradient constancy importance - float gamma; - - //! pyramid scale factor - float scale_factor; - - //! number of lagged non-linearity iterations (inner loop) - int inner_iterations; - - //! number of warping iterations (number of pyramid levels) - int outer_iterations; - - //! number of linear system solver iterations - int solver_iterations; - - GpuMat buf; - }; - - - -gpu::GoodFeaturesToTrackDetector_GPU ------------------------------------- -.. ocv:class:: gpu::GoodFeaturesToTrackDetector_GPU - -Class used for strong corners detection on an image. :: - - class GoodFeaturesToTrackDetector_GPU - { - public: - explicit GoodFeaturesToTrackDetector_GPU(int maxCorners_ = 1000, double qualityLevel_ = 0.01, double minDistance_ = 0.0, - int blockSize_ = 3, bool useHarrisDetector_ = false, double harrisK_ = 0.04); - - void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat()); - - int maxCorners; - double qualityLevel; - double minDistance; - - int blockSize; - bool useHarrisDetector; - double harrisK; - - void releaseMemory(); - }; - -The class finds the most prominent corners in the image. - -.. seealso:: :ocv:func:`goodFeaturesToTrack` - - - -gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU ---------------------------------------------------------------------- -Constructor. - -.. ocv:function:: gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0, int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04) - - :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned. - - :param qualityLevel: Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see :ocv:func:`gpu::cornerMinEigenVal` ) or the Harris function response (see :ocv:func:`gpu::cornerHarris` ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the ``qualityLevel=0.01`` , then all the corners with the quality measure less than 15 are rejected. - - :param minDistance: Minimum possible Euclidean distance between the returned corners. - - :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See :ocv:func:`cornerEigenValsAndVecs` . - - :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`gpu::cornerHarris`) or :ocv:func:`gpu::cornerMinEigenVal`. - - :param harrisK: Free parameter of the Harris detector. - - - -gpu::GoodFeaturesToTrackDetector_GPU::operator () -------------------------------------------------- -Finds the most prominent corners in the image. - -.. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat()) - - :param image: Input 8-bit, single-channel image. - - :param corners: Output vector of detected corners (it will be one row matrix with CV_32FC2 type). - - :param mask: Optional region of interest. If the image is not empty (it needs to have the type ``CV_8UC1`` and the same size as ``image`` ), it specifies the region in which the corners are detected. - -.. seealso:: :ocv:func:`goodFeaturesToTrack` - - - -gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory ---------------------------------------------------- -Releases inner buffers memory. - -.. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory() - - - -gpu::FarnebackOpticalFlow -------------------------- -.. ocv:class:: gpu::FarnebackOpticalFlow - -Class computing a dense optical flow using the Gunnar Farneback’s algorithm. :: - - class CV_EXPORTS FarnebackOpticalFlow - { - public: - FarnebackOpticalFlow() - { - numLevels = 5; - pyrScale = 0.5; - fastPyramids = false; - winSize = 13; - numIters = 10; - polyN = 5; - polySigma = 1.1; - flags = 0; - } - - int numLevels; - double pyrScale; - bool fastPyramids; - int winSize; - int numIters; - int polyN; - double polySigma; - int flags; - - void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()); - - void releaseMemory(); - - private: - /* hidden */ - }; - - - -gpu::FarnebackOpticalFlow::operator () --------------------------------------- -Computes a dense optical flow using the Gunnar Farneback’s algorithm. - -.. ocv:function:: void gpu::FarnebackOpticalFlow::operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()) - - :param frame0: First 8-bit gray-scale input image - :param frame1: Second 8-bit gray-scale input image - :param flowx: Flow horizontal component - :param flowy: Flow vertical component - :param s: Stream - -.. seealso:: :ocv:func:`calcOpticalFlowFarneback` - - - -gpu::FarnebackOpticalFlow::releaseMemory ----------------------------------------- -Releases unused auxiliary memory buffers. - -.. ocv:function:: void gpu::FarnebackOpticalFlow::releaseMemory() - - - -gpu::PyrLKOpticalFlow ---------------------- -.. ocv:class:: gpu::PyrLKOpticalFlow - -Class used for calculating an optical flow. :: - - class PyrLKOpticalFlow - { - public: - PyrLKOpticalFlow(); - - void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, - GpuMat& status, GpuMat* err = 0); - - void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0); - - Size winSize; - int maxLevel; - int iters; - bool useInitialFlow; - - void releaseMemory(); - }; - -The class can calculate an optical flow for a sparse feature set or dense optical flow using the iterative Lucas-Kanade method with pyramids. - -.. seealso:: :ocv:func:`calcOpticalFlowPyrLK` - - - -gpu::PyrLKOpticalFlow::sparse ------------------------------ -Calculate an optical flow for a sparse feature set. - -.. ocv:function:: void gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, GpuMat& status, GpuMat* err = 0) - - :param prevImg: First 8-bit input image (supports both grayscale and color images). - - :param nextImg: Second input image of the same size and the same type as ``prevImg`` . - - :param prevPts: Vector of 2D points for which the flow needs to be found. It must be one row matrix with CV_32FC2 type. - - :param nextPts: Output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image. When ``useInitialFlow`` is true, the vector must have the same size as in the input. - - :param status: Output status vector (CV_8UC1 type). Each element of the vector is set to 1 if the flow for the corresponding features has been found. Otherwise, it is set to 0. - - :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed. - -.. seealso:: :ocv:func:`calcOpticalFlowPyrLK` - - - -gpu::PyrLKOpticalFlow::dense ------------------------------ -Calculate dense optical flow. - -.. ocv:function:: void gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0) - - :param prevImg: First 8-bit grayscale input image. - - :param nextImg: Second input image of the same size and the same type as ``prevImg`` . - - :param u: Horizontal component of the optical flow of the same size as input images, 32-bit floating-point, single-channel - - :param v: Vertical component of the optical flow of the same size as input images, 32-bit floating-point, single-channel - - :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed. - - - -gpu::PyrLKOpticalFlow::releaseMemory ------------------------------------- -Releases inner buffers memory. - -.. ocv:function:: void gpu::PyrLKOpticalFlow::releaseMemory() - - - -gpu::interpolateFrames ----------------------- -Interpolates frames (images) using provided optical flow (displacement field). - -.. ocv:function:: void gpu::interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, const GpuMat& fu, const GpuMat& fv, const GpuMat& bu, const GpuMat& bv, float pos, GpuMat& newFrame, GpuMat& buf, Stream& stream = Stream::Null()) - - :param frame0: First frame (32-bit floating point images, single channel). - - :param frame1: Second frame. Must have the same type and size as ``frame0`` . - - :param fu: Forward horizontal displacement. - - :param fv: Forward vertical displacement. - - :param bu: Backward horizontal displacement. - - :param bv: Backward vertical displacement. - - :param pos: New frame position. - - :param newFrame: Output image. - - :param buf: Temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat: occlusion masks for first frame, occlusion masks for second, interpolated forward horizontal flow, interpolated forward vertical flow, interpolated backward horizontal flow, interpolated backward vertical flow. - - :param stream: Stream for the asynchronous version. - - - -gpu::FGDStatModel ------------------ -.. ocv:class:: gpu::FGDStatModel - -Class used for background/foreground segmentation. :: - - class FGDStatModel - { - public: - struct Params - { - ... - }; - - explicit FGDStatModel(int out_cn = 3); - explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3); - - ~FGDStatModel(); - - void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params()); - void release(); - - int update(const cv::gpu::GpuMat& curFrame); - - //8UC3 or 8UC4 reference background image - cv::gpu::GpuMat background; - - //8UC1 foreground image - cv::gpu::GpuMat foreground; - - std::vector< std::vector > foreground_regions; - }; - - The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [FGD2003]_. - - The results are available through the class fields: - - .. ocv:member:: cv::gpu::GpuMat background - - The output background image. - - .. ocv:member:: cv::gpu::GpuMat foreground - - The output foreground mask as an 8-bit binary image. - - .. ocv:member:: cv::gpu::GpuMat foreground_regions - - The output foreground regions calculated by :ocv:func:`findContours`. - - - -gpu::FGDStatModel::FGDStatModel -------------------------------- -Constructors. - -.. ocv:function:: gpu::FGDStatModel::FGDStatModel(int out_cn = 3) -.. ocv:function:: gpu::FGDStatModel::FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3) - - :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ). - - :param params: Algorithm's parameters. See [FGD2003]_ for explanation. - - :param out_cn: Channels count in output result and inner buffers. Can be 3 or 4. 4-channels version requires more memory, but works a bit faster. - -.. seealso:: :ocv:func:`gpu::FGDStatModel::create` - - - -gpu::FGDStatModel::create -------------------------- -Initializes background model. - -.. ocv:function:: void gpu::FGDStatModel::create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params()) - - :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ). - - :param params: Algorithm's parameters. See [FGD2003]_ for explanation. - - - -gpu::FGDStatModel::release --------------------------- -Releases all inner buffer's memory. - -.. ocv:function:: void gpu::FGDStatModel::release() - - - -gpu::FGDStatModel::update --------------------------- -Updates the background model and returns foreground regions count. - -.. ocv:function:: int gpu::FGDStatModel::update(const cv::gpu::GpuMat& curFrame) - - :param curFrame: Next video frame. - - - -gpu::MOG_GPU ------------- -.. ocv:class:: gpu::MOG_GPU - -Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm. :: - - class MOG_GPU - { - public: - MOG_GPU(int nmixtures = -1); - - void initialize(Size frameSize, int frameType); - - void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null()); - - void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const; - - void release(); - - int history; - float varThreshold; - float backgroundRatio; - float noiseSigma; - }; - -The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [MOG2001]_. - -.. seealso:: :ocv:class:`BackgroundSubtractorMOG` - - - -gpu::MOG_GPU::MOG_GPU ---------------------- -The constructor. - -.. ocv:function:: gpu::MOG_GPU::MOG_GPU(int nmixtures = -1) - - :param nmixtures: Number of Gaussian mixtures. - -Default constructor sets all parameters to default values. - - - -gpu::MOG_GPU::operator() ------------------------- -Updates the background model and returns the foreground mask. - -.. ocv:function:: void gpu::MOG_GPU::operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null()) - - :param frame: Next video frame. - - :param fgmask: The output foreground mask as an 8-bit binary image. - - :param stream: Stream for the asynchronous version. - - - -gpu::MOG_GPU::getBackgroundImage --------------------------------- -Computes a background image. - -.. ocv:function:: void gpu::MOG_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const - - :param backgroundImage: The output background image. - - :param stream: Stream for the asynchronous version. - - - -gpu::MOG_GPU::release ---------------------- -Releases all inner buffer's memory. - -.. ocv:function:: void gpu::MOG_GPU::release() - - - -gpu::MOG2_GPU -------------- -.. ocv:class:: gpu::MOG2_GPU - -Gaussian Mixture-based Background/Foreground Segmentation Algorithm. :: - - class MOG2_GPU - { - public: - MOG2_GPU(int nmixtures = -1); - - void initialize(Size frameSize, int frameType); - - void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null()); - - void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const; - - void release(); - - // parameters - ... - }; - - The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [MOG2004]_. - - Here are important members of the class that control the algorithm, which you can set after constructing the class instance: - - .. ocv:member:: float backgroundRatio - - Threshold defining whether the component is significant enough to be included into the background model ( corresponds to ``TB=1-cf`` from the paper??which paper??). ``cf=0.1 => TB=0.9`` is default. For ``alpha=0.001``, it means that the mode should exist for approximately 105 frames before it is considered foreground. - - .. ocv:member:: float varThreshold - - Threshold for the squared Mahalanobis distance that helps decide when a sample is close to the existing components (corresponds to ``Tg``). If it is not close to any component, a new component is generated. ``3 sigma => Tg=3*3=9`` is default. A smaller ``Tg`` value generates more components. A higher ``Tg`` value may result in a small number of components but they can grow too large. - - .. ocv:member:: float fVarInit - - Initial variance for the newly generated components. It affects the speed of adaptation. The parameter value is based on your estimate of the typical standard deviation from the images. OpenCV uses 15 as a reasonable value. - - .. ocv:member:: float fVarMin - - Parameter used to further control the variance. - - .. ocv:member:: float fVarMax - - Parameter used to further control the variance. - - .. ocv:member:: float fCT - - Complexity reduction parameter. This parameter defines the number of samples needed to accept to prove the component exists. ``CT=0.05`` is a default value for all the samples. By setting ``CT=0`` you get an algorithm very similar to the standard Stauffer&Grimson algorithm. - - .. ocv:member:: uchar nShadowDetection - - The value for marking shadow pixels in the output foreground mask. Default value is 127. - - .. ocv:member:: float fTau - - Shadow threshold. The shadow is detected if the pixel is a darker version of the background. ``Tau`` is a threshold defining how much darker the shadow can be. ``Tau= 0.5`` means that if a pixel is more than twice darker then it is not shadow. See [ShadowDetect2003]_. - - .. ocv:member:: bool bShadowDetection - - Parameter defining whether shadow detection should be enabled. - -.. seealso:: :ocv:class:`BackgroundSubtractorMOG2` - - - -gpu::MOG2_GPU::MOG2_GPU ------------------------ -The constructor. - -.. ocv:function:: gpu::MOG2_GPU::MOG2_GPU(int nmixtures = -1) - - :param nmixtures: Number of Gaussian mixtures. - -Default constructor sets all parameters to default values. - - - -gpu::MOG2_GPU::operator() -------------------------- -Updates the background model and returns the foreground mask. - -.. ocv:function:: void gpu::MOG2_GPU::operator()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() ) - - :param frame: Next video frame. - - :param fgmask: The output foreground mask as an 8-bit binary image. - - :param stream: Stream for the asynchronous version. - - - -gpu::MOG2_GPU::getBackgroundImage ---------------------------------- -Computes a background image. - -.. ocv:function:: void gpu::MOG2_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const - - :param backgroundImage: The output background image. - - :param stream: Stream for the asynchronous version. - - - -gpu::MOG2_GPU::release ----------------------- -Releases all inner buffer's memory. - -.. ocv:function:: void gpu::MOG2_GPU::release() - - - -gpu::GMG_GPU ------------- -.. ocv:class:: gpu::GMG_GPU - - Class used for background/foreground segmentation. :: - - class GMG_GPU_GPU - { - public: - GMG_GPU(); - - void initialize(Size frameSize, float min = 0.0f, float max = 255.0f); - - void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null()); - - void release(); - - int maxFeatures; - float learningRate; - int numInitializationFrames; - int quantizationLevels; - float backgroundPrior; - float decisionThreshold; - int smoothingRadius; - - ... - }; - - The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [GMG2012]_. - - Here are important members of the class that control the algorithm, which you can set after constructing the class instance: - - .. ocv:member:: int maxFeatures - - Total number of distinct colors to maintain in histogram. - - .. ocv:member:: float learningRate - - Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms. - - .. ocv:member:: int numInitializationFrames - - Number of frames of video to use to initialize histograms. - - .. ocv:member:: int quantizationLevels - - Number of discrete levels in each channel to be used in histograms. - - .. ocv:member:: float backgroundPrior - - Prior probability that any given pixel is a background pixel. A sensitivity parameter. - - .. ocv:member:: float decisionThreshold - - Value above which pixel is determined to be FG. - - .. ocv:member:: float smoothingRadius - - Smoothing radius, in pixels, for cleaning up FG image. - - - -gpu::GMG_GPU::GMG_GPU ---------------------- -The default constructor. - -.. ocv:function:: gpu::GMG_GPU::GMG_GPU() - -Default constructor sets all parameters to default values. - - - -gpu::GMG_GPU::initialize ------------------------- -Initialize background model and allocates all inner buffers. - -.. ocv:function:: void gpu::GMG_GPU::initialize(Size frameSize, float min = 0.0f, float max = 255.0f) - - :param frameSize: Input frame size. - - :param min: Minimum value taken on by pixels in image sequence. Usually 0. - - :param max: Maximum value taken on by pixels in image sequence, e.g. 1.0 or 255. - - - -gpu::GMG_GPU::operator() ------------------------- -Updates the background model and returns the foreground mask - -.. ocv:function:: void gpu::GMG_GPU::operator ()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() ) - - :param frame: Next video frame. - - :param fgmask: The output foreground mask as an 8-bit binary image. - - :param stream: Stream for the asynchronous version. - - - -gpu::GMG_GPU::release ---------------------- -Releases all inner buffer's memory. - -.. ocv:function:: void gpu::GMG_GPU::release() - - - -gpu::VideoWriter_GPU ---------------------- -Video writer class. - -.. ocv:class:: gpu::VideoWriter_GPU - -The class uses H264 video codec. - -.. note:: Currently only Windows platform is supported. - - - -gpu::VideoWriter_GPU::VideoWriter_GPU -------------------------------------- -Constructors. - -.. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU() -.. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const String& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR) -.. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const String& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR) -.. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR) -.. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR) - - :param fileName: Name of the output video file. Only AVI file format is supported. - - :param frameSize: Size of the input video frames. - - :param fps: Framerate of the created video stream. - - :param params: Encoder parameters. See :ocv:struct:`gpu::VideoWriter_GPU::EncoderParams` . - - :param format: Surface format of input frames ( ``SF_UYVY`` , ``SF_YUY2`` , ``SF_YV12`` , ``SF_NV12`` , ``SF_IYUV`` , ``SF_BGR`` or ``SF_GRAY``). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is. - - :param encoderCallback: Callbacks for video encoder. See :ocv:class:`gpu::VideoWriter_GPU::EncoderCallBack` . Use it if you want to work with raw video stream. - -The constructors initialize video writer. FFMPEG is used to write videos. User can implement own multiplexing with :ocv:class:`gpu::VideoWriter_GPU::EncoderCallBack` . - - - -gpu::VideoWriter_GPU::open --------------------------- -Initializes or reinitializes video writer. - -.. ocv:function:: void gpu::VideoWriter_GPU::open(const String& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR) -.. ocv:function:: void gpu::VideoWriter_GPU::open(const String& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR) -.. ocv:function:: void gpu::VideoWriter_GPU::open(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR) -.. ocv:function:: void gpu::VideoWriter_GPU::open(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR) - -The method opens video writer. Parameters are the same as in the constructor :ocv:func:`gpu::VideoWriter_GPU::VideoWriter_GPU` . The method throws :ocv:class:`Exception` if error occurs. - - - -gpu::VideoWriter_GPU::isOpened ------------------------------- -Returns true if video writer has been successfully initialized. - -.. ocv:function:: bool gpu::VideoWriter_GPU::isOpened() const - - - -gpu::VideoWriter_GPU::close ---------------------------- -Releases the video writer. - -.. ocv:function:: void gpu::VideoWriter_GPU::close() - - - -gpu::VideoWriter_GPU::write ---------------------------- -Writes the next video frame. - -.. ocv:function:: void gpu::VideoWriter_GPU::write(const cv::gpu::GpuMat& image, bool lastFrame = false) - - :param image: The written frame. - - :param lastFrame: Indicates that it is end of stream. The parameter can be ignored. - -The method write the specified image to video file. The image must have the same size and the same surface format as has been specified when opening the video writer. - - - -gpu::VideoWriter_GPU::EncoderParams ------------------------------------ -.. ocv:struct:: gpu::VideoWriter_GPU::EncoderParams - -Different parameters for CUDA video encoder. :: - - struct EncoderParams - { - int P_Interval; // NVVE_P_INTERVAL, - int IDR_Period; // NVVE_IDR_PERIOD, - int DynamicGOP; // NVVE_DYNAMIC_GOP, - int RCType; // NVVE_RC_TYPE, - int AvgBitrate; // NVVE_AVG_BITRATE, - int PeakBitrate; // NVVE_PEAK_BITRATE, - int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA, - int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P, - int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B, - int DeblockMode; // NVVE_DEBLOCK_MODE, - int ProfileLevel; // NVVE_PROFILE_LEVEL, - int ForceIntra; // NVVE_FORCE_INTRA, - int ForceIDR; // NVVE_FORCE_IDR, - int ClearStat; // NVVE_CLEAR_STAT, - int DIMode; // NVVE_SET_DEINTERLACE, - int Presets; // NVVE_PRESETS, - int DisableCabac; // NVVE_DISABLE_CABAC, - int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE - int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS - - EncoderParams(); - explicit EncoderParams(const String& configFile); - - void load(const String& configFile); - void save(const String& configFile) const; - }; - - - -gpu::VideoWriter_GPU::EncoderParams::EncoderParams --------------------------------------------------- -Constructors. - -.. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams() -.. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams(const String& configFile) - - :param configFile: Config file name. - -Creates default parameters or reads parameters from config file. - - - -gpu::VideoWriter_GPU::EncoderParams::load ------------------------------------------ -Reads parameters from config file. - -.. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::load(const String& configFile) - - :param configFile: Config file name. - - - -gpu::VideoWriter_GPU::EncoderParams::save ------------------------------------------ -Saves parameters to config file. - -.. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::save(const String& configFile) const - - :param configFile: Config file name. - - - -gpu::VideoWriter_GPU::EncoderCallBack -------------------------------------- -.. ocv:class:: gpu::VideoWriter_GPU::EncoderCallBack - -Callbacks for CUDA video encoder. :: - - class EncoderCallBack - { - public: - enum PicType - { - IFRAME = 1, - PFRAME = 2, - BFRAME = 3 - }; - - virtual ~EncoderCallBack() {} - - virtual unsigned char* acquireBitStream(int* bufferSize) = 0; - virtual void releaseBitStream(unsigned char* data, int size) = 0; - virtual void onBeginFrame(int frameNumber, PicType picType) = 0; - virtual void onEndFrame(int frameNumber, PicType picType) = 0; - }; - - - -gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream -------------------------------------------------------- -Callback function to signal the start of bitstream that is to be encoded. - -.. ocv:function:: virtual uchar* gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream(int* bufferSize) = 0 - -Callback must allocate buffer for CUDA encoder and return pointer to it and it's size. - - - -gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream -------------------------------------------------------- -Callback function to signal that the encoded bitstream is ready to be written to file. - -.. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream(unsigned char* data, int size) = 0 - - - -gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame ---------------------------------------------------- -Callback function to signal that the encoding operation on the frame has started. - -.. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame(int frameNumber, PicType picType) = 0 - - :param picType: Specify frame type (I-Frame, P-Frame or B-Frame). - - - -gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame -------------------------------------------------- -Callback function signals that the encoding operation on the frame has finished. - -.. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame(int frameNumber, PicType picType) = 0 - - :param picType: Specify frame type (I-Frame, P-Frame or B-Frame). - - - -gpu::VideoReader_GPU --------------------- -Class for reading video from files. - -.. ocv:class:: gpu::VideoReader_GPU - -.. note:: Currently only Windows and Linux platforms are supported. - - - -gpu::VideoReader_GPU::Codec ---------------------------- - -Video codecs supported by :ocv:class:`gpu::VideoReader_GPU` . - -.. ocv:enum:: gpu::VideoReader_GPU::Codec - - .. ocv:emember:: MPEG1 = 0 - .. ocv:emember:: MPEG2 - .. ocv:emember:: MPEG4 - .. ocv:emember:: VC1 - .. ocv:emember:: H264 - .. ocv:emember:: JPEG - .. ocv:emember:: H264_SVC - .. ocv:emember:: H264_MVC - - .. ocv:emember:: Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')) - - Y,U,V (4:2:0) - - .. ocv:emember:: Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')) - - Y,V,U (4:2:0) - - .. ocv:emember:: Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')) - - Y,UV (4:2:0) - - .. ocv:emember:: Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')) - - YUYV/YUY2 (4:2:2) - - .. ocv:emember:: Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) - - UYVY (4:2:2) - - -gpu::VideoReader_GPU::ChromaFormat ----------------------------------- - -Chroma formats supported by :ocv:class:`gpu::VideoReader_GPU` . - -.. ocv:enum:: gpu::VideoReader_GPU::ChromaFormat - - .. ocv:emember:: Monochrome = 0 - .. ocv:emember:: YUV420 - .. ocv:emember:: YUV422 - .. ocv:emember:: YUV444 - - -gpu::VideoReader_GPU::FormatInfo --------------------------------- -.. ocv:struct:: gpu::VideoReader_GPU::FormatInfo - -Struct providing information about video file format. :: - - struct FormatInfo - { - Codec codec; - ChromaFormat chromaFormat; - int width; - int height; - }; - - -gpu::VideoReader_GPU::VideoReader_GPU -------------------------------------- -Constructors. - -.. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU() -.. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU(const String& filename) -.. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU(const cv::Ptr& source) - - :param filename: Name of the input video file. - - :param source: Video file parser implemented by user. - -The constructors initialize video reader. FFMPEG is used to read videos. User can implement own demultiplexing with :ocv:class:`gpu::VideoReader_GPU::VideoSource` . - - - -gpu::VideoReader_GPU::open --------------------------- -Initializes or reinitializes video reader. - -.. ocv:function:: void gpu::VideoReader_GPU::open(const String& filename) -.. ocv:function:: void gpu::VideoReader_GPU::open(const cv::Ptr& source) - -The method opens video reader. Parameters are the same as in the constructor :ocv:func:`gpu::VideoReader_GPU::VideoReader_GPU` . The method throws :ocv:class:`Exception` if error occurs. - - - -gpu::VideoReader_GPU::isOpened ------------------------------- -Returns true if video reader has been successfully initialized. - -.. ocv:function:: bool gpu::VideoReader_GPU::isOpened() const - - - -gpu::VideoReader_GPU::close ---------------------------- -Releases the video reader. - -.. ocv:function:: void gpu::VideoReader_GPU::close() - - - -gpu::VideoReader_GPU::read --------------------------- -Grabs, decodes and returns the next video frame. - -.. ocv:function:: bool gpu::VideoReader_GPU::read(GpuMat& image) - -If no frames has been grabbed (there are no more frames in video file), the methods return ``false`` . The method throws :ocv:class:`Exception` if error occurs. - - - -gpu::VideoReader_GPU::format ----------------------------- -Returns information about video file format. - -.. ocv:function:: FormatInfo gpu::VideoReader_GPU::format() const - -The method throws :ocv:class:`Exception` if video reader wasn't initialized. - - - -gpu::VideoReader_GPU::dumpFormat --------------------------------- -Dump information about video file format to specified stream. - -.. ocv:function:: void gpu::VideoReader_GPU::dumpFormat(std::ostream& st) - - :param st: Output stream. - -The method throws :ocv:class:`Exception` if video reader wasn't initialized. - - - -gpu::VideoReader_GPU::VideoSource ------------------------------------ -.. ocv:class:: gpu::VideoReader_GPU::VideoSource - -Interface for video demultiplexing. :: - - class VideoSource - { - public: - VideoSource(); - virtual ~VideoSource() {} - - virtual FormatInfo format() const = 0; - virtual void start() = 0; - virtual void stop() = 0; - virtual bool isStarted() const = 0; - virtual bool hasError() const = 0; - - protected: - bool parseVideoData(const unsigned char* data, size_t size, bool endOfStream = false); - }; - -User can implement own demultiplexing by implementing this interface. - - - -gpu::VideoReader_GPU::VideoSource::format ------------------------------------------ -Returns information about video file format. - -.. ocv:function:: virtual FormatInfo gpu::VideoReader_GPU::VideoSource::format() const = 0 - - - -gpu::VideoReader_GPU::VideoSource::start ----------------------------------------- -Starts processing. - -.. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::start() = 0 - -Implementation must create own thread with video processing and call periodic :ocv:func:`gpu::VideoReader_GPU::VideoSource::parseVideoData` . - - - -gpu::VideoReader_GPU::VideoSource::stop ---------------------------------------- -Stops processing. - -.. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::stop() = 0 - - - -gpu::VideoReader_GPU::VideoSource::isStarted --------------------------------------------- -Returns ``true`` if processing was successfully started. - -.. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::isStarted() const = 0 - - - -gpu::VideoReader_GPU::VideoSource::hasError -------------------------------------------- -Returns ``true`` if error occured during processing. - -.. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::hasError() const = 0 - - - -gpu::VideoReader_GPU::VideoSource::parseVideoData -------------------------------------------------- -Parse next video frame. Implementation must call this method after new frame was grabbed. - -.. ocv:function:: bool gpu::VideoReader_GPU::VideoSource::parseVideoData(const uchar* data, size_t size, bool endOfStream = false) - - :param data: Pointer to frame data. Can be ``NULL`` if ``endOfStream`` if ``true`` . - - :param size: Size in bytes of current frame. - - :param endOfStream: Indicates that it is end of stream. - - - -.. [Brox2004] T. Brox, A. Bruhn, N. Papenberg, J. Weickert. *High accuracy optical flow estimation based on a theory for warping*. ECCV 2004. -.. [FGD2003] Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. *Foreground Object Detection from Videos Containing Complex Background*. ACM MM2003 9p, 2003. -.. [MOG2001] P. KadewTraKuPong and R. Bowden. *An improved adaptive background mixture model for real-time tracking with shadow detection*. Proc. 2nd European Workshop on Advanced Video-Based Surveillance Systems, 2001 -.. [MOG2004] Z. Zivkovic. *Improved adaptive Gausian mixture model for background subtraction*. International Conference Pattern Recognition, UK, August, 2004 -.. [ShadowDetect2003] Prati, Mikic, Trivedi and Cucchiarra. *Detecting Moving Shadows...*. IEEE PAMI, 2003 -.. [GMG2012] A. Godbehere, A. Matsukawa and K. Goldberg. *Visual Tracking of Human Visitors under Variable-Lighting Conditions for a Responsive Audio Art Installation*. American Control Conference, Montreal, June 2012 diff --git a/modules/gpu/include/opencv2/gpu.hpp b/modules/gpu/include/opencv2/gpu.hpp index 84de397..5dc9b95 100644 --- a/modules/gpu/include/opencv2/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu.hpp @@ -43,2323 +43,210 @@ #ifndef __OPENCV_GPU_HPP__ #define __OPENCV_GPU_HPP__ -#ifndef SKIP_INCLUDES -#include -#include -#include +#ifndef __cplusplus +# error gpu.hpp header must be compiled as C++ #endif #include "opencv2/core/gpumat.hpp" -#include "opencv2/imgproc.hpp" -#include "opencv2/objdetect.hpp" -#include "opencv2/features2d.hpp" -namespace cv { namespace gpu { -//////////////////////////////// Filter Engine //////////////////////////////// - -/*! -The Base Class for 1D or Row-wise Filters - -This is the base class for linear or non-linear filters that process 1D data. -In particular, such filters are used for the "horizontal" filtering parts in separable filters. -*/ -class CV_EXPORTS BaseRowFilter_GPU -{ -public: - BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {} - virtual ~BaseRowFilter_GPU() {} - virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0; - int ksize, anchor; -}; - -/*! -The Base Class for Column-wise Filters - -This is the base class for linear or non-linear filters that process columns of 2D arrays. -Such filters are used for the "vertical" filtering parts in separable filters. -*/ -class CV_EXPORTS BaseColumnFilter_GPU -{ -public: - BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {} - virtual ~BaseColumnFilter_GPU() {} - virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0; - int ksize, anchor; -}; - -/*! -The Base Class for Non-Separable 2D Filters. - -This is the base class for linear or non-linear 2D filters. -*/ -class CV_EXPORTS BaseFilter_GPU -{ -public: - BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {} - virtual ~BaseFilter_GPU() {} - virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0; - Size ksize; - Point anchor; -}; - -/*! -The Base Class for Filter Engine. - -The class can be used to apply an arbitrary filtering operation to an image. -It contains all the necessary intermediate buffers. -*/ -class CV_EXPORTS FilterEngine_GPU -{ -public: - virtual ~FilterEngine_GPU() {} - - virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1), Stream& stream = Stream::Null()) = 0; -}; - -//! returns the non-separable filter engine with the specified filter -CV_EXPORTS Ptr createFilter2D_GPU(const Ptr& filter2D, int srcType, int dstType); - -//! returns the separable filter engine with the specified filters -CV_EXPORTS Ptr createSeparableFilter_GPU(const Ptr& rowFilter, - const Ptr& columnFilter, int srcType, int bufType, int dstType); -CV_EXPORTS Ptr createSeparableFilter_GPU(const Ptr& rowFilter, - const Ptr& columnFilter, int srcType, int bufType, int dstType, GpuMat& buf); - -//! returns horizontal 1D box filter -//! supports only CV_8UC1 source type and CV_32FC1 sum type -CV_EXPORTS Ptr getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1); - -//! returns vertical 1D box filter -//! supports only CV_8UC1 sum type and CV_32FC1 dst type -CV_EXPORTS Ptr getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1); - -//! returns 2D box filter -//! supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type -CV_EXPORTS Ptr getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1)); - -//! returns box filter engine -CV_EXPORTS Ptr createBoxFilter_GPU(int srcType, int dstType, const Size& ksize, - const Point& anchor = Point(-1,-1)); - -//! returns 2D morphological filter -//! only MORPH_ERODE and MORPH_DILATE are supported -//! supports CV_8UC1 and CV_8UC4 types -//! kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height -CV_EXPORTS Ptr getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize, - Point anchor=Point(-1,-1)); - -//! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported. -CV_EXPORTS Ptr createMorphologyFilter_GPU(int op, int type, const Mat& kernel, - const Point& anchor = Point(-1,-1), int iterations = 1); -CV_EXPORTS Ptr createMorphologyFilter_GPU(int op, int type, const Mat& kernel, GpuMat& buf, - const Point& anchor = Point(-1,-1), int iterations = 1); - -//! returns 2D filter with the specified kernel -//! supports CV_8U, CV_16U and CV_32F one and four channel image -CV_EXPORTS Ptr getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT); - -//! returns the non-separable linear filter engine -CV_EXPORTS Ptr createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, - Point anchor = Point(-1,-1), int borderType = BORDER_DEFAULT); - -//! returns the primitive row filter with the specified kernel. -//! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 source type. -//! there are two version of algorithm: NPP and OpenCV. -//! NPP calls when srcType == CV_8UC1 or srcType == CV_8UC4 and bufType == srcType, -//! otherwise calls OpenCV version. -//! NPP supports only BORDER_CONSTANT border type. -//! OpenCV version supports only CV_32F as buffer depth and -//! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types. -CV_EXPORTS Ptr getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel, - int anchor = -1, int borderType = BORDER_DEFAULT); - -//! returns the primitive column filter with the specified kernel. -//! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 dst type. -//! there are two version of algorithm: NPP and OpenCV. -//! NPP calls when dstType == CV_8UC1 or dstType == CV_8UC4 and bufType == dstType, -//! otherwise calls OpenCV version. -//! NPP supports only BORDER_CONSTANT border type. -//! OpenCV version supports only CV_32F as buffer depth and -//! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types. -CV_EXPORTS Ptr getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel, - int anchor = -1, int borderType = BORDER_DEFAULT); - -//! returns the separable linear filter engine -CV_EXPORTS Ptr createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel, - const Mat& columnKernel, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, - int columnBorderType = -1); -CV_EXPORTS Ptr createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel, - const Mat& columnKernel, GpuMat& buf, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, - int columnBorderType = -1); - -//! returns filter engine for the generalized Sobel operator -CV_EXPORTS Ptr createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS Ptr createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize, GpuMat& buf, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); - -//! returns the Gaussian filter engine -CV_EXPORTS Ptr createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS Ptr createGaussianFilter_GPU(int type, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); - -//! returns maximum filter -CV_EXPORTS Ptr getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1)); - -//! returns minimum filter -CV_EXPORTS Ptr getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1)); - -//! smooths the image using the normalized box filter -//! supports CV_8UC1, CV_8UC4 types -CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null()); - -//! a synonym for normalized box filter -static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null()) -{ - boxFilter(src, dst, -1, ksize, anchor, stream); -} - -//! erodes the image (applies the local minimum operator) -CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1); -CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf, - Point anchor = Point(-1, -1), int iterations = 1, - Stream& stream = Stream::Null()); - -//! dilates the image (applies the local maximum operator) -CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1); -CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf, - Point anchor = Point(-1, -1), int iterations = 1, - Stream& stream = Stream::Null()); - -//! applies an advanced morphological operation to the image -CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1); -CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, GpuMat& buf1, GpuMat& buf2, - Point anchor = Point(-1, -1), int iterations = 1, Stream& stream = Stream::Null()); - -//! applies non-separable 2D linear filter to the image -CV_EXPORTS void filter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1), int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null()); - -//! applies separable 2D linear filter to the image -CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, - Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, GpuMat& buf, - Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, - Stream& stream = Stream::Null()); - -//! applies generalized Sobel operator to the image -CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, int ksize = 3, double scale = 1, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null()); - -//! applies the vertical or horizontal Scharr operator to the image -CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, double scale = 1, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null()); - -//! smooths the image using Gaussian filter. -CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1); -CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0, - int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null()); - -//! applies Laplacian operator to the image -//! 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()); - - -////////////////////////////// Arithmetics /////////////////////////////////// - -//! implements generalized matrix product algorithm GEMM from BLAS -CV_EXPORTS void gemm(const GpuMat& src1, const GpuMat& src2, double alpha, - const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null()); - -//! transposes the matrix -//! supports matrix with element size = 1, 4 and 8 bytes (CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, etc) -CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst, Stream& stream = Stream::Null()); - -//! reverses the order of the rows, columns or both in a matrix -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U, CV_32S or CV_32F depth -CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode, Stream& stream = Stream::Null()); - -//! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i)) -//! destination array will have the depth type as lut and the same channels number as source -//! supports CV_8UC1, CV_8UC3 types -CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stream = Stream::Null()); - -//! makes multi-channel array out of several single-channel arrays -CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null()); - -//! makes multi-channel array out of several single-channel arrays -CV_EXPORTS void merge(const std::vector& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! copies each plane of a multi-channel array to a dedicated array -CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null()); - -//! copies each plane of a multi-channel array to a dedicated array -CV_EXPORTS void split(const GpuMat& src, std::vector& dst, Stream& stream = Stream::Null()); - -//! computes magnitude of complex (x(i).re, x(i).im) vector -//! supports only CV_32FC2 type -CV_EXPORTS void magnitude(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null()); - -//! computes squared magnitude of complex (x(i).re, x(i).im) vector -//! supports only CV_32FC2 type -CV_EXPORTS void magnitudeSqr(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null()); - -//! computes magnitude of each (x(i), y(i)) vector -//! supports only floating-point source -CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null()); - -//! computes squared magnitude of each (x(i), y(i)) vector -//! supports only floating-point source -CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null()); - -//! computes angle (angle(i)) of each (x(i), y(i)) vector -//! supports only floating-point source -CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null()); - -//! converts Cartesian coordinates to polar -//! supports only floating-point source -CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null()); - -//! converts polar coordinates to Cartesian -//! supports only floating-point source -CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false, Stream& stream = Stream::Null()); - -//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values -CV_EXPORTS void normalize(const GpuMat& src, GpuMat& dst, double alpha = 1, double beta = 0, - int norm_type = NORM_L2, int dtype = -1, const GpuMat& mask = GpuMat()); -CV_EXPORTS void normalize(const GpuMat& src, GpuMat& dst, double a, double b, - int norm_type, int dtype, const GpuMat& mask, GpuMat& norm_buf, GpuMat& cvt_buf); - - -//////////////////////////// Per-element operations //////////////////////////////////// - -//! adds one matrix to another (c = a + b) -CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()); -//! adds scalar to a matrix (c = a + s) -CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()); - -//! subtracts one matrix from another (c = a - b) -CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()); -//! subtracts scalar from a matrix (c = a - s) -CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()); - -//! computes element-wise weighted product of the two arrays (c = scale * a * b) -CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()); -//! weighted multiplies matrix to a scalar (c = scale * a * s) -CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()); - -//! computes element-wise weighted quotient of the two arrays (c = a / b) -CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()); -//! computes element-wise weighted quotient of matrix and scalar (c = a / s) -CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()); -//! computes element-wise weighted reciprocal of an array (dst = scale/src2) -CV_EXPORTS void divide(double scale, const GpuMat& b, GpuMat& c, int dtype = -1, Stream& stream = Stream::Null()); - -//! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma) -CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, - int dtype = -1, Stream& stream = Stream::Null()); - -//! adds scaled array to another one (dst = alpha*src1 + src2) -static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()) -{ - addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream); -} - -//! computes element-wise absolute difference of two arrays (c = abs(a - b)) -CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream = Stream::Null()); -//! computes element-wise absolute difference of array and scalar (c = abs(a - s)) -CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c, Stream& stream = Stream::Null()); - -//! computes absolute value of each matrix element -//! supports CV_16S and CV_32F depth -CV_EXPORTS void abs(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes square of each pixel in an image -//! supports CV_8U, CV_16U, CV_16S and CV_32F depth -CV_EXPORTS void sqr(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes square root of each pixel in an image -//! supports CV_8U, CV_16U, CV_16S and CV_32F depth -CV_EXPORTS void sqrt(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes exponent of each matrix element (b = e**a) -//! supports CV_8U, CV_16U, CV_16S and CV_32F depth -CV_EXPORTS void exp(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null()); - -//! computes natural logarithm of absolute value of each matrix element: b = log(abs(a)) -//! supports CV_8U, CV_16U, CV_16S and CV_32F depth -CV_EXPORTS void log(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null()); - -//! computes power of each matrix element: -// (dst(i,j) = pow( src(i,j) , power), if src.type() is integer -// (dst(i,j) = pow(fabs(src(i,j)), power), otherwise -//! supports all, except depth == CV_64F -CV_EXPORTS void pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream = Stream::Null()); - -//! compares elements of two arrays (c = a b) -CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream = Stream::Null()); -CV_EXPORTS void compare(const GpuMat& a, Scalar sc, GpuMat& c, int cmpop, Stream& stream = Stream::Null()); - -//! performs per-elements bit-wise inversion -CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null()); - -//! calculates per-element bit-wise disjunction of two arrays -CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null()); -//! calculates per-element bit-wise disjunction of array and scalar -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth -CV_EXPORTS void bitwise_or(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! calculates per-element bit-wise conjunction of two arrays -CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null()); -//! calculates per-element bit-wise conjunction of array and scalar -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth -CV_EXPORTS void bitwise_and(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! calculates per-element bit-wise "exclusive or" operation -CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null()); -//! calculates per-element bit-wise "exclusive or" of array and scalar -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth -CV_EXPORTS void bitwise_xor(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! pixel by pixel right shift of an image by a constant value -//! supports 1, 3 and 4 channels images with integers elements -CV_EXPORTS void rshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! pixel by pixel left shift of an image by a constant value -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth -CV_EXPORTS void lshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes per-element minimum of two arrays (dst = min(src1, src2)) -CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes per-element minimum of array and scalar (dst = min(src1, src2)) -CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes per-element maximum of two arrays (dst = max(src1, src2)) -CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()); - -//! computes per-element maximum of array and scalar (dst = max(src1, src2)) -CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null()); - -enum { ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL, - ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL}; - -//! Composite two images using alpha opacity values contained in each image -//! Supports CV_8UC4, CV_16UC4, CV_32SC4 and CV_32FC4 types -CV_EXPORTS void alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream = Stream::Null()); - - -////////////////////////////// Image processing ////////////////////////////// - -//! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] -//! supports only CV_32FC1 map type -CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, - int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), - Stream& stream = Stream::Null()); - -//! Does mean shift filtering on GPU. -CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr, - TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1), - Stream& stream = Stream::Null()); - -//! Does mean shift procedure on GPU. -CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr, - TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1), - Stream& stream = Stream::Null()); - -//! Does mean shift segmentation with elimination of small regions. -CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize, - TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1)); - -//! Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV. -//! Supported types of input disparity: CV_8U, CV_16S. -//! Output disparity has CV_8UC4 type in BGRA format (alpha = 255). -CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, Stream& stream = Stream::Null()); - -//! Reprojects disparity image to 3D space. -//! Supports CV_8U and CV_16S types of input disparity. -//! The output is a 3- or 4-channel floating-point matrix. -//! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map. -//! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify. -CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, int dst_cn = 4, Stream& stream = Stream::Null()); - -//! converts image from one color space to another -CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0, Stream& stream = Stream::Null()); - -enum -{ - // Bayer Demosaicing (Malvar, He, and Cutler) - COLOR_BayerBG2BGR_MHT = 256, - COLOR_BayerGB2BGR_MHT = 257, - COLOR_BayerRG2BGR_MHT = 258, - COLOR_BayerGR2BGR_MHT = 259, - - COLOR_BayerBG2RGB_MHT = COLOR_BayerRG2BGR_MHT, - COLOR_BayerGB2RGB_MHT = COLOR_BayerGR2BGR_MHT, - COLOR_BayerRG2RGB_MHT = COLOR_BayerBG2BGR_MHT, - COLOR_BayerGR2RGB_MHT = COLOR_BayerGB2BGR_MHT, - - COLOR_BayerBG2GRAY_MHT = 260, - COLOR_BayerGB2GRAY_MHT = 261, - COLOR_BayerRG2GRAY_MHT = 262, - COLOR_BayerGR2GRAY_MHT = 263 -}; -CV_EXPORTS void demosaicing(const GpuMat& src, GpuMat& dst, int code, int dcn = -1, Stream& stream = Stream::Null()); - -//! swap channels -//! dstOrder - Integer array describing how channel values are permutated. The n-th entry -//! of the array contains the number of the channel that is stored in the n-th channel of -//! the output image. E.g. Given an RGBA image, aDstOrder = [3,2,1,0] converts this to ABGR -//! channel order. -CV_EXPORTS void swapChannels(GpuMat& image, const int dstOrder[4], Stream& stream = Stream::Null()); - -//! Routines for correcting image color gamma -CV_EXPORTS void gammaCorrection(const GpuMat& src, GpuMat& dst, bool forward = true, Stream& stream = Stream::Null()); - -//! applies fixed threshold to the image -CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, Stream& stream = Stream::Null()); - -//! resizes the image -//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA -CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()); - -//! warps the image using affine transformation -//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC -CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR, - int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()); - -CV_EXPORTS void buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null()); - -//! warps the image using perspective transformation -//! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC -CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR, - int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null()); - -CV_EXPORTS void buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null()); - -//! builds plane warping maps -CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, const Mat &T, float scale, - GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null()); - -//! builds cylindrical warping maps -CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale, - GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null()); - -//! builds spherical warping maps -CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale, - GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null()); - -//! rotates an image around the origin (0,0) and then shifts it -//! supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC -//! supports 1, 3 or 4 channels images with CV_8U, CV_16U or CV_32F depth -CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, - int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()); - -//! copies 2D array to a larger destination array and pads borders with user-specifiable constant -CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType, - const Scalar& value = Scalar(), Stream& stream = Stream::Null()); - -//! computes the integral image -//! sum will have CV_32S type, but will contain unsigned int values -//! supports only CV_8UC1 source type -CV_EXPORTS void integral(const GpuMat& src, GpuMat& sum, Stream& stream = Stream::Null()); -//! buffered version -CV_EXPORTS void integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer, Stream& stream = Stream::Null()); - -//! computes squared integral image -//! result matrix will have 64F type, but will contain 64U values -//! supports source images of 8UC1 type only -CV_EXPORTS void sqrIntegral(const GpuMat& src, GpuMat& sqsum, Stream& stream = Stream::Null()); - -//! computes vertical sum, supports only CV_32FC1 images -CV_EXPORTS void columnSum(const GpuMat& src, GpuMat& sum); - -//! computes the standard deviation of integral images -//! supports only CV_32SC1 source type and CV_32FC1 sqr type -//! output will have CV_32FC1 type -CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect, Stream& stream = Stream::Null()); - -//! computes Harris cornerness criteria at each image pixel -CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101); -CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101); -CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k, - int borderType = BORDER_REFLECT101, Stream& stream = Stream::Null()); - -//! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria -CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101); -CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType=BORDER_REFLECT101); -CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, - int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null()); - -//! performs per-element multiplication of two full (not packed) Fourier spectrums -//! supports 32FC2 matrixes only (interleaved format) -CV_EXPORTS void mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false, Stream& stream = Stream::Null()); - -//! performs per-element multiplication of two full (not packed) Fourier spectrums -//! supports 32FC2 matrixes only (interleaved format) -CV_EXPORTS void mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null()); - -//! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix. -//! Param dft_size is the size of DFT transform. -//! -//! If the source matrix is not continous, then additional copy will be done, -//! so to avoid copying ensure the source matrix is continous one. If you want to use -//! preallocated output ensure it is continuous too, otherwise it will be reallocated. -//! -//! Being implemented via CUFFT real-to-complex transform result contains only non-redundant values -//! in CUFFT's format. Result as full complex matrix for such kind of transform cannot be retrieved. -//! -//! For complex-to-real transform it is assumed that the source matrix is packed in CUFFT's format. -CV_EXPORTS void dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0, Stream& stream = Stream::Null()); - -struct CV_EXPORTS ConvolveBuf -{ - Size result_size; - Size block_size; - Size user_block_size; - Size dft_size; - int spect_len; - - GpuMat image_spect, templ_spect, result_spect; - GpuMat image_block, templ_block, result_data; - - void create(Size image_size, Size templ_size); - static Size estimateBlockSize(Size result_size, Size templ_size); -}; - - -//! computes convolution (or cross-correlation) of two images using discrete Fourier transform -//! supports source images of 32FC1 type only -//! result matrix will have 32FC1 type -CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr = false); -CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf, Stream& stream = Stream::Null()); - -struct CV_EXPORTS MatchTemplateBuf -{ - Size user_block_size; - GpuMat imagef, templf; - std::vector images; - std::vector image_sums; - std::vector image_sqsums; -}; - -//! computes the proximity map for the raster template and the image where the template is searched for -CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, Stream &stream = Stream::Null()); - -//! computes the proximity map for the raster template and the image where the template is searched for -CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, MatchTemplateBuf &buf, Stream& stream = Stream::Null()); - -//! smoothes the source image and downsamples it -CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! upsamples the source image and then smoothes it -CV_EXPORTS void pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); - -//! performs linear blending of two images -//! to avoid accuracy errors sum of weigths shouldn't be very close to zero -CV_EXPORTS void blendLinear(const GpuMat& img1, const GpuMat& img2, const GpuMat& weights1, const GpuMat& weights2, - GpuMat& result, Stream& stream = Stream::Null()); - -//! Performa bilateral filtering of passsed image -CV_EXPORTS void bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial, - int borderMode = BORDER_DEFAULT, Stream& stream = Stream::Null()); - -//! Brute force non-local means algorith (slow but universal) -CV_EXPORTS void nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null()); - -//! Fast (but approximate)version of non-local means algorith similar to CPU function (running sums technique) -class CV_EXPORTS FastNonLocalMeansDenoising -{ -public: - //! Simple method, recommended for grayscale images (though it supports multichannel images) - void simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()); - - //! Processes luminance and color components separatelly - void labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()); - -private: - - GpuMat buffer, extended_src_buffer; - GpuMat lab, l, ab; -}; - -struct CV_EXPORTS CannyBuf -{ - void create(const Size& image_size, int apperture_size = 3); - void release(); - - GpuMat dx, dy; - GpuMat mag; - GpuMat map; - GpuMat st1, st2; - Ptr filterDX, filterDY; -}; - -CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false); -CV_EXPORTS void Canny(const GpuMat& image, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false); -CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false); -CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false); - -class CV_EXPORTS ImagePyramid -{ -public: - inline ImagePyramid() : nLayers_(0) {} - inline ImagePyramid(const GpuMat& img, int nLayers, Stream& stream = Stream::Null()) - { - build(img, nLayers, stream); - } - - void build(const GpuMat& img, int nLayers, Stream& stream = Stream::Null()); - - void getLayer(GpuMat& outImg, Size outRoi, Stream& stream = Stream::Null()) const; - - inline void release() - { - layer0_.release(); - pyramid_.clear(); - nLayers_ = 0; - } - -private: - GpuMat layer0_; - std::vector pyramid_; - int nLayers_; -}; - -//! HoughLines - -struct HoughLinesBuf -{ - GpuMat accum; - GpuMat list; -}; - -CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096); -CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096); -CV_EXPORTS void HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray()); - -//! HoughLinesP - -//! finds line segments in the black-n-white image using probabalistic Hough transform -CV_EXPORTS void HoughLinesP(const GpuMat& image, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096); - -//! HoughCircles - -struct HoughCirclesBuf -{ - GpuMat edges; - GpuMat accum; - GpuMat list; - CannyBuf cannyBuf; -}; - -CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096); -CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096); -CV_EXPORTS void HoughCirclesDownload(const GpuMat& d_circles, OutputArray h_circles); - -//! finds arbitrary template in the grayscale image using Generalized Hough Transform -//! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. -//! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038. -class CV_EXPORTS GeneralizedHough_GPU : public cv::Algorithm -{ -public: - static Ptr create(int method); - - virtual ~GeneralizedHough_GPU(); - - //! set template to search - void setTemplate(const GpuMat& templ, int cannyThreshold = 100, Point templCenter = Point(-1, -1)); - void setTemplate(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, Point templCenter = Point(-1, -1)); - - //! find template on image - void detect(const GpuMat& image, GpuMat& positions, int cannyThreshold = 100); - void detect(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, GpuMat& positions); - - void download(const GpuMat& d_positions, OutputArray h_positions, OutputArray h_votes = noArray()); - - void release(); - -protected: - virtual void setTemplateImpl(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, Point templCenter) = 0; - virtual void detectImpl(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, GpuMat& positions) = 0; - virtual void releaseImpl() = 0; - -private: - GpuMat edges_; - CannyBuf cannyBuf_; -}; - -////////////////////////////// Matrix reductions ////////////////////////////// - -//! computes mean value and standard deviation of all or selected array elements -//! supports only CV_8UC1 type -CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev); -//! buffered version -CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev, GpuMat& buf); - -//! computes norm of array -//! supports NORM_INF, NORM_L1, NORM_L2 -//! supports all matrices except 64F -CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2); -CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf); -CV_EXPORTS double norm(const GpuMat& src1, int normType, const GpuMat& mask, GpuMat& buf); - -//! computes norm of the difference between two arrays -//! supports NORM_INF, NORM_L1, NORM_L2 -//! supports only CV_8UC1 type -CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2); - -//! computes sum of array elements -//! supports only single channel images -CV_EXPORTS Scalar sum(const GpuMat& src); -CV_EXPORTS Scalar sum(const GpuMat& src, GpuMat& buf); -CV_EXPORTS Scalar sum(const GpuMat& src, const GpuMat& mask, GpuMat& buf); - -//! computes sum of array elements absolute values -//! supports only single channel images -CV_EXPORTS Scalar absSum(const GpuMat& src); -CV_EXPORTS Scalar absSum(const GpuMat& src, GpuMat& buf); -CV_EXPORTS Scalar absSum(const GpuMat& src, const GpuMat& mask, GpuMat& buf); - -//! computes squared sum of array elements -//! supports only single channel images -CV_EXPORTS Scalar sqrSum(const GpuMat& src); -CV_EXPORTS Scalar sqrSum(const GpuMat& src, GpuMat& buf); -CV_EXPORTS Scalar sqrSum(const GpuMat& src, const GpuMat& mask, GpuMat& buf); - -//! finds global minimum and maximum array elements and returns their values -CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat()); -CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf); - -//! finds global minimum and maximum array elements and returns their values with locations -CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, - const GpuMat& mask=GpuMat()); -CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, - const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf); - -//! counts non-zero array elements -CV_EXPORTS int countNonZero(const GpuMat& src); -CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf); - -//! reduces a matrix to a vector -CV_EXPORTS void reduce(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null()); - - -///////////////////////////// Calibration 3D ////////////////////////////////// - -CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec, - GpuMat& dst, Stream& stream = Stream::Null()); - -CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec, - const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst, - Stream& stream = Stream::Null()); - -CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat, - const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false, - int num_iters=100, float max_dist=8.0, int min_inlier_count=100, - std::vector* inliers=NULL); - -//////////////////////////////// Image Labeling //////////////////////////////// - -//!performs labeling via graph cuts of a 2D regular 4-connected graph. -CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, - GpuMat& buf, Stream& stream = Stream::Null()); - -//!performs labeling via graph cuts of a 2D regular 8-connected graph. -CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight, - GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight, - GpuMat& labels, - GpuMat& buf, Stream& stream = Stream::Null()); - -//! compute mask for Generalized Flood fill componetns labeling. -CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null()); - -//! performs connected componnents labeling. -CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null()); - -////////////////////////////////// Histograms ////////////////////////////////// - -//! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type. -CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel); -//! Calculates histogram with evenly distributed bins for signle channel source. -//! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types. -//! Output hist will have one row and histSize cols and CV_32SC1 type. -CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null()); -CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, GpuMat& buf, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null()); -//! Calculates histogram with evenly distributed bins for four-channel source. -//! All channels of source are processed separately. -//! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types. -//! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type. -CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null()); -CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], GpuMat& buf, int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null()); -//! Calculates histogram with bins determined by levels array. -//! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise. -//! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types. -//! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type. -CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, Stream& stream = Stream::Null()); -CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, GpuMat& buf, Stream& stream = Stream::Null()); -//! Calculates histogram with bins determined by levels array. -//! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise. -//! All channels of source are processed separately. -//! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types. -//! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type. -CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], Stream& stream = Stream::Null()); -CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], GpuMat& buf, Stream& stream = Stream::Null()); - -//! Calculates histogram for 8u one channel image -//! Output hist will have one row, 256 cols and CV32SC1 type. -CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, Stream& stream = Stream::Null()); -CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null()); - -//! normalizes the grayscale image brightness and contrast by normalizing its histogram -CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()); -CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, Stream& stream = Stream::Null()); -CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null()); - -class CV_EXPORTS CLAHE : public cv::CLAHE -{ -public: - using cv::CLAHE::apply; - virtual void apply(InputArray src, OutputArray dst, Stream& stream) = 0; -}; -CV_EXPORTS Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); - -//////////////////////////////// StereoBM_GPU //////////////////////////////// - -class CV_EXPORTS StereoBM_GPU -{ -public: - enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 }; - - enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 }; - - //! the default constructor - StereoBM_GPU(); - //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8. - StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ); - - //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair - //! Output disparity has CV_8U type. - void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null()); - - //! Some heuristics that tries to estmate - // if current GPU will be faster than CPU in this algorithm. - // It queries current active device. - static bool checkIfGpuCallReasonable(); - - int preset; - int ndisp; - int winSize; - - // If avergeTexThreshold == 0 => post procesing is disabled - // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image - // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold - // i.e. input left image is low textured. - float avergeTexThreshold; - -private: - GpuMat minSSD, leBuf, riBuf; -}; - -////////////////////////// StereoBeliefPropagation /////////////////////////// -// "Efficient Belief Propagation for Early Vision" -// P.Felzenszwalb - -class CV_EXPORTS StereoBeliefPropagation -{ -public: - enum { DEFAULT_NDISP = 64 }; - enum { DEFAULT_ITERS = 5 }; - enum { DEFAULT_LEVELS = 5 }; - - static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels); - - //! the default constructor - explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP, - int iters = DEFAULT_ITERS, - int levels = DEFAULT_LEVELS, - int msg_type = CV_32F); - - //! the full constructor taking the number of disparities, number of BP iterations on each level, - //! number of levels, truncation of data cost, data weight, - //! truncation of discontinuity cost and discontinuity single jump - //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term) - //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term) - //! please see paper for more details - StereoBeliefPropagation(int ndisp, int iters, int levels, - float max_data_term, float data_weight, - float max_disc_term, float disc_single_jump, - int msg_type = CV_32F); - - //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair, - //! if disparity is empty output type will be CV_16S else output type will be disparity.type(). - void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null()); - - - //! version for user specified data term - void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream = Stream::Null()); - - int ndisp; - - int iters; - int levels; - - float max_data_term; - float data_weight; - float max_disc_term; - float disc_single_jump; - - int msg_type; -private: - GpuMat u, d, l, r, u2, d2, l2, r2; - std::vector datas; - GpuMat out; -}; - -/////////////////////////// StereoConstantSpaceBP /////////////////////////// -// "A Constant-Space Belief Propagation Algorithm for Stereo Matching" -// Qingxiong Yang, Liang Wang, Narendra Ahuja -// http://vision.ai.uiuc.edu/~qyang6/ - -class CV_EXPORTS StereoConstantSpaceBP -{ -public: - enum { DEFAULT_NDISP = 128 }; - enum { DEFAULT_ITERS = 8 }; - enum { DEFAULT_LEVELS = 4 }; - enum { DEFAULT_NR_PLANE = 4 }; - - static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane); - - //! the default constructor - explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP, - int iters = DEFAULT_ITERS, - int levels = DEFAULT_LEVELS, - int nr_plane = DEFAULT_NR_PLANE, - int msg_type = CV_32F); - - //! the full constructor taking the number of disparities, number of BP iterations on each level, - //! number of levels, number of active disparity on the first level, truncation of data cost, data weight, - //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold - StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane, - float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, - int min_disp_th = 0, - int msg_type = CV_32F); - - //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair, - //! if disparity is empty output type will be CV_16S else output type will be disparity.type(). - void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null()); - - int ndisp; - - int iters; - int levels; - - int nr_plane; - - float max_data_term; - float data_weight; - float max_disc_term; - float disc_single_jump; - - int min_disp_th; - - int msg_type; - - bool use_local_init_data_cost; -private: - GpuMat messages_buffers; - - GpuMat temp; - GpuMat out; -}; - -/////////////////////////// DisparityBilateralFilter /////////////////////////// -// Disparity map refinement using joint bilateral filtering given a single color image. -// Qingxiong Yang, Liang Wang, Narendra Ahuja -// http://vision.ai.uiuc.edu/~qyang6/ - -class CV_EXPORTS DisparityBilateralFilter -{ -public: - enum { DEFAULT_NDISP = 64 }; - enum { DEFAULT_RADIUS = 3 }; - enum { DEFAULT_ITERS = 1 }; - - //! the default constructor - explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS); - - //! the full constructor taking the number of disparities, filter radius, - //! number of iterations, truncation of data continuity, truncation of disparity continuity - //! and filter range sigma - DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range); - - //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image. - //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type. - void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream = Stream::Null()); - -private: - int ndisp; - int radius; - int iters; - - float edge_threshold; - float max_disc_threshold; - float sigma_range; - - GpuMat table_color; - GpuMat table_space; -}; - - -//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// -struct CV_EXPORTS HOGConfidence -{ - double scale; - std::vector locations; - std::vector confidences; - std::vector part_scores[4]; -}; - -struct CV_EXPORTS HOGDescriptor -{ - enum { DEFAULT_WIN_SIGMA = -1 }; - enum { DEFAULT_NLEVELS = 64 }; - enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL }; - - HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16), - Size block_stride=Size(8, 8), Size cell_size=Size(8, 8), - int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA, - double threshold_L2hys=0.2, bool gamma_correction=true, - int nlevels=DEFAULT_NLEVELS); - - size_t getDescriptorSize() const; - size_t getBlockHistogramSize() const; - - void setSVMDetector(const std::vector& detector); - - static std::vector getDefaultPeopleDetector(); - static std::vector getPeopleDetector48x96(); - static std::vector getPeopleDetector64x128(); - - void detect(const GpuMat& img, std::vector& found_locations, - double hit_threshold=0, Size win_stride=Size(), - Size padding=Size()); - - void detectMultiScale(const GpuMat& img, std::vector& found_locations, - double hit_threshold=0, Size win_stride=Size(), - Size padding=Size(), double scale0=1.05, - int group_threshold=2); - - void computeConfidence(const GpuMat& img, std::vector& hits, double hit_threshold, - Size win_stride, Size padding, std::vector& locations, std::vector& confidences); - - void computeConfidenceMultiScale(const GpuMat& img, std::vector& found_locations, - double hit_threshold, Size win_stride, Size padding, - std::vector &conf_out, int group_threshold); - - void getDescriptors(const GpuMat& img, Size win_stride, - GpuMat& descriptors, - int descr_format=DESCR_FORMAT_COL_BY_COL); - - Size win_size; - Size block_size; - Size block_stride; - Size cell_size; - int nbins; - double win_sigma; - double threshold_L2hys; - bool gamma_correction; - int nlevels; - -protected: - void computeBlockHistograms(const GpuMat& img); - void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle); - - double getWinSigma() const; - bool checkDetectorSize() const; - - static int numPartsWithin(int size, int part_size, int stride); - static Size numPartsWithin(Size size, Size part_size, Size stride); - - // Coefficients of the separating plane - float free_coef; - GpuMat detector; - - // Results of the last classification step - GpuMat labels, labels_buf; - Mat labels_host; - - // Results of the last histogram evaluation step - GpuMat block_hists, block_hists_buf; - - // Gradients conputation results - GpuMat grad, qangle, grad_buf, qangle_buf; - - // returns subbuffer with required size, reallocates buffer if nessesary. - static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf); - static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf); - - std::vector image_scales; -}; - - -////////////////////////////////// BruteForceMatcher ////////////////////////////////// - -class CV_EXPORTS BFMatcher_GPU -{ -public: - explicit BFMatcher_GPU(int norm = cv::NORM_L2); - - // Add descriptors to train descriptor collection - void add(const std::vector& descCollection); - - // Get train descriptors collection - const std::vector& getTrainDescriptors() const; - - // Clear train descriptors collection - void clear(); - - // Return true if there are not train descriptors in collection - bool empty() const; - - // Return true if the matcher supports mask in match methods - bool isMaskSupported() const; - - // Find one best match for each query descriptor - void matchSingle(const GpuMat& query, const GpuMat& train, - GpuMat& trainIdx, GpuMat& distance, - const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); - - // Download trainIdx and distance and convert it to CPU vector with DMatch - static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector& matches); - // Convert trainIdx and distance to vector with DMatch - static void matchConvert(const Mat& trainIdx, const Mat& distance, std::vector& matches); - - // Find one best match for each query descriptor - void match(const GpuMat& query, const GpuMat& train, std::vector& matches, const GpuMat& mask = GpuMat()); - - // Make gpu collection of trains and masks in suitable format for matchCollection function - void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const std::vector& masks = std::vector()); - - // Find one best match from train collection for each query descriptor - void matchCollection(const GpuMat& query, const GpuMat& trainCollection, - GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, - const GpuMat& masks = GpuMat(), Stream& stream = Stream::Null()); - - // Download trainIdx, imgIdx and distance and convert it to vector with DMatch - static void matchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, std::vector& matches); - // Convert trainIdx, imgIdx and distance to vector with DMatch - static void matchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector& matches); - - // Find one best match from train collection for each query descriptor. - void match(const GpuMat& query, std::vector& matches, const std::vector& masks = std::vector()); - - // Find k best matches for each query descriptor (in increasing order of distances) - void knnMatchSingle(const GpuMat& query, const GpuMat& train, - GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, - const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); - - // Download trainIdx and distance and convert it to vector with DMatch - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, - std::vector< std::vector >& matches, bool compactResult = false); - // Convert trainIdx and distance to vector with DMatch - static void knnMatchConvert(const Mat& trainIdx, const Mat& distance, - std::vector< std::vector >& matches, bool compactResult = false); - - // Find k best matches for each query descriptor (in increasing order of distances). - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - void knnMatch(const GpuMat& query, const GpuMat& train, - std::vector< std::vector >& matches, int k, const GpuMat& mask = GpuMat(), - bool compactResult = false); - - // Find k best matches from train collection for each query descriptor (in increasing order of distances) - void knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection, - GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, - const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null()); - - // Download trainIdx and distance and convert it to vector with DMatch - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - static void knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, - std::vector< std::vector >& matches, bool compactResult = false); - // Convert trainIdx and distance to vector with DMatch - static void knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, - std::vector< std::vector >& matches, bool compactResult = false); - - // Find k best matches for each query descriptor (in increasing order of distances). - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - void knnMatch(const GpuMat& query, std::vector< std::vector >& matches, int k, - const std::vector& masks = std::vector(), bool compactResult = false); - - // Find best matches for each query descriptor which have distance less than maxDistance. - // nMatches.at(0, queryIdx) will contain matches count for queryIdx. - // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches, - // because it didn't have enough memory. - // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nTrain / 100), 10), - // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches - // Matches doesn't sorted. - void radiusMatchSingle(const GpuMat& query, const GpuMat& train, - GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, - const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); - - // Download trainIdx, nMatches and distance and convert it to vector with DMatch. - // matches will be sorted in increasing order of distances. - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches, - std::vector< std::vector >& matches, bool compactResult = false); - // Convert trainIdx, nMatches and distance to vector with DMatch. - static void radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches, - std::vector< std::vector >& matches, bool compactResult = false); - - // Find best matches for each query descriptor which have distance less than maxDistance - // in increasing order of distances). - void radiusMatch(const GpuMat& query, const GpuMat& train, - std::vector< std::vector >& matches, float maxDistance, - const GpuMat& mask = GpuMat(), bool compactResult = false); - - // Find best matches for each query descriptor which have distance less than maxDistance. - // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nQuery / 100), 10), - // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches - // Matches doesn't sorted. - void radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, - const std::vector& masks = std::vector(), Stream& stream = Stream::Null()); - - // Download trainIdx, imgIdx, nMatches and distance and convert it to vector with DMatch. - // matches will be sorted in increasing order of distances. - // compactResult is used when mask is not empty. If compactResult is false matches - // vector will have the same size as queryDescriptors rows. If compactResult is true - // matches vector will not contain matches for fully masked out query descriptors. - static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches, - std::vector< std::vector >& matches, bool compactResult = false); - // Convert trainIdx, nMatches and distance to vector with DMatch. - static void radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches, - std::vector< std::vector >& matches, bool compactResult = false); - - // Find best matches from train collection for each query descriptor which have distance less than - // maxDistance (in increasing order of distances). - void radiusMatch(const GpuMat& query, std::vector< std::vector >& matches, float maxDistance, - const std::vector& masks = std::vector(), bool compactResult = false); - - int norm; - -private: - std::vector trainDescCollection; -}; - -template -class CV_EXPORTS BruteForceMatcher_GPU; - -template -class CV_EXPORTS BruteForceMatcher_GPU< L1 > : public BFMatcher_GPU -{ -public: - explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L1) {} - explicit BruteForceMatcher_GPU(L1 /*d*/) : BFMatcher_GPU(NORM_L1) {} -}; -template -class CV_EXPORTS BruteForceMatcher_GPU< L2 > : public BFMatcher_GPU -{ -public: - explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L2) {} - explicit BruteForceMatcher_GPU(L2 /*d*/) : BFMatcher_GPU(NORM_L2) {} -}; -template <> class CV_EXPORTS BruteForceMatcher_GPU< Hamming > : public BFMatcher_GPU -{ -public: - explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_HAMMING) {} - explicit BruteForceMatcher_GPU(Hamming /*d*/) : BFMatcher_GPU(NORM_HAMMING) {} -}; - -////////////////////////////////// CascadeClassifier_GPU ////////////////////////////////////////// -// The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny. -class CV_EXPORTS CascadeClassifier_GPU -{ -public: - CascadeClassifier_GPU(); - CascadeClassifier_GPU(const String& filename); - ~CascadeClassifier_GPU(); - - bool empty() const; - bool load(const String& filename); - void release(); - - /* returns number of detected objects */ - int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.2, int minNeighbors = 4, Size minSize = Size()); - int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4); - - bool findLargestObject; - bool visualizeInPlace; - - Size getClassifierSize() const; - -private: - struct CascadeClassifierImpl; - CascadeClassifierImpl* impl; - struct HaarCascade; - struct LbpCascade; - friend class CascadeClassifier_GPU_LBP; -}; - -////////////////////////////////// FAST ////////////////////////////////////////// - -class CV_EXPORTS FAST_GPU -{ -public: - enum - { - LOCATION_ROW = 0, - RESPONSE_ROW, - ROWS_COUNT - }; - - // all features have same size - static const int FEATURE_SIZE = 7; - - explicit FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05); - - //! finds the keypoints using FAST detector - //! supports only CV_8UC1 images - void operator ()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints); - void operator ()(const GpuMat& image, const GpuMat& mask, std::vector& keypoints); - - //! download keypoints from device to host memory - static void downloadKeypoints(const GpuMat& d_keypoints, std::vector& keypoints); - - //! convert keypoints to KeyPoint vector - static void convertKeypoints(const Mat& h_keypoints, std::vector& keypoints); - - //! release temporary buffer's memory - void release(); - - bool nonmaxSupression; - - int threshold; - - //! max keypoints = keypointsRatio * img.size().area() - double keypointsRatio; - - //! find keypoints and compute it's response if nonmaxSupression is true - //! return count of detected keypoints - int calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask); - - //! get final array of keypoints - //! performs nonmax supression if needed - //! return final count of keypoints - int getKeyPoints(GpuMat& keypoints); - -private: - GpuMat kpLoc_; - int count_; - - GpuMat score_; - - GpuMat d_keypoints_; -}; - -////////////////////////////////// ORB ////////////////////////////////////////// - -class CV_EXPORTS ORB_GPU -{ -public: - enum - { - X_ROW = 0, - Y_ROW, - RESPONSE_ROW, - ANGLE_ROW, - OCTAVE_ROW, - SIZE_ROW, - ROWS_COUNT - }; - - enum - { - DEFAULT_FAST_THRESHOLD = 20 - }; - - //! Constructor - explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31, - int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31); - - //! Compute the ORB features on an image - //! image - the image to compute the features (supports only CV_8UC1 images) - //! mask - the mask to apply - //! keypoints - the resulting keypoints - void operator()(const GpuMat& image, const GpuMat& mask, std::vector& keypoints); - void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints); - - //! Compute the ORB features and descriptors on an image - //! image - the image to compute the features (supports only CV_8UC1 images) - //! mask - the mask to apply - //! keypoints - the resulting keypoints - //! descriptors - descriptors array - void operator()(const GpuMat& image, const GpuMat& mask, std::vector& keypoints, GpuMat& descriptors); - void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors); - - //! download keypoints from device to host memory - static void downloadKeyPoints(const GpuMat& d_keypoints, std::vector& keypoints); - //! convert keypoints to KeyPoint vector - static void convertKeyPoints(const Mat& d_keypoints, std::vector& keypoints); - - //! returns the descriptor size in bytes - inline int descriptorSize() const { return kBytes; } - - inline void setFastParams(int threshold, bool nonmaxSupression = true) - { - fastDetector_.threshold = threshold; - fastDetector_.nonmaxSupression = nonmaxSupression; - } - - //! release temporary buffer's memory - void release(); - - //! if true, image will be blurred before descriptors calculation - bool blurForDescriptor; - -private: - enum { kBytes = 32 }; - - void buildScalePyramids(const GpuMat& image, const GpuMat& mask); - - void computeKeyPointsPyramid(); - - void computeDescriptors(GpuMat& descriptors); - - void mergeKeyPoints(GpuMat& keypoints); - - int nFeatures_; - float scaleFactor_; - int nLevels_; - int edgeThreshold_; - int firstLevel_; - int WTA_K_; - int scoreType_; - int patchSize_; - - // The number of desired features per scale - std::vector n_features_per_level_; - - // Points to compute BRIEF descriptors from - GpuMat pattern_; - - std::vector imagePyr_; - std::vector maskPyr_; - - GpuMat buf_; - - std::vector keyPointsPyr_; - std::vector keyPointsCount_; - - FAST_GPU fastDetector_; - - Ptr blurFilter; - - GpuMat d_keypoints_; -}; - -////////////////////////////////// Optical Flow ////////////////////////////////////////// - -class CV_EXPORTS BroxOpticalFlow -{ -public: - BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) : - alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_), - inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_) - { - } - - //! Compute optical flow - //! frame0 - source frame (supports only CV_32FC1 type) - //! frame1 - frame to track (with the same size and type as frame0) - //! u - flow horizontal component (along x axis) - //! v - flow vertical component (along y axis) - void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); - - //! flow smoothness - float alpha; - - //! gradient constancy importance - float gamma; - - //! pyramid scale factor - float scale_factor; - - //! number of lagged non-linearity iterations (inner loop) - int inner_iterations; - - //! number of warping iterations (number of pyramid levels) - int outer_iterations; - - //! number of linear system solver iterations - int solver_iterations; - - GpuMat buf; -}; - -class CV_EXPORTS GoodFeaturesToTrackDetector_GPU -{ -public: - explicit GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0, - int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04); - - //! return 1 rows matrix with CV_32FC2 type - void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat()); - - int maxCorners; - double qualityLevel; - double minDistance; - - int blockSize; - bool useHarrisDetector; - double harrisK; - - void releaseMemory() - { - Dx_.release(); - Dy_.release(); - buf_.release(); - eig_.release(); - minMaxbuf_.release(); - tmpCorners_.release(); - } - -private: - GpuMat Dx_; - GpuMat Dy_; - GpuMat buf_; - GpuMat eig_; - GpuMat minMaxbuf_; - GpuMat tmpCorners_; -}; - -inline GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners_, double qualityLevel_, double minDistance_, - int blockSize_, bool useHarrisDetector_, double harrisK_) -{ - maxCorners = maxCorners_; - qualityLevel = qualityLevel_; - minDistance = minDistance_; - blockSize = blockSize_; - useHarrisDetector = useHarrisDetector_; - harrisK = harrisK_; -} - - -class CV_EXPORTS PyrLKOpticalFlow -{ -public: - PyrLKOpticalFlow(); - - void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, - GpuMat& status, GpuMat* err = 0); - - void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0); - - void releaseMemory(); - - Size winSize; - int maxLevel; - int iters; - bool useInitialFlow; - -private: - std::vector prevPyr_; - std::vector nextPyr_; - - GpuMat buf_; - - GpuMat uPyr_[2]; - GpuMat vPyr_[2]; -}; - - -class CV_EXPORTS FarnebackOpticalFlow -{ -public: - FarnebackOpticalFlow() - { - numLevels = 5; - pyrScale = 0.5; - fastPyramids = false; - winSize = 13; - numIters = 10; - polyN = 5; - polySigma = 1.1; - flags = 0; - } - - int numLevels; - double pyrScale; - bool fastPyramids; - int winSize; - int numIters; - int polyN; - double polySigma; - int flags; - - void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null()); - - void releaseMemory() - { - frames_[0].release(); - frames_[1].release(); - pyrLevel_[0].release(); - pyrLevel_[1].release(); - M_.release(); - bufM_.release(); - R_[0].release(); - R_[1].release(); - blurredFrame_[0].release(); - blurredFrame_[1].release(); - pyramid0_.clear(); - pyramid1_.clear(); - } - -private: - void prepareGaussian( - int n, double sigma, float *g, float *xg, float *xxg, - double &ig11, double &ig03, double &ig33, double &ig55); - - void setPolynomialExpansionConsts(int n, double sigma); - - void updateFlow_boxFilter( - const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy, - GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); - - void updateFlow_gaussianBlur( - const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy, - GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]); - - GpuMat frames_[2]; - GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2]; - std::vector pyramid0_, pyramid1_; -}; - - -// Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method -// -// see reference: -// [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". -// [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". -class CV_EXPORTS OpticalFlowDual_TVL1_GPU -{ -public: - OpticalFlowDual_TVL1_GPU(); - - void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy); - - void collectGarbage(); - - /** - * Time step of the numerical scheme. - */ - double tau; - - /** - * Weight parameter for the data term, attachment parameter. - * This is the most relevant parameter, which determines the smoothness of the output. - * The smaller this parameter is, the smoother the solutions we obtain. - * It depends on the range of motions of the images, so its value should be adapted to each image sequence. - */ - double lambda; - - /** - * Weight parameter for (u - v)^2, tightness parameter. - * It serves as a link between the attachment and the regularization terms. - * In theory, it should have a small value in order to maintain both parts in correspondence. - * The method is stable for a large range of values of this parameter. - */ - double theta; +#if !defined(__OPENCV_BUILD) && !defined(OPENCV_GPU_SKIP_INCLUDE) + #include "opencv2/opencv_modules.hpp" - /** - * Number of scales used to create the pyramid of images. - */ - int nscales; + #ifdef HAVE_OPENCV_GPUARITHM + #include "opencv2/gpuarithm.hpp" + #endif - /** - * Number of warpings per scale. - * Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale. - * This is a parameter that assures the stability of the method. - * It also affects the running time, so it is a compromise between speed and accuracy. - */ - int warps; + #ifdef HAVE_OPENCV_GPUWARPING + #include "opencv2/gpuwarping.hpp" + #endif - /** - * Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time. - * A small value will yield more accurate solutions at the expense of a slower convergence. - */ - double epsilon; + #ifdef HAVE_OPENCV_GPUFILTERS + #include "opencv2/gpufilters.hpp" + #endif - /** - * Stopping criterion iterations number used in the numerical scheme. - */ - int iterations; + #ifdef HAVE_OPENCV_GPUIMGPROC + #include "opencv2/gpuimgproc.hpp" + #endif - double scaleStep; + #ifdef HAVE_OPENCV_GPUFEATURES2D + #include "opencv2/gpufeatures2d.hpp" + #endif - bool useInitialFlow; + #ifdef HAVE_OPENCV_GPUOPTFLOW + #include "opencv2/gpuoptflow.hpp" + #endif -private: - void procOneScale(const GpuMat& I0, const GpuMat& I1, GpuMat& u1, GpuMat& u2); - - std::vector I0s; - std::vector I1s; - std::vector u1s; - std::vector u2s; - - GpuMat I1x_buf; - GpuMat I1y_buf; - - GpuMat I1w_buf; - GpuMat I1wx_buf; - GpuMat I1wy_buf; + #ifdef HAVE_OPENCV_GPUBGSEGM + #include "opencv2/gpubgsegm.hpp" + #endif - GpuMat grad_buf; - GpuMat rho_c_buf; + #ifdef HAVE_OPENCV_GPUSTEREO + #include "opencv2/gpustereo.hpp" + #endif - GpuMat p11_buf; - GpuMat p12_buf; - GpuMat p21_buf; - GpuMat p22_buf; - - GpuMat diff_buf; - GpuMat norm_buf; -}; + #ifdef HAVE_OPENCV_GPUCODEC + #include "opencv2/gpucodec.hpp" + #endif +#endif +namespace cv { namespace gpu { -//! Calculates optical flow for 2 images using block matching algorithm */ -CV_EXPORTS void calcOpticalFlowBM(const GpuMat& prev, const GpuMat& curr, - Size block_size, Size shift_size, Size max_range, bool use_previous, - GpuMat& velx, GpuMat& vely, GpuMat& buf, - Stream& stream = Stream::Null()); +//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// -class CV_EXPORTS FastOpticalFlowBM +struct CV_EXPORTS HOGConfidence { -public: - void operator ()(const GpuMat& I0, const GpuMat& I1, GpuMat& flowx, GpuMat& flowy, int search_window = 21, int block_window = 7, Stream& s = Stream::Null()); - -private: - GpuMat buffer; - GpuMat extended_I0; - GpuMat extended_I1; + double scale; + std::vector locations; + std::vector confidences; + std::vector part_scores[4]; }; - -//! Interpolate frames (images) using provided optical flow (displacement field). -//! frame0 - frame 0 (32-bit floating point images, single channel) -//! frame1 - frame 1 (the same type and size) -//! fu - forward horizontal displacement -//! fv - forward vertical displacement -//! bu - backward horizontal displacement -//! bv - backward vertical displacement -//! pos - new frame position -//! newFrame - new frame -//! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat; -//! occlusion masks 0, occlusion masks 1, -//! interpolated forward flow 0, interpolated forward flow 1, -//! interpolated backward flow 0, interpolated backward flow 1 -//! -CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, - const GpuMat& fu, const GpuMat& fv, - const GpuMat& bu, const GpuMat& bv, - float pos, GpuMat& newFrame, GpuMat& buf, - Stream& stream = Stream::Null()); - -CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors); - - -//////////////////////// Background/foreground segmentation //////////////////////// - -// Foreground Object Detection from Videos Containing Complex Background. -// Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. -// ACM MM2003 9p -class CV_EXPORTS FGDStatModel +struct CV_EXPORTS HOGDescriptor { -public: - struct CV_EXPORTS Params - { - int Lc; // Quantized levels per 'color' component. Power of two, typically 32, 64 or 128. - int N1c; // Number of color vectors used to model normal background color variation at a given pixel. - int N2c; // Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c. - // Used to allow the first N1c vectors to adapt over time to changing background. - - int Lcc; // Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64. - int N1cc; // Number of color co-occurrence vectors used to model normal background color variation at a given pixel. - int N2cc; // Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc. - // Used to allow the first N1cc vectors to adapt over time to changing background. - - bool is_obj_without_holes; // If TRUE we ignore holes within foreground blobs. Defaults to TRUE. - int perform_morphing; // Number of erode-dilate-erode foreground-blob cleanup iterations. - // These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1. - - float alpha1; // How quickly we forget old background pixel values seen. Typically set to 0.1. - float alpha2; // "Controls speed of feature learning". Depends on T. Typical value circa 0.005. - float alpha3; // Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1. - - float delta; // Affects color and color co-occurrence quantization, typically set to 2. - float T; // A percentage value which determines when new features can be recognized as new background. (Typically 0.9). - float minArea; // Discard foreground blobs whose bounding box is smaller than this threshold. - - // default Params - Params(); - }; + enum { DEFAULT_WIN_SIGMA = -1 }; + enum { DEFAULT_NLEVELS = 64 }; + enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL }; - // out_cn - channels count in output result (can be 3 or 4) - // 4-channels require more memory, but a bit faster - explicit FGDStatModel(int out_cn = 3); - explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3); + HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16), + Size block_stride=Size(8, 8), Size cell_size=Size(8, 8), + int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA, + double threshold_L2hys=0.2, bool gamma_correction=true, + int nlevels=DEFAULT_NLEVELS); - ~FGDStatModel(); + size_t getDescriptorSize() const; + size_t getBlockHistogramSize() const; - void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params()); - void release(); + void setSVMDetector(const std::vector& detector); - int update(const cv::gpu::GpuMat& curFrame); + static std::vector getDefaultPeopleDetector(); + static std::vector getPeopleDetector48x96(); + static std::vector getPeopleDetector64x128(); - //8UC3 or 8UC4 reference background image - cv::gpu::GpuMat background; + void detect(const GpuMat& img, std::vector& found_locations, + double hit_threshold=0, Size win_stride=Size(), + Size padding=Size()); - //8UC1 foreground image - cv::gpu::GpuMat foreground; + void detectMultiScale(const GpuMat& img, std::vector& found_locations, + double hit_threshold=0, Size win_stride=Size(), + Size padding=Size(), double scale0=1.05, + int group_threshold=2); - std::vector< std::vector > foreground_regions; + void computeConfidence(const GpuMat& img, std::vector& hits, double hit_threshold, + Size win_stride, Size padding, std::vector& locations, std::vector& confidences); -private: - FGDStatModel(const FGDStatModel&); - FGDStatModel& operator=(const FGDStatModel&); + void computeConfidenceMultiScale(const GpuMat& img, std::vector& found_locations, + double hit_threshold, Size win_stride, Size padding, + std::vector &conf_out, int group_threshold); - class Impl; - std::auto_ptr impl_; -}; + void getDescriptors(const GpuMat& img, Size win_stride, + GpuMat& descriptors, + int descr_format=DESCR_FORMAT_COL_BY_COL); -/*! - Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm + Size win_size; + Size block_size; + Size block_stride; + Size cell_size; + int nbins; + double win_sigma; + double threshold_L2hys; + bool gamma_correction; + int nlevels; - The class implements the following algorithm: - "An improved adaptive background mixture model for real-time tracking with shadow detection" - P. KadewTraKuPong and R. Bowden, - Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001." - http://personal.ee.surrey.ac.uk/Personal/R.Bowden/publications/avbs01/avbs01.pdf -*/ -class CV_EXPORTS MOG_GPU -{ -public: - //! the default constructor - MOG_GPU(int nmixtures = -1); +protected: + void computeBlockHistograms(const GpuMat& img); + void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle); - //! re-initiaization method - void initialize(Size frameSize, int frameType); + double getWinSigma() const; + bool checkDetectorSize() const; - //! the update operator - void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null()); + static int numPartsWithin(int size, int part_size, int stride); + static Size numPartsWithin(Size size, Size part_size, Size stride); - //! computes a background image which are the mean of all background gaussians - void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const; + // Coefficients of the separating plane + float free_coef; + GpuMat detector; - //! releases all inner buffers - void release(); + // Results of the last classification step + GpuMat labels, labels_buf; + Mat labels_host; - int history; - float varThreshold; - float backgroundRatio; - float noiseSigma; + // Results of the last histogram evaluation step + GpuMat block_hists, block_hists_buf; -private: - int nmixtures_; + // Gradients conputation results + GpuMat grad, qangle, grad_buf, qangle_buf; - Size frameSize_; - int frameType_; - int nframes_; + // returns subbuffer with required size, reallocates buffer if nessesary. + static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf); + static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf); - GpuMat weight_; - GpuMat sortKey_; - GpuMat mean_; - GpuMat var_; + std::vector image_scales; }; -/*! - The class implements the following algorithm: - "Improved adaptive Gausian mixture model for background subtraction" - Z.Zivkovic - International Conference Pattern Recognition, UK, August, 2004. - http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf -*/ -class CV_EXPORTS MOG2_GPU -{ -public: - //! the default constructor - MOG2_GPU(int nmixtures = -1); - - //! re-initiaization method - void initialize(Size frameSize, int frameType); - - //! the update operator - void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null()); - - //! computes a background image which are the mean of all background gaussians - void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const; - - //! releases all inner buffers - void release(); - - // parameters - // you should call initialize after parameters changes - - int history; - - //! here it is the maximum allowed number of mixture components. - //! Actual number is determined dynamically per pixel - float varThreshold; - // threshold on the squared Mahalanobis distance to decide if it is well described - // by the background model or not. Related to Cthr from the paper. - // This does not influence the update of the background. A typical value could be 4 sigma - // and that is varThreshold=4*4=16; Corresponds to Tb in the paper. - - ///////////////////////// - // less important parameters - things you might change but be carefull - //////////////////////// - - float backgroundRatio; - // corresponds to fTB=1-cf from the paper - // TB - threshold when the component becomes significant enough to be included into - // the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0. - // For alpha=0.001 it means that the mode should exist for approximately 105 frames before - // it is considered foreground - // float noiseSigma; - float varThresholdGen; - - //correspondts to Tg - threshold on the squared Mahalan. dist. to decide - //when a sample is close to the existing components. If it is not close - //to any a new component will be generated. I use 3 sigma => Tg=3*3=9. - //Smaller Tg leads to more generated components and higher Tg might make - //lead to small number of components but they can grow too large - float fVarInit; - float fVarMin; - float fVarMax; - - //initial variance for the newly generated components. - //It will will influence the speed of adaptation. A good guess should be made. - //A simple way is to estimate the typical standard deviation from the images. - //I used here 10 as a reasonable value - // min and max can be used to further control the variance - float fCT; //CT - complexity reduction prior - //this is related to the number of samples needed to accept that a component - //actually exists. We use CT=0.05 of all the samples. By setting CT=0 you get - //the standard Stauffer&Grimson algorithm (maybe not exact but very similar) - - //shadow detection parameters - bool bShadowDetection; //default 1 - do shadow detection - unsigned char nShadowDetection; //do shadow detection - insert this value as the detection result - 127 default value - float fTau; - // Tau - shadow threshold. The shadow is detected if the pixel is darker - //version of the background. Tau is a threshold on how much darker the shadow can be. - //Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow - //See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003. - -private: - int nmixtures_; - - Size frameSize_; - int frameType_; - int nframes_; - - GpuMat weight_; - GpuMat variance_; - GpuMat mean_; - - GpuMat bgmodelUsedModes_; //keep track of number of modes per pixel -}; +//////////////////////////// CascadeClassifier //////////////////////////// -/** - * Background Subtractor module. Takes a series of images and returns a sequence of mask (8UC1) - * images of the same size, where 255 indicates Foreground and 0 represents Background. - * This class implements an algorithm described in "Visual Tracking of Human Visitors under - * Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere, - * A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012. - */ -class CV_EXPORTS GMG_GPU +// The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny. +class CV_EXPORTS CascadeClassifier_GPU { public: - GMG_GPU(); - - /** - * Validate parameters and set up data structures for appropriate frame size. - * @param frameSize Input frame size - * @param min Minimum value taken on by pixels in image sequence. Usually 0 - * @param max Maximum value taken on by pixels in image sequence. e.g. 1.0 or 255 - */ - void initialize(Size frameSize, float min = 0.0f, float max = 255.0f); - - /** - * Performs single-frame background subtraction and builds up a statistical background image - * model. - * @param frame Input frame - * @param fgmask Output mask image representing foreground and background pixels - * @param stream Stream for the asynchronous version - */ - void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null()); + CascadeClassifier_GPU(); + CascadeClassifier_GPU(const String& filename); + ~CascadeClassifier_GPU(); - //! Releases all inner buffers + bool empty() const; + bool load(const String& filename); void release(); - //! Total number of distinct colors to maintain in histogram. - int maxFeatures; - - //! Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms. - float learningRate; - - //! Number of frames of video to use to initialize histograms. - int numInitializationFrames; - - //! Number of discrete levels in each channel to be used in histograms. - int quantizationLevels; - - //! Prior probability that any given pixel is a background pixel. A sensitivity parameter. - float backgroundPrior; - - //! Value above which pixel is determined to be FG. - float decisionThreshold; - - //! Smoothing radius, in pixels, for cleaning up FG image. - int smoothingRadius; - - //! Perform background model update. - bool updateBackgroundModel; - -private: - float maxVal_, minVal_; - - Size frameSize_; - - int frameNum_; - - GpuMat nfeatures_; - GpuMat colors_; - GpuMat weights_; - - Ptr boxFilter_; - GpuMat buf_; -}; - -////////////////////////////////// Video Encoding ////////////////////////////////// - -// Works only under Windows -// Supports olny H264 video codec and AVI files -class CV_EXPORTS VideoWriter_GPU -{ -public: - struct EncoderParams; - - // Callbacks for video encoder, use it if you want to work with raw video stream - class EncoderCallBack; - - enum SurfaceFormat - { - SF_UYVY = 0, - SF_YUY2, - SF_YV12, - SF_NV12, - SF_IYUV, - SF_BGR, - SF_GRAY = SF_BGR - }; - - VideoWriter_GPU(); - VideoWriter_GPU(const String& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR); - VideoWriter_GPU(const String& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR); - VideoWriter_GPU(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR); - VideoWriter_GPU(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR); - ~VideoWriter_GPU(); - - // all methods throws cv::Exception if error occurs - void open(const String& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR); - void open(const String& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR); - void open(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR); - void open(const cv::Ptr& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR); - - bool isOpened() const; - void close(); - - void write(const cv::gpu::GpuMat& image, bool lastFrame = false); - - struct CV_EXPORTS EncoderParams - { - int P_Interval; // NVVE_P_INTERVAL, - int IDR_Period; // NVVE_IDR_PERIOD, - int DynamicGOP; // NVVE_DYNAMIC_GOP, - int RCType; // NVVE_RC_TYPE, - int AvgBitrate; // NVVE_AVG_BITRATE, - int PeakBitrate; // NVVE_PEAK_BITRATE, - int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA, - int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P, - int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B, - int DeblockMode; // NVVE_DEBLOCK_MODE, - int ProfileLevel; // NVVE_PROFILE_LEVEL, - int ForceIntra; // NVVE_FORCE_INTRA, - int ForceIDR; // NVVE_FORCE_IDR, - int ClearStat; // NVVE_CLEAR_STAT, - int DIMode; // NVVE_SET_DEINTERLACE, - int Presets; // NVVE_PRESETS, - int DisableCabac; // NVVE_DISABLE_CABAC, - int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE - int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS - - EncoderParams(); - explicit EncoderParams(const String& configFile); - - void load(const String& configFile); - void save(const String& configFile) const; - }; - - EncoderParams getParams() const; - - class CV_EXPORTS EncoderCallBack - { - public: - enum PicType - { - IFRAME = 1, - PFRAME = 2, - BFRAME = 3 - }; - - virtual ~EncoderCallBack() {} - - // callback function to signal the start of bitstream that is to be encoded - // must return pointer to buffer - virtual uchar* acquireBitStream(int* bufferSize) = 0; - - // callback function to signal that the encoded bitstream is ready to be written to file - virtual void releaseBitStream(unsigned char* data, int size) = 0; + /* returns number of detected objects */ + int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.2, int minNeighbors = 4, Size minSize = Size()); + int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4); - // callback function to signal that the encoding operation on the frame has started - virtual void onBeginFrame(int frameNumber, PicType picType) = 0; + bool findLargestObject; + bool visualizeInPlace; - // callback function signals that the encoding operation on the frame has finished - virtual void onEndFrame(int frameNumber, PicType picType) = 0; - }; + Size getClassifierSize() const; private: - VideoWriter_GPU(const VideoWriter_GPU&); - VideoWriter_GPU& operator=(const VideoWriter_GPU&); - - class Impl; - std::auto_ptr impl_; + struct CascadeClassifierImpl; + CascadeClassifierImpl* impl; + struct HaarCascade; + struct LbpCascade; + friend class CascadeClassifier_GPU_LBP; }; +//////////////////////////// Labeling //////////////////////////// -////////////////////////////////// Video Decoding ////////////////////////////////////////// - -namespace detail -{ - class FrameQueue; - class VideoParser; -} - -class CV_EXPORTS VideoReader_GPU -{ -public: - enum Codec - { - MPEG1 = 0, - MPEG2, - MPEG4, - VC1, - H264, - JPEG, - H264_SVC, - H264_MVC, - - Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0) - Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0) - Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0) - Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2) - Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2) - }; - - enum ChromaFormat - { - Monochrome=0, - YUV420, - YUV422, - YUV444, - }; - - struct FormatInfo - { - Codec codec; - ChromaFormat chromaFormat; - int width; - int height; - }; - - class VideoSource; - - VideoReader_GPU(); - explicit VideoReader_GPU(const String& filename); - explicit VideoReader_GPU(const cv::Ptr& source); - - ~VideoReader_GPU(); - - void open(const String& filename); - void open(const cv::Ptr& source); - bool isOpened() const; - - void close(); - - bool read(GpuMat& image); - - FormatInfo format() const; - void dumpFormat(std::ostream& st); +//!performs labeling via graph cuts of a 2D regular 4-connected graph. +CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, + GpuMat& buf, Stream& stream = Stream::Null()); - class CV_EXPORTS VideoSource - { - public: - VideoSource() : frameQueue_(0), videoParser_(0) {} - virtual ~VideoSource() {} +//!performs labeling via graph cuts of a 2D regular 8-connected graph. +CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight, + GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight, + GpuMat& labels, + GpuMat& buf, Stream& stream = Stream::Null()); - virtual FormatInfo format() const = 0; - virtual void start() = 0; - virtual void stop() = 0; - virtual bool isStarted() const = 0; - virtual bool hasError() const = 0; +//! compute mask for Generalized Flood fill componetns labeling. +CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null()); - void setFrameQueue(detail::FrameQueue* frameQueue) { frameQueue_ = frameQueue; } - void setVideoParser(detail::VideoParser* videoParser) { videoParser_ = videoParser; } +//! performs connected componnents labeling. +CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null()); - protected: - bool parseVideoData(const uchar* data, size_t size, bool endOfStream = false); +//////////////////////////// Calib3d //////////////////////////// - private: - VideoSource(const VideoSource&); - VideoSource& operator =(const VideoSource&); +CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec, + GpuMat& dst, Stream& stream = Stream::Null()); - detail::FrameQueue* frameQueue_; - detail::VideoParser* videoParser_; - }; +CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec, + const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst, + Stream& stream = Stream::Null()); -private: - VideoReader_GPU(const VideoReader_GPU&); - VideoReader_GPU& operator =(const VideoReader_GPU&); +CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat, + const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false, + int num_iters=100, float max_dist=8.0, int min_inlier_count=100, + std::vector* inliers=NULL); - class Impl; - std::auto_ptr impl_; -}; +//////////////////////////// VStab //////////////////////////// //! removes points (CV_32FC2, single row matrix) with zero mask value CV_EXPORTS void compactPoints(GpuMat &points0, GpuMat &points1, const GpuMat &mask); @@ -2368,8 +255,6 @@ CV_EXPORTS void calcWobbleSuppressionMaps( int left, int idx, int right, Size size, const Mat &ml, const Mat &mr, GpuMat &mapx, GpuMat &mapy); -} // namespace gpu - -} // namespace cv +}} // namespace cv { namespace gpu { #endif /* __OPENCV_GPU_HPP__ */ diff --git a/modules/gpu/perf/perf_calib3d.cpp b/modules/gpu/perf/perf_calib3d.cpp index 725f49c..185d9cd 100644 --- a/modules/gpu/perf/perf_calib3d.cpp +++ b/modules/gpu/perf/perf_calib3d.cpp @@ -46,181 +46,8 @@ using namespace std; using namespace testing; using namespace perf; -////////////////////////////////////////////////////////////////////// -// StereoBM - -typedef std::tr1::tuple pair_string; -DEF_PARAM_TEST_1(ImagePair, pair_string); - -PERF_TEST_P(ImagePair, Calib3D_StereoBM, - Values(pair_string("gpu/perf/aloe.png", "gpu/perf/aloeR.png"))) -{ - declare.time(300.0); - - const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(imgLeft.empty()); - - const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(imgRight.empty()); - - const int preset = 0; - const int ndisp = 256; - - if (PERF_RUN_GPU()) - { - cv::gpu::StereoBM_GPU d_bm(preset, ndisp); - - const cv::gpu::GpuMat d_imgLeft(imgLeft); - const cv::gpu::GpuMat d_imgRight(imgRight); - cv::gpu::GpuMat dst; - - TEST_CYCLE() d_bm(d_imgLeft, d_imgRight, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Ptr bm = cv::createStereoBM(ndisp); - - cv::Mat dst; - - TEST_CYCLE() bm->compute(imgLeft, imgRight, dst); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// StereoBeliefPropagation - -PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, - Values(pair_string("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png"))) -{ - declare.time(300.0); - - const cv::Mat imgLeft = readImage(GET_PARAM(0)); - ASSERT_FALSE(imgLeft.empty()); - - const cv::Mat imgRight = readImage(GET_PARAM(1)); - ASSERT_FALSE(imgRight.empty()); - - const int ndisp = 64; - - if (PERF_RUN_GPU()) - { - cv::gpu::StereoBeliefPropagation d_bp(ndisp); - - const cv::gpu::GpuMat d_imgLeft(imgLeft); - const cv::gpu::GpuMat d_imgRight(imgRight); - cv::gpu::GpuMat dst; - - TEST_CYCLE() d_bp(d_imgLeft, d_imgRight, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// StereoConstantSpaceBP - -PERF_TEST_P(ImagePair, Calib3D_StereoConstantSpaceBP, - Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-R.png"))) -{ - declare.time(300.0); - - const cv::Mat imgLeft = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(imgLeft.empty()); - - const cv::Mat imgRight = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(imgRight.empty()); - - const int ndisp = 128; - - if (PERF_RUN_GPU()) - { - cv::gpu::StereoConstantSpaceBP d_csbp(ndisp); - - const cv::gpu::GpuMat d_imgLeft(imgLeft); - const cv::gpu::GpuMat d_imgRight(imgRight); - cv::gpu::GpuMat dst; - - TEST_CYCLE() d_csbp(d_imgLeft, d_imgRight, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// DisparityBilateralFilter - -PERF_TEST_P(ImagePair, Calib3D_DisparityBilateralFilter, - Values(pair_string("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png"))) -{ - const cv::Mat img = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - const cv::Mat disp = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(disp.empty()); - - const int ndisp = 128; - - if (PERF_RUN_GPU()) - { - cv::gpu::DisparityBilateralFilter d_filter(ndisp); - - const cv::gpu::GpuMat d_img(img); - const cv::gpu::GpuMat d_disp(disp); - cv::gpu::GpuMat dst; - - TEST_CYCLE() d_filter(d_disp, d_img, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// TransformPoints - DEF_PARAM_TEST_1(Count, int); -PERF_TEST_P(Count, Calib3D_TransformPoints, - Values(5000, 10000, 20000)) -{ - const int count = GetParam(); - - cv::Mat src(1, count, CV_32FC3); - declare.in(src, WARMUP_RNG); - - const cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); - const cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::transformPoints(d_src, rvec, tvec, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - ////////////////////////////////////////////////////////////////////// // ProjectPoints @@ -306,66 +133,3 @@ PERF_TEST_P(Count, Calib3D_SolvePnPRansac, CPU_SANITY_CHECK(tvec, 1e-6); } } - -////////////////////////////////////////////////////////////////////// -// ReprojectImageTo3D - -PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16S))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - - cv::Mat src(size, depth); - declare.in(src, WARMUP_RNG); - - cv::Mat Q(4, 4, CV_32FC1); - cv::randu(Q, 0.1, 1.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::reprojectImageTo3D(d_src, dst, Q); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::reprojectImageTo3D(src, dst, Q); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// DrawColorDisp - -PERF_TEST_P(Sz_Depth, Calib3D_DrawColorDisp, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16S))) -{ - const cv::Size size = GET_PARAM(0); - const int type = GET_PARAM(1); - - 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::drawColorDisp(d_src, dst, 255); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp deleted file mode 100644 index 0a24d24..0000000 --- a/modules/gpu/perf/perf_imgproc.cpp +++ /dev/null @@ -1,1904 +0,0 @@ -/*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 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 "perf_precomp.hpp" - -using namespace std; -using namespace testing; -using namespace perf; - -////////////////////////////////////////////////////////////////////// -// Remap - -enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH }; -CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH); - -void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode) -{ - for (int j = 0; j < map_x.rows; ++j) - { - for (int i = 0; i < map_x.cols; ++i) - { - switch (remapMode) - { - case HALF_SIZE: - if (i > map_x.cols*0.25 && i < map_x.cols*0.75 && j > map_x.rows*0.25 && j < map_x.rows*0.75) - { - map_x.at(j,i) = 2.f * (i - map_x.cols * 0.25f) + 0.5f; - map_y.at(j,i) = 2.f * (j - map_x.rows * 0.25f) + 0.5f; - } - else - { - map_x.at(j,i) = 0.f; - map_y.at(j,i) = 0.f; - } - break; - case UPSIDE_DOWN: - map_x.at(j,i) = static_cast(i); - map_y.at(j,i) = static_cast(map_x.rows - j); - break; - case REFLECTION_X: - map_x.at(j,i) = static_cast(map_x.cols - i); - map_y.at(j,i) = static_cast(j); - break; - case REFLECTION_BOTH: - map_x.at(j,i) = static_cast(map_x.cols - i); - map_y.at(j,i) = static_cast(map_x.rows - j); - break; - } // end of switch - } - } -} - -DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, MatCn, Interpolation, BorderMode, RemapMode); - -PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, ImgProc_Remap, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - ALL_BORDER_MODES, - RemapMode::all())) -{ - declare.time(20.0); - - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = GET_PARAM(3); - const int borderMode = GET_PARAM(4); - const int remapMode = GET_PARAM(5); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - declare.in(src, WARMUP_RNG); - - cv::Mat xmap(size, CV_32FC1); - cv::Mat ymap(size, CV_32FC1); - generateMap(xmap, ymap, remapMode); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - const cv::gpu::GpuMat d_xmap(xmap); - const cv::gpu::GpuMat d_ymap(ymap); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::remap(d_src, dst, d_xmap, d_ymap, interpolation, borderMode); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// Resize - -DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, MatCn, Interpolation, double); - -PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - Values(0.5, 0.3, 2.0))) -{ - declare.time(20.0); - - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = GET_PARAM(3); - const double f = GET_PARAM(4); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::resize(d_src, dst, cv::Size(), f, f, interpolation); - - GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// ResizeArea - -DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, MatCn, double); - -PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(0.2, 0.1, 0.05))) -{ - declare.time(1.0); - - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = cv::INTER_AREA; - const double f = GET_PARAM(3); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::resize(d_src, dst, cv::Size(), f, f, interpolation); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// WarpAffine - -DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, MatCn, Interpolation, BorderMode); - -PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - ALL_BORDER_MODES)) -{ - declare.time(20.0); - - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = GET_PARAM(3); - const int borderMode = GET_PARAM(4); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - declare.in(src, WARMUP_RNG); - - const double aplha = CV_PI / 4; - const double mat[2 * 3] = - { - std::cos(aplha), -std::sin(aplha), src.cols / 2, - std::sin(aplha), std::cos(aplha), 0 - }; - const cv::Mat M(2, 3, CV_64F, (void*) mat); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::warpAffine(d_src, dst, M, size, interpolation, borderMode); - - GPU_SANITY_CHECK(dst, 1); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::warpAffine(src, dst, M, size, interpolation, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// WarpPerspective - -PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - ALL_BORDER_MODES)) -{ - declare.time(20.0); - - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = GET_PARAM(3); - const int borderMode = GET_PARAM(4); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - declare.in(src, WARMUP_RNG); - - const double aplha = CV_PI / 4; - double mat[3][3] = { {std::cos(aplha), -std::sin(aplha), src.cols / 2}, - {std::sin(aplha), std::cos(aplha), 0}, - {0.0, 0.0, 1.0}}; - const cv::Mat M(3, 3, CV_64F, (void*) mat); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::warpPerspective(d_src, dst, M, size, interpolation, borderMode); - - GPU_SANITY_CHECK(dst, 1); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::warpPerspective(src, dst, M, size, interpolation, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// CopyMakeBorder - -DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode); - -PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - ALL_BORDER_MODES)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int borderMode = GET_PARAM(3); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// Threshold - -CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV) - -DEF_PARAM_TEST(Sz_Depth_Op, cv::Size, MatDepth, ThreshOp); - -PERF_TEST_P(Sz_Depth_Op, ImgProc_Threshold, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F, CV_64F), - ThreshOp::all())) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int threshOp = GET_PARAM(2); - - cv::Mat src(size, depth); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::threshold(d_src, dst, 100.0, 255.0, threshOp); - - GPU_SANITY_CHECK(dst, 1e-10); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::threshold(src, dst, 100.0, 255.0, threshOp); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// Integral - -PERF_TEST_P(Sz, ImgProc_Integral, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::integralBuffered(d_src, dst, d_buf); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::integral(src, dst); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// IntegralSqr - -PERF_TEST_P(Sz, ImgProc_IntegralSqr, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::sqrIntegral(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// HistEvenC1 - -PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC1, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_16S))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - - cv::Mat src(size, depth); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::histEven(d_src, dst, d_buf, 30, 0, 180); - - GPU_SANITY_CHECK(dst); - } - else - { - const int hbins = 30; - const float hranges[] = {0.0f, 180.0f}; - const int histSize[] = {hbins}; - const float* ranges[] = {hranges}; - const int channels[] = {0}; - - cv::Mat dst; - - TEST_CYCLE() cv::calcHist(&src, 1, channels, cv::Mat(), dst, 1, histSize, ranges); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// HistEvenC4 - -PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC4, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_16S))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - - cv::Mat src(size, CV_MAKE_TYPE(depth, 4)); - declare.in(src, WARMUP_RNG); - - int histSize[] = {30, 30, 30, 30}; - int lowerLevel[] = {0, 0, 0, 0}; - int upperLevel[] = {180, 180, 180, 180}; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_hist[4]; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); - - cv::Mat cpu_hist0, cpu_hist1, cpu_hist2, cpu_hist3; - d_hist[0].download(cpu_hist0); - d_hist[1].download(cpu_hist1); - d_hist[2].download(cpu_hist2); - d_hist[3].download(cpu_hist3); - SANITY_CHECK(cpu_hist0); - SANITY_CHECK(cpu_hist1); - SANITY_CHECK(cpu_hist2); - SANITY_CHECK(cpu_hist3); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// CalcHist - -PERF_TEST_P(Sz, ImgProc_CalcHist, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::calcHist(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// EqualizeHist - -PERF_TEST_P(Sz, ImgProc_EqualizeHist, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat d_hist; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::equalizeHist(d_src, dst, d_hist, d_buf); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::equalizeHist(src, dst); - - CPU_SANITY_CHECK(dst); - } -} - -DEF_PARAM_TEST(Sz_ClipLimit, cv::Size, double); - -PERF_TEST_P(Sz_ClipLimit, ImgProc_CLAHE, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(0.0, 40.0))) -{ - const cv::Size size = GET_PARAM(0); - const double clipLimit = GET_PARAM(1); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - cv::Ptr clahe = cv::gpu::createCLAHE(clipLimit); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() clahe->apply(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Ptr clahe = cv::createCLAHE(clipLimit); - cv::Mat dst; - - TEST_CYCLE() clahe->apply(src, dst); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// ColumnSum - -PERF_TEST_P(Sz, ImgProc_ColumnSum, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_32FC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::columnSum(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// Canny - -DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool); - -PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny, - Combine(Values("perf/800x600.png", "perf/1280x1024.png", "perf/1680x1050.png"), - Values(3, 5), - Bool())) -{ - const string fileName = GET_PARAM(0); - const int apperture_size = GET_PARAM(1); - const bool useL2gradient = GET_PARAM(2); - - const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - const double low_thresh = 50.0; - const double high_thresh = 100.0; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat dst; - cv::gpu::CannyBuf d_buf; - - TEST_CYCLE() cv::gpu::Canny(d_image, d_buf, dst, low_thresh, high_thresh, apperture_size, useL2gradient); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::Canny(image, dst, low_thresh, high_thresh, apperture_size, useL2gradient); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// MeanShiftFiltering - -DEF_PARAM_TEST_1(Image, string); - -PERF_TEST_P(Image, ImgProc_MeanShiftFiltering, - Values("gpu/meanshift/cones.png")) -{ - declare.time(300.0); - - const cv::Mat img = readImage(GetParam()); - ASSERT_FALSE(img.empty()); - - cv::Mat rgba; - cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - - const int sp = 50; - const int sr = 50; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(rgba); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::meanShiftFiltering(d_src, dst, sp, sr); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::pyrMeanShiftFiltering(img, dst, sp, sr); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// MeanShiftProc - -PERF_TEST_P(Image, ImgProc_MeanShiftProc, - Values("gpu/meanshift/cones.png")) -{ - declare.time(300.0); - - const cv::Mat img = readImage(GetParam()); - ASSERT_FALSE(img.empty()); - - cv::Mat rgba; - cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - - const int sp = 50; - const int sr = 50; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(rgba); - cv::gpu::GpuMat dstr; - cv::gpu::GpuMat dstsp; - - TEST_CYCLE() cv::gpu::meanShiftProc(d_src, dstr, dstsp, sp, sr); - - GPU_SANITY_CHECK(dstr); - GPU_SANITY_CHECK(dstsp); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// MeanShiftSegmentation - -PERF_TEST_P(Image, ImgProc_MeanShiftSegmentation, - Values("gpu/meanshift/cones.png")) -{ - declare.time(300.0); - - const cv::Mat img = readImage(GetParam()); - ASSERT_FALSE(img.empty()); - - cv::Mat rgba; - cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - - const int sp = 10; - const int sr = 10; - const int minsize = 20; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(rgba); - cv::Mat dst; - - TEST_CYCLE() cv::gpu::meanShiftSegmentation(d_src, dst, sp, sr, minsize); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// BlendLinear - -PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_32F), - GPU_CHANNELS_1_3_4)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat img1(size, type); - cv::Mat img2(size, type); - declare.in(img1, img2, WARMUP_RNG); - - const cv::Mat weights1(size, CV_32FC1, cv::Scalar::all(0.5)); - const cv::Mat weights2(size, CV_32FC1, cv::Scalar::all(0.5)); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_img1(img1); - const cv::gpu::GpuMat d_img2(img2); - const cv::gpu::GpuMat d_weights1(weights1); - const cv::gpu::GpuMat d_weights2(weights2); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// Convolve - -DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool); - -PERF_TEST_P(Sz_KernelSz_Ccorr, ImgProc_Convolve, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(17, 27, 32, 64), - Bool())) -{ - declare.time(10.0); - - const cv::Size size = GET_PARAM(0); - const int templ_size = GET_PARAM(1); - const bool ccorr = GET_PARAM(2); - - const cv::Mat image(size, CV_32FC1); - const cv::Mat templ(templ_size, templ_size, CV_32FC1); - declare.in(image, templ, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_image = cv::gpu::createContinuous(size, CV_32FC1); - d_image.upload(image); - - cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1); - d_templ.upload(templ); - - cv::gpu::GpuMat dst; - cv::gpu::ConvolveBuf d_buf; - - TEST_CYCLE() cv::gpu::convolve(d_image, d_templ, dst, ccorr, d_buf); - - GPU_SANITY_CHECK(dst); - } - else - { - if (ccorr) - FAIL_NO_CPU(); - - cv::Mat dst; - - TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ); - - CPU_SANITY_CHECK(dst); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// MatchTemplate8U - -CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED) - -DEF_PARAM_TEST(Sz_TemplateSz_Cn_Method, cv::Size, cv::Size, MatCn, TemplateMethod); - -PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate8U, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)), - GPU_CHANNELS_1_3_4, - TemplateMethod::all())) -{ - declare.time(300.0); - - const cv::Size size = GET_PARAM(0); - const cv::Size templ_size = GET_PARAM(1); - const int cn = GET_PARAM(2); - const int method = GET_PARAM(3); - - cv::Mat image(size, CV_MAKE_TYPE(CV_8U, cn)); - cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_8U, cn)); - declare.in(image, templ, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_image(image); - const cv::gpu::GpuMat d_templ(templ); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method); - - GPU_SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::matchTemplate(image, templ, dst, method); - - CPU_SANITY_CHECK(dst); - } -}; - -//////////////////////////////////////////////////////////////////////////////// -// MatchTemplate32F - -PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate32F, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)), - GPU_CHANNELS_1_3_4, - Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR)))) -{ - declare.time(300.0); - - const cv::Size size = GET_PARAM(0); - const cv::Size templ_size = GET_PARAM(1); - const int cn = GET_PARAM(2); - int method = GET_PARAM(3); - - cv::Mat image(size, CV_MAKE_TYPE(CV_32F, cn)); - cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_32F, cn)); - declare.in(image, templ, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_image(image); - const cv::gpu::GpuMat d_templ(templ); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method); - - GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::matchTemplate(image, templ, dst, method); - - CPU_SANITY_CHECK(dst); - } -}; - -////////////////////////////////////////////////////////////////////// -// MulSpectrums - -CV_FLAGS(DftFlags, 0, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT) - -DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags); - -PERF_TEST_P(Sz_Flags, ImgProc_MulSpectrums, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(0, DftFlags(cv::DFT_ROWS)))) -{ - const cv::Size size = GET_PARAM(0); - const int flag = GET_PARAM(1); - - cv::Mat a(size, CV_32FC2); - cv::Mat b(size, CV_32FC2); - declare.in(a, b, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_a(a); - const cv::gpu::GpuMat d_b(b); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::mulSpectrums(d_a, d_b, dst, flag); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// MulAndScaleSpectrums - -PERF_TEST_P(Sz, ImgProc_MulAndScaleSpectrums, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - const float scale = 1.f / size.area(); - - cv::Mat src1(size, CV_32FC2); - cv::Mat src2(size, CV_32FC2); - declare.in(src1,src2, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src1(src1); - const cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// Dft - -PERF_TEST_P(Sz_Flags, ImgProc_Dft, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))) -{ - declare.time(10.0); - - const cv::Size size = GET_PARAM(0); - const int flag = GET_PARAM(1); - - cv::Mat src(size, CV_32FC2); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::dft(d_src, dst, size, flag); - - GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::dft(src, dst, flag); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// CornerHarris - -DEF_PARAM_TEST(Image_Type_Border_BlockSz_ApertureSz, string, MatType, BorderMode, int, int); - -PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerHarris, - Combine(Values("gpu/stereobm/aloe-L.png"), - Values(CV_8UC1, CV_32FC1), - Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - Values(3, 5, 7), - Values(0, 3, 5, 7))) -{ - const string fileName = GET_PARAM(0); - const int type = GET_PARAM(1); - const int borderMode = GET_PARAM(2); - const int blockSize = GET_PARAM(3); - const int apertureSize = GET_PARAM(4); - - cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); - - const double k = 0.5; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat d_Dx; - cv::gpu::GpuMat d_Dy; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::cornerHarris(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); - - GPU_SANITY_CHECK(dst, 1e-4); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// CornerMinEigenVal - -PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerMinEigenVal, - Combine(Values("gpu/stereobm/aloe-L.png"), - Values(CV_8UC1, CV_32FC1), - Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - Values(3, 5, 7), - Values(0, 3, 5, 7))) -{ - const string fileName = GET_PARAM(0); - const int type = GET_PARAM(1); - const int borderMode = GET_PARAM(2); - const int blockSize = GET_PARAM(3); - const int apertureSize = GET_PARAM(4); - - cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat d_Dx; - cv::gpu::GpuMat d_Dy; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::cornerMinEigenVal(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); - - GPU_SANITY_CHECK(dst, 1e-4); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderMode); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// BuildWarpPlaneMaps - -PERF_TEST_P(Sz, ImgProc_BuildWarpPlaneMaps, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); - const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - const cv::Mat T = cv::Mat::zeros(1, 3, CV_32F); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - - TEST_CYCLE() cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, map_x, map_y); - - GPU_SANITY_CHECK(map_x); - GPU_SANITY_CHECK(map_y); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// BuildWarpCylindricalMaps - -PERF_TEST_P(Sz, ImgProc_BuildWarpCylindricalMaps, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); - const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - - TEST_CYCLE() cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); - - GPU_SANITY_CHECK(map_x); - GPU_SANITY_CHECK(map_y); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// BuildWarpSphericalMaps - -PERF_TEST_P(Sz, ImgProc_BuildWarpSphericalMaps, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); - const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - - TEST_CYCLE() cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); - - GPU_SANITY_CHECK(map_x); - GPU_SANITY_CHECK(map_y); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// Rotate - -DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, MatCn, Interpolation); - -PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4, - Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - const int interpolation = GET_PARAM(3); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::rotate(d_src, dst, size, 30.0, 0, 0, interpolation); - - GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// PyrDown - -PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrDown, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::pyrDown(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::pyrDown(src, dst); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// PyrUp - -PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrUp, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U, CV_32F), - GPU_CHANNELS_1_3_4)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - - const int type = CV_MAKE_TYPE(depth, channels); - - 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::pyrUp(d_src, dst); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::pyrUp(src, dst); - - CPU_SANITY_CHECK(dst); - } -} - -////////////////////////////////////////////////////////////////////// -// CvtColor - -DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CvtColorInfo); - -PERF_TEST_P(Sz_Depth_Code, ImgProc_CvtColor, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_32F), - Values(CvtColorInfo(4, 4, cv::COLOR_RGBA2BGRA), - CvtColorInfo(4, 1, cv::COLOR_BGRA2GRAY), - CvtColorInfo(1, 4, cv::COLOR_GRAY2BGRA), - CvtColorInfo(3, 3, cv::COLOR_BGR2XYZ), - CvtColorInfo(3, 3, cv::COLOR_XYZ2BGR), - CvtColorInfo(3, 3, cv::COLOR_BGR2YCrCb), - CvtColorInfo(3, 3, cv::COLOR_YCrCb2BGR), - CvtColorInfo(3, 3, cv::COLOR_BGR2YUV), - CvtColorInfo(3, 3, cv::COLOR_YUV2BGR), - CvtColorInfo(3, 3, cv::COLOR_BGR2HSV), - CvtColorInfo(3, 3, cv::COLOR_HSV2BGR), - CvtColorInfo(3, 3, cv::COLOR_BGR2HLS), - CvtColorInfo(3, 3, cv::COLOR_HLS2BGR), - CvtColorInfo(3, 3, cv::COLOR_BGR2Lab), - CvtColorInfo(3, 3, cv::COLOR_LBGR2Lab), - CvtColorInfo(3, 3, cv::COLOR_BGR2Luv), - CvtColorInfo(3, 3, cv::COLOR_LBGR2Luv), - CvtColorInfo(3, 3, cv::COLOR_Lab2BGR), - CvtColorInfo(3, 3, cv::COLOR_Lab2LBGR), - CvtColorInfo(3, 3, cv::COLOR_Luv2RGB), - CvtColorInfo(3, 3, cv::COLOR_Luv2LRGB)))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const CvtColorInfo info = GET_PARAM(2); - - cv::Mat src(size, CV_MAKETYPE(depth, info.scn)); - cv::randu(src, 0, depth == CV_8U ? 255.0 : 1.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn); - - GPU_SANITY_CHECK(dst, 1e-4); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn); - - CPU_SANITY_CHECK(dst); - } -} - -PERF_TEST_P(Sz_Depth_Code, ImgProc_CvtColorBayer, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8U, CV_16U), - Values(CvtColorInfo(1, 3, cv::COLOR_BayerBG2BGR), - CvtColorInfo(1, 3, cv::COLOR_BayerGB2BGR), - CvtColorInfo(1, 3, cv::COLOR_BayerRG2BGR), - CvtColorInfo(1, 3, cv::COLOR_BayerGR2BGR), - - CvtColorInfo(1, 1, cv::COLOR_BayerBG2GRAY), - CvtColorInfo(1, 1, cv::COLOR_BayerGB2GRAY), - CvtColorInfo(1, 1, cv::COLOR_BayerRG2GRAY), - CvtColorInfo(1, 1, cv::COLOR_BayerGR2GRAY)))) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const CvtColorInfo info = GET_PARAM(2); - - cv::Mat src(size, CV_MAKETYPE(depth, info.scn)); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn); - - GPU_SANITY_CHECK(dst); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn); - - CPU_SANITY_CHECK(dst); - } -} - -CV_ENUM(DemosaicingCode, - COLOR_BayerBG2BGR, COLOR_BayerGB2BGR, COLOR_BayerRG2BGR, COLOR_BayerGR2BGR, - COLOR_BayerBG2GRAY, COLOR_BayerGB2GRAY, COLOR_BayerRG2GRAY, COLOR_BayerGR2GRAY, - COLOR_BayerBG2BGR_MHT, COLOR_BayerGB2BGR_MHT, COLOR_BayerRG2BGR_MHT, COLOR_BayerGR2BGR_MHT, - COLOR_BayerBG2GRAY_MHT, COLOR_BayerGB2GRAY_MHT, COLOR_BayerRG2GRAY_MHT, COLOR_BayerGR2GRAY_MHT) - -DEF_PARAM_TEST(Sz_Code, cv::Size, DemosaicingCode); - -PERF_TEST_P(Sz_Code, ImgProc_Demosaicing, - Combine(GPU_TYPICAL_MAT_SIZES, - DemosaicingCode::all())) -{ - const cv::Size size = GET_PARAM(0); - const int code = GET_PARAM(1); - - cv::Mat src(size, CV_8UC1); - declare.in(src, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::demosaicing(d_src, dst, code); - - GPU_SANITY_CHECK(dst); - } - else - { - if (code >= cv::COLOR_COLORCVT_MAX) - { - FAIL_NO_CPU(); - } - else - { - cv::Mat dst; - - TEST_CYCLE() cv::cvtColor(src, dst, code); - - CPU_SANITY_CHECK(dst); - } - } -} - -////////////////////////////////////////////////////////////////////// -// SwapChannels - -PERF_TEST_P(Sz, ImgProc_SwapChannels, - GPU_TYPICAL_MAT_SIZES) -{ - const cv::Size size = GetParam(); - - cv::Mat src(size, CV_8UC4); - declare.in(src, WARMUP_RNG); - - const int dstOrder[] = {2, 1, 0, 3}; - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat dst(src); - - TEST_CYCLE() cv::gpu::swapChannels(dst, dstOrder); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// AlphaComp - -CV_ENUM(AlphaOp, ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL, ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL) - -DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp); - -PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(CV_8UC4, CV_16UC4, CV_32SC4, CV_32FC4), - AlphaOp::all())) -{ - const cv::Size size = GET_PARAM(0); - const int type = GET_PARAM(1); - const int alpha_op = GET_PARAM(2); - - cv::Mat img1(size, type); - cv::Mat img2(size, type); - declare.in(img1, img2, WARMUP_RNG); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_img1(img1); - const cv::gpu::GpuMat d_img2(img2); - cv::gpu::GpuMat dst; - - TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op); - - GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// ImagePyramidBuild - -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)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - declare.in(src, WARMUP_RNG); - - const int nLayers = 5; - const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - - cv::gpu::ImagePyramid d_pyr; - - TEST_CYCLE() d_pyr.build(d_src, nLayers); - - cv::gpu::GpuMat dst; - d_pyr.getLayer(dst, dstSize); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// ImagePyramidGetLayer - -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)) -{ - const cv::Size size = GET_PARAM(0); - const int depth = GET_PARAM(1); - const int channels = GET_PARAM(2); - - const int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - declare.in(src, WARMUP_RNG); - - const int nLayers = 3; - const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat dst; - - cv::gpu::ImagePyramid d_pyr(d_src, nLayers); - - TEST_CYCLE() d_pyr.getLayer(dst, dstSize); - - GPU_SANITY_CHECK(dst); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////////////////////// -// HoughLines - -namespace -{ - struct Vec4iComparator - { - bool operator()(const cv::Vec4i& a, const cv::Vec4i b) const - { - if (a[0] != b[0]) return a[0] < b[0]; - else if(a[1] != b[1]) return a[1] < b[1]; - else if(a[2] != b[2]) return a[2] < b[2]; - else return a[3] < b[3]; - } - }; - struct Vec3fComparator - { - bool operator()(const cv::Vec3f& a, const cv::Vec3f b) const - { - if(a[0] != b[0]) return a[0] < b[0]; - else if(a[1] != b[1]) return a[1] < b[1]; - else return a[2] < b[2]; - } - }; - struct Vec2fComparator - { - bool operator()(const cv::Vec2f& a, const cv::Vec2f b) const - { - if(a[0] != b[0]) return a[0] < b[0]; - else return a[1] < b[1]; - } - }; -} - -PERF_TEST_P(Sz, ImgProc_HoughLines, - GPU_TYPICAL_MAT_SIZES) -{ - declare.time(30.0); - - const cv::Size size = GetParam(); - - const float rho = 1.0f; - const float theta = static_cast(CV_PI / 180.0); - const int threshold = 300; - - cv::Mat src(size, CV_8UC1, cv::Scalar::all(0)); - cv::line(src, cv::Point(0, 100), cv::Point(src.cols, 100), cv::Scalar::all(255), 1); - cv::line(src, cv::Point(0, 200), cv::Point(src.cols, 200), cv::Scalar::all(255), 1); - cv::line(src, cv::Point(0, 400), cv::Point(src.cols, 400), cv::Scalar::all(255), 1); - cv::line(src, cv::Point(100, 0), cv::Point(100, src.rows), cv::Scalar::all(255), 1); - cv::line(src, cv::Point(200, 0), cv::Point(200, src.rows), cv::Scalar::all(255), 1); - cv::line(src, cv::Point(400, 0), cv::Point(400, src.rows), cv::Scalar::all(255), 1); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_lines; - cv::gpu::HoughLinesBuf d_buf; - - TEST_CYCLE() cv::gpu::HoughLines(d_src, d_lines, d_buf, rho, theta, threshold); - - cv::Mat gpu_lines(d_lines.row(0)); - cv::Vec2f* begin = gpu_lines.ptr(0); - cv::Vec2f* end = begin + gpu_lines.cols; - std::sort(begin, end, Vec2fComparator()); - SANITY_CHECK(gpu_lines); - } - else - { - std::vector cpu_lines; - - TEST_CYCLE() cv::HoughLines(src, cpu_lines, rho, theta, threshold); - - SANITY_CHECK(cpu_lines); - } -} - -////////////////////////////////////////////////////////////////////// -// HoughLinesP - -DEF_PARAM_TEST_1(Image, std::string); - -PERF_TEST_P(Image, ImgProc_HoughLinesP, - testing::Values("cv/shared/pic5.png", "stitching/a1.png")) -{ - declare.time(30.0); - - const std::string fileName = getDataPath(GetParam()); - - const float rho = 1.0f; - const float theta = static_cast(CV_PI / 180.0); - const int threshold = 100; - const int minLineLenght = 50; - const int maxLineGap = 5; - - const cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - cv::Mat mask; - cv::Canny(image, mask, 50, 100); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_mask(mask); - cv::gpu::GpuMat d_lines; - cv::gpu::HoughLinesBuf d_buf; - - TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap); - - cv::Mat gpu_lines(d_lines); - cv::Vec4i* begin = gpu_lines.ptr(); - cv::Vec4i* end = begin + gpu_lines.cols; - std::sort(begin, end, Vec4iComparator()); - SANITY_CHECK(gpu_lines); - } - else - { - std::vector cpu_lines; - - TEST_CYCLE() cv::HoughLinesP(mask, cpu_lines, rho, theta, threshold, minLineLenght, maxLineGap); - - SANITY_CHECK(cpu_lines); - } -} - -////////////////////////////////////////////////////////////////////// -// HoughCircles - -DEF_PARAM_TEST(Sz_Dp_MinDist, cv::Size, float, float); - -PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles, - Combine(GPU_TYPICAL_MAT_SIZES, - Values(1.0f, 2.0f, 4.0f), - Values(1.0f))) -{ - declare.time(30.0); - - const cv::Size size = GET_PARAM(0); - const float dp = GET_PARAM(1); - const float minDist = GET_PARAM(2); - - const int minRadius = 10; - const int maxRadius = 30; - const int cannyThreshold = 100; - const int votesThreshold = 15; - - cv::Mat src(size, CV_8UC1, cv::Scalar::all(0)); - cv::circle(src, cv::Point(100, 100), 20, cv::Scalar::all(255), -1); - cv::circle(src, cv::Point(200, 200), 25, cv::Scalar::all(255), -1); - cv::circle(src, cv::Point(200, 100), 25, cv::Scalar::all(255), -1); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_circles; - cv::gpu::HoughCirclesBuf d_buf; - - TEST_CYCLE() cv::gpu::HoughCircles(d_src, d_circles, d_buf, cv::HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius); - - cv::Mat gpu_circles(d_circles); - cv::Vec3f* begin = gpu_circles.ptr(0); - cv::Vec3f* end = begin + gpu_circles.cols; - std::sort(begin, end, Vec3fComparator()); - SANITY_CHECK(gpu_circles); - } - else - { - std::vector cpu_circles; - - TEST_CYCLE() cv::HoughCircles(src, cpu_circles, cv::HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius); - - SANITY_CHECK(cpu_circles); - } -} - -////////////////////////////////////////////////////////////////////// -// GeneralizedHough - -enum { GHT_POSITION = cv::GeneralizedHough::GHT_POSITION, - GHT_SCALE = cv::GeneralizedHough::GHT_SCALE, - GHT_ROTATION = cv::GeneralizedHough::GHT_ROTATION - }; - -CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION); - -DEF_PARAM_TEST(Method_Sz, GHMethod, cv::Size); - -PERF_TEST_P(Method_Sz, ImgProc_GeneralizedHough, - Combine(Values(GHMethod(GHT_POSITION), GHMethod(GHT_POSITION | GHT_SCALE), GHMethod(GHT_POSITION | GHT_ROTATION), GHMethod(GHT_POSITION | GHT_SCALE | GHT_ROTATION)), - GPU_TYPICAL_MAT_SIZES)) -{ - declare.time(10); - - const int method = GET_PARAM(0); - const cv::Size imageSize = GET_PARAM(1); - - const cv::Mat templ = readImage("cv/shared/templ.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(templ.empty()); - - cv::Mat image(imageSize, CV_8UC1, cv::Scalar::all(0)); - templ.copyTo(image(cv::Rect(50, 50, templ.cols, templ.rows))); - - cv::RNG rng(123456789); - const int objCount = rng.uniform(5, 15); - for (int i = 0; i < objCount; ++i) - { - double scale = rng.uniform(0.7, 1.3); - bool rotate = 1 == rng.uniform(0, 2); - - cv::Mat obj; - cv::resize(templ, obj, cv::Size(), scale, scale); - if (rotate) - obj = obj.t(); - - cv::Point pos; - - pos.x = rng.uniform(0, image.cols - obj.cols); - pos.y = rng.uniform(0, image.rows - obj.rows); - - cv::Mat roi = image(cv::Rect(pos, obj.size())); - cv::add(roi, obj, roi); - } - - cv::Mat edges; - cv::Canny(image, edges, 50, 100); - - cv::Mat dx, dy; - cv::Sobel(image, dx, CV_32F, 1, 0); - cv::Sobel(image, dy, CV_32F, 0, 1); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_edges(edges); - const cv::gpu::GpuMat d_dx(dx); - const cv::gpu::GpuMat d_dy(dy); - cv::gpu::GpuMat posAndVotes; - - cv::Ptr d_hough = cv::gpu::GeneralizedHough_GPU::create(method); - if (method & GHT_ROTATION) - { - d_hough->set("maxAngle", 90.0); - d_hough->set("angleStep", 2.0); - } - - d_hough->setTemplate(cv::gpu::GpuMat(templ)); - - TEST_CYCLE() d_hough->detect(d_edges, d_dx, d_dy, posAndVotes); - - const cv::gpu::GpuMat positions(1, posAndVotes.cols, CV_32FC4, posAndVotes.data); - GPU_SANITY_CHECK(positions); - } - else - { - cv::Mat positions; - - cv::Ptr hough = cv::GeneralizedHough::create(method); - if (method & GHT_ROTATION) - { - hough->set("maxAngle", 90.0); - hough->set("angleStep", 2.0); - } - - hough->setTemplate(templ); - - TEST_CYCLE() hough->detect(edges, dx, dy, positions); - - CPU_SANITY_CHECK(positions); - } -} diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp index f365a5a..5bfb14b 100644 --- a/modules/gpu/perf/perf_precomp.hpp +++ b/modules/gpu/perf/perf_precomp.hpp @@ -51,21 +51,12 @@ #ifndef __OPENCV_PERF_PRECOMP_HPP__ #define __OPENCV_PERF_PRECOMP_HPP__ -#include -#include - #include "opencv2/ts.hpp" #include "opencv2/ts/gpu_perf.hpp" -#include "opencv2/core.hpp" -#include "opencv2/highgui.hpp" #include "opencv2/gpu.hpp" #include "opencv2/calib3d.hpp" -#include "opencv2/imgproc.hpp" -#include "opencv2/video.hpp" -#include "opencv2/photo.hpp" - -#include "opencv2/core/gpu_private.hpp" +#include "opencv2/objdetect.hpp" #ifdef GTEST_CREATE_SHARED_LIBRARY #error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp deleted file mode 100644 index c69b960..0000000 --- a/modules/gpu/perf/perf_video.cpp +++ /dev/null @@ -1,1107 +0,0 @@ -/*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 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 "perf_precomp.hpp" -#include "opencv2/legacy.hpp" - -using namespace std; -using namespace testing; -using namespace perf; - -#if defined(HAVE_XINE) || \ - defined(HAVE_GSTREAMER) || \ - defined(HAVE_QUICKTIME) || \ - defined(HAVE_AVFOUNDATION) || \ - defined(HAVE_FFMPEG) || \ - defined(WIN32) /* assume that we have ffmpeg */ - -# define BUILD_WITH_VIDEO_INPUT_SUPPORT 1 -#else -# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0 -#endif - -namespace cv -{ - template<> void Ptr::delete_obj() - { - cvReleaseBGStatModel(&obj); - } -} - -////////////////////////////////////////////////////// -// InterpolateFrames - -typedef pair pair_string; - -DEF_PARAM_TEST_1(ImagePair, pair_string); - -PERF_TEST_P(ImagePair, Video_InterpolateFrames, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); - frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_fu, d_fv; - cv::gpu::GpuMat d_bu, d_bv; - - cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, - 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); - - d_flow(d_frame0, d_frame1, d_fu, d_fv); - d_flow(d_frame1, d_frame0, d_bu, d_bv); - - cv::gpu::GpuMat newFrame; - cv::gpu::GpuMat d_buf; - - TEST_CYCLE() cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, newFrame, d_buf); - - GPU_SANITY_CHECK(newFrame); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////// -// CreateOpticalFlowNeedleMap - -PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); - frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, - 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); - - d_flow(d_frame0, d_frame1, u, v); - - cv::gpu::GpuMat vertex, colors; - - TEST_CYCLE() cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors); - - GPU_SANITY_CHECK(vertex); - GPU_SANITY_CHECK(colors); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////// -// GoodFeaturesToTrack - -DEF_PARAM_TEST(Image_MinDistance, string, double); - -PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack, - Combine(Values("gpu/perf/aloe.png"), - Values(0.0, 3.0))) -{ - const string fileName = GET_PARAM(0); - const double minDistance = GET_PARAM(1); - - const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - const int maxCorners = 8000; - const double qualityLevel = 0.01; - - if (PERF_RUN_GPU()) - { - cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(maxCorners, qualityLevel, minDistance); - - const cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat pts; - - TEST_CYCLE() d_detector(d_image, pts); - - GPU_SANITY_CHECK(pts); - } - else - { - cv::Mat pts; - - TEST_CYCLE() cv::goodFeaturesToTrack(image, pts, maxCorners, qualityLevel, minDistance); - - CPU_SANITY_CHECK(pts); - } -} - -////////////////////////////////////////////////////// -// BroxOpticalFlow - -PERF_TEST_P(ImagePair, Video_BroxOpticalFlow, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - declare.time(300); - - cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); - frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, - 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); - - TEST_CYCLE() d_flow(d_frame0, d_frame1, u, v); - - GPU_SANITY_CHECK(u); - GPU_SANITY_CHECK(v); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////// -// PyrLKOpticalFlowSparse - -DEF_PARAM_TEST(ImagePair_Gray_NPts_WinSz_Levels_Iters, pair_string, bool, int, int, int, int); - -PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, Video_PyrLKOpticalFlowSparse, - Combine(Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")), - Bool(), - Values(8000), - Values(21), - Values(1, 3), - Values(1, 30))) -{ - declare.time(20.0); - - const pair_string imagePair = GET_PARAM(0); - const bool useGray = GET_PARAM(1); - const int points = GET_PARAM(2); - const int winSize = GET_PARAM(3); - const int levels = GET_PARAM(4); - const int iters = GET_PARAM(5); - - const cv::Mat frame0 = readImage(imagePair.first, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(imagePair.second, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - ASSERT_FALSE(frame1.empty()); - - cv::Mat gray_frame; - if (useGray) - gray_frame = frame0; - else - cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY); - - cv::Mat pts; - cv::goodFeaturesToTrack(gray_frame, pts, points, 0.01, 0.0); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_pts(pts.reshape(2, 1)); - - cv::gpu::PyrLKOpticalFlow d_pyrLK; - d_pyrLK.winSize = cv::Size(winSize, winSize); - d_pyrLK.maxLevel = levels - 1; - d_pyrLK.iters = iters; - - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat nextPts; - cv::gpu::GpuMat status; - - TEST_CYCLE() d_pyrLK.sparse(d_frame0, d_frame1, d_pts, nextPts, status); - - GPU_SANITY_CHECK(nextPts); - GPU_SANITY_CHECK(status); - } - else - { - cv::Mat nextPts; - cv::Mat status; - - TEST_CYCLE() - { - cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, cv::noArray(), - cv::Size(winSize, winSize), levels - 1, - cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, iters, 0.01)); - } - - CPU_SANITY_CHECK(nextPts); - CPU_SANITY_CHECK(status); - } -} - -////////////////////////////////////////////////////// -// PyrLKOpticalFlowDense - -DEF_PARAM_TEST(ImagePair_WinSz_Levels_Iters, pair_string, int, int, int); - -PERF_TEST_P(ImagePair_WinSz_Levels_Iters, Video_PyrLKOpticalFlowDense, - Combine(Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")), - Values(3, 5, 7, 9, 13, 17, 21), - Values(1, 3), - Values(1, 10))) -{ - declare.time(30); - - const pair_string imagePair = GET_PARAM(0); - const int winSize = GET_PARAM(1); - const int levels = GET_PARAM(2); - const int iters = GET_PARAM(3); - - const cv::Mat frame0 = readImage(imagePair.first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(imagePair.second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::PyrLKOpticalFlow d_pyrLK; - d_pyrLK.winSize = cv::Size(winSize, winSize); - d_pyrLK.maxLevel = levels - 1; - d_pyrLK.iters = iters; - - TEST_CYCLE() d_pyrLK.dense(d_frame0, d_frame1, u, v); - - GPU_SANITY_CHECK(u); - GPU_SANITY_CHECK(v); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////// -// FarnebackOpticalFlow - -PERF_TEST_P(ImagePair, Video_FarnebackOpticalFlow, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - declare.time(10); - - const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - const int numLevels = 5; - const double pyrScale = 0.5; - const int winSize = 13; - const int numIters = 10; - const int polyN = 5; - const double polySigma = 1.1; - const int flags = 0; - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::FarnebackOpticalFlow d_farneback; - d_farneback.numLevels = numLevels; - d_farneback.pyrScale = pyrScale; - d_farneback.winSize = winSize; - d_farneback.numIters = numIters; - d_farneback.polyN = polyN; - d_farneback.polySigma = polySigma; - d_farneback.flags = flags; - - TEST_CYCLE() d_farneback(d_frame0, d_frame1, u, v); - - GPU_SANITY_CHECK(u, 1e-4); - GPU_SANITY_CHECK(v, 1e-4); - } - else - { - cv::Mat flow; - - TEST_CYCLE() cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); - - CPU_SANITY_CHECK(flow); - } -} - -////////////////////////////////////////////////////// -// OpticalFlowDual_TVL1 - -PERF_TEST_P(ImagePair, Video_OpticalFlowDual_TVL1, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - declare.time(20); - - const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::OpticalFlowDual_TVL1_GPU d_alg; - - TEST_CYCLE() d_alg(d_frame0, d_frame1, u, v); - - GPU_SANITY_CHECK(u, 1e-2); - GPU_SANITY_CHECK(v, 1e-2); - } - else - { - cv::Mat flow; - - cv::Ptr alg = cv::createOptFlow_DualTVL1(); - alg->set("medianFiltering", 1); - alg->set("innerIterations", 1); - alg->set("outerIterations", 300); - - TEST_CYCLE() alg->calc(frame0, frame1, flow); - - CPU_SANITY_CHECK(flow); - } -} - -////////////////////////////////////////////////////// -// OpticalFlowBM - -void calcOpticalFlowBM(const cv::Mat& prev, const cv::Mat& curr, - cv::Size bSize, cv::Size shiftSize, cv::Size maxRange, int usePrevious, - cv::Mat& velx, cv::Mat& vely) -{ - cv::Size sz((curr.cols - bSize.width + shiftSize.width)/shiftSize.width, (curr.rows - bSize.height + shiftSize.height)/shiftSize.height); - - velx.create(sz, CV_32FC1); - vely.create(sz, CV_32FC1); - - CvMat cvprev = prev; - CvMat cvcurr = curr; - - CvMat cvvelx = velx; - CvMat cvvely = vely; - - cvCalcOpticalFlowBM(&cvprev, &cvcurr, bSize, shiftSize, maxRange, usePrevious, &cvvelx, &cvvely); -} - -PERF_TEST_P(ImagePair, Video_OpticalFlowBM, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - declare.time(400); - - const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - const cv::Size block_size(16, 16); - const cv::Size shift_size(1, 1); - const cv::Size max_range(16, 16); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u, v, buf; - - TEST_CYCLE() cv::gpu::calcOpticalFlowBM(d_frame0, d_frame1, block_size, shift_size, max_range, false, u, v, buf); - - GPU_SANITY_CHECK(u); - GPU_SANITY_CHECK(v); - } - else - { - cv::Mat u, v; - - TEST_CYCLE() calcOpticalFlowBM(frame0, frame1, block_size, shift_size, max_range, false, u, v); - - CPU_SANITY_CHECK(u); - CPU_SANITY_CHECK(v); - } -} - -PERF_TEST_P(ImagePair, Video_FastOpticalFlowBM, - Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) -{ - declare.time(400); - - const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - const cv::Size block_size(16, 16); - const cv::Size shift_size(1, 1); - const cv::Size max_range(16, 16); - - if (PERF_RUN_GPU()) - { - const cv::gpu::GpuMat d_frame0(frame0); - const cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat u, v; - - cv::gpu::FastOpticalFlowBM fastBM; - - TEST_CYCLE() fastBM(d_frame0, d_frame1, u, v, max_range.width, block_size.width); - - GPU_SANITY_CHECK(u, 2); - GPU_SANITY_CHECK(v, 2); - } - else - { - FAIL_NO_CPU(); - } -} - -////////////////////////////////////////////////////// -// FGDStatModel - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST_1(Video, string); - -PERF_TEST_P(Video, Video_FGDStatModel, - Values(string("gpu/video/768x576.avi"))) -{ - declare.time(60); - - const string inputFile = perf::TestBase::getDataPath(GetParam()); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - - cv::gpu::FGDStatModel d_model(4); - d_model.create(d_frame); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - d_frame.upload(frame); - - startTimer(); next(); - d_model.update(d_frame); - stopTimer(); - } - - const cv::gpu::GpuMat background = d_model.background; - const cv::gpu::GpuMat foreground = d_model.foreground; - - GPU_SANITY_CHECK(background, 1e-2, ERROR_RELATIVE); - GPU_SANITY_CHECK(foreground, 1e-2, ERROR_RELATIVE); - } - else - { - IplImage ipl_frame = frame; - cv::Ptr model(cvCreateFGDStatModel(&ipl_frame)); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - ipl_frame = frame; - - startTimer(); next(); - cvUpdateBGStatModel(&ipl_frame, model); - stopTimer(); - } - - const cv::Mat background = cv::cvarrToMat(model->background); - const cv::Mat foreground = cv::cvarrToMat(model->foreground); - - CPU_SANITY_CHECK(background); - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST(Video_Cn_LearningRate, string, MatCn, double); - -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))) -{ - const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); - const int cn = GET_PARAM(1); - const float learningRate = static_cast(GET_PARAM(2)); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - cv::gpu::MOG_GPU d_mog; - cv::gpu::GpuMat foreground; - - d_mog(d_frame, foreground, learningRate); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - d_frame.upload(frame); - - startTimer(); next(); - d_mog(d_frame, foreground, learningRate); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Ptr mog = cv::createBackgroundSubtractorMOG(); - cv::Mat foreground; - - mog->apply(frame, foreground, learningRate); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - startTimer(); next(); - mog->apply(frame, foreground, learningRate); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG2 - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST(Video_Cn, string, int); - -PERF_TEST_P(Video_Cn, Video_MOG2, - Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - GPU_CHANNELS_1_3_4)) -{ - const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); - const int cn = GET_PARAM(1); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - if (PERF_RUN_GPU()) - { - cv::gpu::MOG2_GPU d_mog2; - d_mog2.bShadowDetection = false; - - cv::gpu::GpuMat d_frame(frame); - cv::gpu::GpuMat foreground; - - d_mog2(d_frame, foreground); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - d_frame.upload(frame); - - startTimer(); next(); - d_mog2(d_frame, foreground); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Ptr mog2 = cv::createBackgroundSubtractorMOG2(); - mog2->set("detectShadows", false); - - cv::Mat foreground; - - mog2->apply(frame, foreground); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - startTimer(); next(); - mog2->apply(frame, foreground); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// MOG2GetBackgroundImage - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, - Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), - GPU_CHANNELS_1_3_4)) -{ - const string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); - const int cn = GET_PARAM(1); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU d_mog2; - cv::gpu::GpuMat d_foreground; - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - d_frame.upload(frame); - - d_mog2(d_frame, d_foreground); - } - - cv::gpu::GpuMat background; - - TEST_CYCLE() d_mog2.getBackgroundImage(background); - - GPU_SANITY_CHECK(background, 1); - } - else - { - cv::Ptr mog2 = cv::createBackgroundSubtractorMOG2(); - cv::Mat foreground; - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - mog2->apply(frame, foreground); - } - - cv::Mat background; - - TEST_CYCLE() mog2->getBackgroundImage(background); - - CPU_SANITY_CHECK(background); - } -} - -#endif - -////////////////////////////////////////////////////// -// GMG - -#if BUILD_WITH_VIDEO_INPUT_SUPPORT - -DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, MatCn, int); - -PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, - Combine(Values(string("gpu/video/768x576.avi")), - GPU_CHANNELS_1_3_4, - Values(20, 40, 60))) -{ - const std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); - const int cn = GET_PARAM(1); - const int maxFeatures = GET_PARAM(2); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - cap >> frame; - ASSERT_FALSE(frame.empty()); - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - if (PERF_RUN_GPU()) - { - cv::gpu::GpuMat d_frame(frame); - cv::gpu::GpuMat foreground; - - cv::gpu::GMG_GPU d_gmg; - d_gmg.maxFeatures = maxFeatures; - - d_gmg(d_frame, foreground); - - for (int i = 0; i < 150; ++i) - { - cap >> frame; - if (frame.empty()) - { - cap.release(); - cap.open(inputFile); - cap >> frame; - } - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - d_frame.upload(frame); - - startTimer(); next(); - d_gmg(d_frame, foreground); - stopTimer(); - } - - GPU_SANITY_CHECK(foreground); - } - else - { - cv::Mat foreground; - cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); - - cv::Ptr gmg = cv::createBackgroundSubtractorGMG(); - gmg->set("maxFeatures", maxFeatures); - //gmg.initialize(frame.size(), 0.0, 255.0); - - gmg->apply(frame, foreground); - - for (int i = 0; i < 150; ++i) - { - cap >> frame; - if (frame.empty()) - { - cap.release(); - cap.open(inputFile); - cap >> frame; - } - - if (cn != 3) - { - cv::Mat temp; - if (cn == 1) - cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY); - else - cv::cvtColor(frame, temp, cv::COLOR_BGR2BGRA); - cv::swap(temp, frame); - } - - startTimer(); next(); - gmg->apply(frame, foreground); - stopTimer(); - } - - CPU_SANITY_CHECK(foreground); - } -} - -#endif - -////////////////////////////////////////////////////// -// VideoReader - -#if defined(HAVE_NVCUVID) && BUILD_WITH_VIDEO_INPUT_SUPPORT - -PERF_TEST_P(Video, DISABLED_Video_VideoReader, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) -{ - declare.time(20); - - const string inputFile = perf::TestBase::getDataPath(GetParam()); - - if (PERF_RUN_GPU()) - { - cv::gpu::VideoReader_GPU d_reader(inputFile); - ASSERT_TRUE( d_reader.isOpened() ); - - cv::gpu::GpuMat frame; - - TEST_CYCLE_N(10) d_reader.read(frame); - - GPU_SANITY_CHECK(frame); - } - else - { - cv::VideoCapture reader(inputFile); - ASSERT_TRUE( reader.isOpened() ); - - cv::Mat frame; - - TEST_CYCLE_N(10) reader >> frame; - - CPU_SANITY_CHECK(frame); - } -} - -#endif - -////////////////////////////////////////////////////// -// VideoWriter - -#if defined(HAVE_NVCUVID) && defined(WIN32) - -PERF_TEST_P(Video, DISABLED_Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) -{ - declare.time(30); - - const string inputFile = perf::TestBase::getDataPath(GetParam()); - const string outputFile = cv::tempfile(".avi"); - - const double FPS = 25.0; - - cv::VideoCapture reader(inputFile); - ASSERT_TRUE( reader.isOpened() ); - - cv::Mat frame; - - if (PERF_RUN_GPU()) - { - cv::gpu::VideoWriter_GPU d_writer; - - cv::gpu::GpuMat d_frame; - - for (int i = 0; i < 10; ++i) - { - reader >> frame; - ASSERT_FALSE(frame.empty()); - - d_frame.upload(frame); - - if (!d_writer.isOpened()) - d_writer.open(outputFile, frame.size(), FPS); - - startTimer(); next(); - d_writer.write(d_frame); - stopTimer(); - } - } - else - { - cv::VideoWriter writer; - - for (int i = 0; i < 10; ++i) - { - reader >> frame; - ASSERT_FALSE(frame.empty()); - - if (!writer.isOpened()) - writer.open(outputFile, CV_FOURCC('X', 'V', 'I', 'D'), FPS, frame.size()); - - startTimer(); next(); - writer.write(frame); - stopTimer(); - } - } - - SANITY_CHECK(frame); -} - -#endif diff --git a/modules/gpu/perf4au/CMakeLists.txt b/modules/gpu/perf4au/CMakeLists.txt index 7452203..cb39506 100644 --- a/modules/gpu/perf4au/CMakeLists.txt +++ b/modules/gpu/perf4au/CMakeLists.txt @@ -1,4 +1,4 @@ -set(PERF4AU_REQUIRED_DEPS opencv_core opencv_imgproc opencv_highgui opencv_video opencv_legacy opencv_gpu opencv_ts) +set(PERF4AU_REQUIRED_DEPS opencv_core opencv_imgproc opencv_highgui opencv_video opencv_legacy opencv_ml opencv_ts opencv_gpufilters opencv_gpuimgproc opencv_gpuoptflow) ocv_check_dependencies(${PERF4AU_REQUIRED_DEPS}) @@ -25,4 +25,3 @@ if(WIN32) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() endif() - diff --git a/modules/gpu/perf4au/main.cpp b/modules/gpu/perf4au/main.cpp index afdd2e4..d86f7b8 100644 --- a/modules/gpu/perf4au/main.cpp +++ b/modules/gpu/perf4au/main.cpp @@ -44,7 +44,8 @@ #include "cvconfig.h" #include "opencv2/core.hpp" -#include "opencv2/gpu.hpp" +#include "opencv2/gpuimgproc.hpp" +#include "opencv2/gpuoptflow.hpp" #include "opencv2/highgui.hpp" #include "opencv2/video.hpp" #include "opencv2/legacy.hpp" diff --git a/modules/gpu/src/arithm.cpp b/modules/gpu/src/arithm.cpp deleted file mode 100644 index c40e713..0000000 --- a/modules/gpu/src/arithm.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/*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 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" - -using namespace cv; -using namespace cv::gpu; - -#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) - -void cv::gpu::gemm(const GpuMat&, const GpuMat&, double, const GpuMat&, double, GpuMat&, int, Stream&) { throw_no_cuda(); } -void cv::gpu::transpose(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::flip(const GpuMat&, GpuMat&, int, Stream&) { throw_no_cuda(); } -void cv::gpu::LUT(const GpuMat&, const Mat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::magnitude(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::magnitudeSqr(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::magnitude(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::magnitudeSqr(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } -void cv::gpu::phase(const GpuMat&, const GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); } -void cv::gpu::cartToPolar(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); } -void cv::gpu::polarToCart(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); } -void cv::gpu::normalize(const GpuMat&, GpuMat&, double, double, int, int, const GpuMat&) { throw_no_cuda(); } -void cv::gpu::normalize(const GpuMat&, GpuMat&, double, double, int, int, const GpuMat&, GpuMat&, GpuMat&) { throw_no_cuda(); } - -#else /* !defined (HAVE_CUDA) */ - -//////////////////////////////////////////////////////////////////////// -// gemm - -void cv::gpu::gemm(const GpuMat& src1, const GpuMat& src2, double alpha, const GpuMat& src3, double beta, GpuMat& dst, int flags, Stream& stream) -{ -#ifndef HAVE_CUBLAS - (void)src1; - (void)src2; - (void)alpha; - (void)src3; - (void)beta; - (void)dst; - (void)flags; - (void)stream; - CV_Error(cv::Error::StsNotImplemented, "The library was build without CUBLAS"); -#else - // CUBLAS works with column-major matrices - - CV_Assert(src1.type() == CV_32FC1 || src1.type() == CV_32FC2 || src1.type() == CV_64FC1 || src1.type() == CV_64FC2); - CV_Assert(src2.type() == src1.type() && (src3.empty() || src3.type() == src1.type())); - - if (src1.depth() == CV_64F) - { - if (!deviceSupports(NATIVE_DOUBLE)) - CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double"); - } - - bool tr1 = (flags & GEMM_1_T) != 0; - bool tr2 = (flags & GEMM_2_T) != 0; - bool tr3 = (flags & GEMM_3_T) != 0; - - if (src1.type() == CV_64FC2) - { - if (tr1 || tr2 || tr3) - CV_Error(cv::Error::StsNotImplemented, "transpose operation doesn't implemented for CV_64FC2 type"); - } - - Size src1Size = tr1 ? Size(src1.rows, src1.cols) : src1.size(); - Size src2Size = tr2 ? Size(src2.rows, src2.cols) : src2.size(); - Size src3Size = tr3 ? Size(src3.rows, src3.cols) : src3.size(); - Size dstSize(src2Size.width, src1Size.height); - - CV_Assert(src1Size.width == src2Size.height); - CV_Assert(src3.empty() || src3Size == dstSize); - - dst.create(dstSize, src1.type()); - - if (beta != 0) - { - if (src3.empty()) - { - if (stream) - stream.enqueueMemSet(dst, Scalar::all(0)); - else - dst.setTo(Scalar::all(0)); - } - else - { - if (tr3) - { - transpose(src3, dst, stream); - } - else - { - if (stream) - stream.enqueueCopy(src3, dst); - else - src3.copyTo(dst); - } - } - } - - cublasHandle_t handle; - cublasSafeCall( cublasCreate_v2(&handle) ); - - cublasSafeCall( cublasSetStream_v2(handle, StreamAccessor::getStream(stream)) ); - - cublasSafeCall( cublasSetPointerMode_v2(handle, CUBLAS_POINTER_MODE_HOST) ); - - const float alphaf = static_cast(alpha); - const float betaf = static_cast(beta); - - const cuComplex alphacf = make_cuComplex(alphaf, 0); - const cuComplex betacf = make_cuComplex(betaf, 0); - - const cuDoubleComplex alphac = make_cuDoubleComplex(alpha, 0); - const cuDoubleComplex betac = make_cuDoubleComplex(beta, 0); - - cublasOperation_t transa = tr2 ? CUBLAS_OP_T : CUBLAS_OP_N; - cublasOperation_t transb = tr1 ? CUBLAS_OP_T : CUBLAS_OP_N; - - switch (src1.type()) - { - case CV_32FC1: - cublasSafeCall( cublasSgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows, - &alphaf, - src2.ptr(), static_cast(src2.step / sizeof(float)), - src1.ptr(), static_cast(src1.step / sizeof(float)), - &betaf, - dst.ptr(), static_cast(dst.step / sizeof(float))) ); - break; - - case CV_64FC1: - cublasSafeCall( cublasDgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows, - &alpha, - src2.ptr(), static_cast(src2.step / sizeof(double)), - src1.ptr(), static_cast(src1.step / sizeof(double)), - &beta, - dst.ptr(), static_cast(dst.step / sizeof(double))) ); - break; - - case CV_32FC2: - cublasSafeCall( cublasCgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows, - &alphacf, - src2.ptr(), static_cast(src2.step / sizeof(cuComplex)), - src1.ptr(), static_cast(src1.step / sizeof(cuComplex)), - &betacf, - dst.ptr(), static_cast(dst.step / sizeof(cuComplex))) ); - break; - - case CV_64FC2: - cublasSafeCall( cublasZgemm_v2(handle, transa, transb, tr2 ? src2.rows : src2.cols, tr1 ? src1.cols : src1.rows, tr2 ? src2.cols : src2.rows, - &alphac, - src2.ptr(), static_cast(src2.step / sizeof(cuDoubleComplex)), - src1.ptr(), static_cast(src1.step / sizeof(cuDoubleComplex)), - &betac, - dst.ptr(), static_cast(dst.step / sizeof(cuDoubleComplex))) ); - break; - } - - cublasSafeCall( cublasDestroy_v2(handle) ); -#endif -} - -//////////////////////////////////////////////////////////////////////// -// transpose - -void cv::gpu::transpose(const GpuMat& src, GpuMat& dst, Stream& s) -{ - CV_Assert(src.elemSize() == 1 || src.elemSize() == 4 || src.elemSize() == 8); - - dst.create( src.cols, src.rows, src.type() ); - - cudaStream_t stream = StreamAccessor::getStream(s); - - if (src.elemSize() == 1) - { - NppStreamHandler h(stream); - - NppiSize sz; - sz.width = src.cols; - sz.height = src.rows; - - nppSafeCall( nppiTranspose_8u_C1R(src.ptr(), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz) ); - } - else if (src.elemSize() == 4) - { - NppStStreamHandler h(stream); - - NcvSize32u sz; - sz.width = src.cols; - sz.height = src.rows; - - ncvSafeCall( nppiStTranspose_32u_C1R(const_cast(src.ptr()), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz) ); - } - else // if (src.elemSize() == 8) - { - if (!deviceSupports(NATIVE_DOUBLE)) - CV_Error(cv::Error::StsUnsupportedFormat, "The device doesn't support double"); - - NppStStreamHandler h(stream); - - NcvSize32u sz; - sz.width = src.cols; - sz.height = src.rows; - - ncvSafeCall( nppiStTranspose_64u_C1R(const_cast(src.ptr()), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz) ); - } - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); -} - -//////////////////////////////////////////////////////////////////////// -// flip - -namespace -{ - template struct NppTypeTraits; - template<> struct NppTypeTraits { typedef Npp8u npp_t; }; - template<> struct NppTypeTraits { typedef Npp8s npp_t; }; - template<> struct NppTypeTraits { typedef Npp16u npp_t; }; - template<> struct NppTypeTraits { typedef Npp16s npp_t; }; - template<> struct NppTypeTraits { typedef Npp32s npp_t; }; - template<> struct NppTypeTraits { typedef Npp32f npp_t; }; - template<> struct NppTypeTraits { typedef Npp64f npp_t; }; - - template struct NppMirrorFunc - { - typedef typename NppTypeTraits::npp_t npp_t; - - typedef NppStatus (*func_t)(const npp_t* pSrc, int nSrcStep, npp_t* pDst, int nDstStep, NppiSize oROI, NppiAxis flip); - }; - - template ::func_t func> struct NppMirror - { - typedef typename NppMirrorFunc::npp_t npp_t; - - static void call(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream) - { - NppStreamHandler h(stream); - - NppiSize sz; - sz.width = src.cols; - sz.height = src.rows; - - nppSafeCall( func(src.ptr(), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz, - (flipCode == 0 ? NPP_HORIZONTAL_AXIS : (flipCode > 0 ? NPP_VERTICAL_AXIS : NPP_BOTH_AXIS))) ); - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); - } - }; -} - -void cv::gpu::flip(const GpuMat& src, GpuMat& dst, int flipCode, Stream& stream) -{ - typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int flipCode, cudaStream_t stream); - static const func_t funcs[6][4] = - { - {NppMirror::call, 0, NppMirror::call, NppMirror::call}, - {0,0,0,0}, - {NppMirror::call, 0, NppMirror::call, NppMirror::call}, - {0,0,0,0}, - {NppMirror::call, 0, NppMirror::call, NppMirror::call}, - {NppMirror::call, 0, NppMirror::call, NppMirror::call} - }; - - CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S || src.depth() == CV_32F); - CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4); - - dst.create(src.size(), src.type()); - - funcs[src.depth()][src.channels() - 1](src, dst, flipCode, StreamAccessor::getStream(stream)); -} - -//////////////////////////////////////////////////////////////////////// -// LUT - -void cv::gpu::LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& s) -{ - const int cn = src.channels(); - - CV_Assert( src.type() == CV_8UC1 || src.type() == CV_8UC3 ); - CV_Assert( lut.depth() == CV_8U ); - CV_Assert( lut.channels() == 1 || lut.channels() == cn ); - CV_Assert( lut.rows * lut.cols == 256 && lut.isContinuous() ); - - dst.create(src.size(), CV_MAKE_TYPE(lut.depth(), cn)); - - NppiSize sz; - sz.height = src.rows; - sz.width = src.cols; - - Mat nppLut; - lut.convertTo(nppLut, CV_32S); - - int nValues3[] = {256, 256, 256}; - - Npp32s pLevels[256]; - for (int i = 0; i < 256; ++i) - pLevels[i] = i; - - const Npp32s* pLevels3[3]; - -#if (CUDA_VERSION <= 4020) - pLevels3[0] = pLevels3[1] = pLevels3[2] = pLevels; -#else - GpuMat d_pLevels; - d_pLevels.upload(Mat(1, 256, CV_32S, pLevels)); - pLevels3[0] = pLevels3[1] = pLevels3[2] = d_pLevels.ptr(); -#endif - - cudaStream_t stream = StreamAccessor::getStream(s); - NppStreamHandler h(stream); - - if (src.type() == CV_8UC1) - { -#if (CUDA_VERSION <= 4020) - nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr(), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz, nppLut.ptr(), pLevels, 256) ); -#else - GpuMat d_nppLut(Mat(1, 256, CV_32S, nppLut.data)); - nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr(), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz, d_nppLut.ptr(), d_pLevels.ptr(), 256) ); -#endif - } - else - { - const Npp32s* pValues3[3]; - - Mat nppLut3[3]; - if (nppLut.channels() == 1) - { -#if (CUDA_VERSION <= 4020) - pValues3[0] = pValues3[1] = pValues3[2] = nppLut.ptr(); -#else - GpuMat d_nppLut(Mat(1, 256, CV_32S, nppLut.data)); - pValues3[0] = pValues3[1] = pValues3[2] = d_nppLut.ptr(); -#endif - } - else - { - cv::split(nppLut, nppLut3); - -#if (CUDA_VERSION <= 4020) - pValues3[0] = nppLut3[0].ptr(); - pValues3[1] = nppLut3[1].ptr(); - pValues3[2] = nppLut3[2].ptr(); -#else - GpuMat d_nppLut0(Mat(1, 256, CV_32S, nppLut3[0].data)); - GpuMat d_nppLut1(Mat(1, 256, CV_32S, nppLut3[1].data)); - GpuMat d_nppLut2(Mat(1, 256, CV_32S, nppLut3[2].data)); - - pValues3[0] = d_nppLut0.ptr(); - pValues3[1] = d_nppLut1.ptr(); - pValues3[2] = d_nppLut2.ptr(); -#endif - } - - nppSafeCall( nppiLUT_Linear_8u_C3R(src.ptr(), static_cast(src.step), - dst.ptr(), static_cast(dst.step), sz, pValues3, pLevels3, nValues3) ); - } - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); -} - -//////////////////////////////////////////////////////////////////////// -// NPP magnitide - -namespace -{ - typedef NppStatus (*nppMagnitude_t)(const Npp32fc* pSrc, int nSrcStep, Npp32f* pDst, int nDstStep, NppiSize oSizeROI); - - inline void npp_magnitude(const GpuMat& src, GpuMat& dst, nppMagnitude_t func, cudaStream_t stream) - { - CV_Assert(src.type() == CV_32FC2); - - dst.create(src.size(), CV_32FC1); - - NppiSize sz; - sz.width = src.cols; - sz.height = src.rows; - - NppStreamHandler h(stream); - - nppSafeCall( func(src.ptr(), static_cast(src.step), dst.ptr(), static_cast(dst.step), sz) ); - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); - } -} - -void cv::gpu::magnitude(const GpuMat& src, GpuMat& dst, Stream& stream) -{ - npp_magnitude(src, dst, nppiMagnitude_32fc32f_C1R, StreamAccessor::getStream(stream)); -} - -void cv::gpu::magnitudeSqr(const GpuMat& src, GpuMat& dst, Stream& stream) -{ - npp_magnitude(src, dst, nppiMagnitudeSqr_32fc32f_C1R, StreamAccessor::getStream(stream)); -} - -//////////////////////////////////////////////////////////////////////// -// Polar <-> Cart - -namespace cv { namespace gpu { namespace cudev -{ - namespace mathfunc - { - void cartToPolar_gpu(PtrStepSzf x, PtrStepSzf y, PtrStepSzf mag, bool magSqr, PtrStepSzf angle, bool angleInDegrees, cudaStream_t stream); - void polarToCart_gpu(PtrStepSzf mag, PtrStepSzf angle, PtrStepSzf x, PtrStepSzf y, bool angleInDegrees, cudaStream_t stream); - } -}}} - -namespace -{ - inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat* mag, bool magSqr, GpuMat* angle, bool angleInDegrees, cudaStream_t stream) - { - using namespace ::cv::gpu::cudev::mathfunc; - - CV_Assert(x.size() == y.size() && x.type() == y.type()); - CV_Assert(x.depth() == CV_32F); - - if (mag) - mag->create(x.size(), x.type()); - if (angle) - angle->create(x.size(), x.type()); - - GpuMat x1cn = x.reshape(1); - GpuMat y1cn = y.reshape(1); - GpuMat mag1cn = mag ? mag->reshape(1) : GpuMat(); - GpuMat angle1cn = angle ? angle->reshape(1) : GpuMat(); - - cartToPolar_gpu(x1cn, y1cn, mag1cn, magSqr, angle1cn, angleInDegrees, stream); - } - - inline void polarToCart_caller(const GpuMat& mag, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, cudaStream_t stream) - { - using namespace ::cv::gpu::cudev::mathfunc; - - CV_Assert((mag.empty() || mag.size() == angle.size()) && mag.type() == angle.type()); - CV_Assert(mag.depth() == CV_32F); - - x.create(mag.size(), mag.type()); - y.create(mag.size(), mag.type()); - - GpuMat mag1cn = mag.reshape(1); - GpuMat angle1cn = angle.reshape(1); - GpuMat x1cn = x.reshape(1); - GpuMat y1cn = y.reshape(1); - - polarToCart_gpu(mag1cn, angle1cn, x1cn, y1cn, angleInDegrees, stream); - } -} - -void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst, Stream& stream) -{ - cartToPolar_caller(x, y, &dst, false, 0, false, StreamAccessor::getStream(stream)); -} - -void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst, Stream& stream) -{ - cartToPolar_caller(x, y, &dst, true, 0, false, StreamAccessor::getStream(stream)); -} - -void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, Stream& stream) -{ - cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, StreamAccessor::getStream(stream)); -} - -void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees, Stream& stream) -{ - cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, StreamAccessor::getStream(stream)); -} - -void cv::gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, Stream& stream) -{ - polarToCart_caller(magnitude, angle, x, y, angleInDegrees, StreamAccessor::getStream(stream)); -} - -//////////////////////////////////////////////////////////////////////// -// normalize - -void cv::gpu::normalize(const GpuMat& src, GpuMat& dst, double a, double b, int norm_type, int dtype, const GpuMat& mask) -{ - GpuMat norm_buf; - GpuMat cvt_buf; - normalize(src, dst, a, b, norm_type, dtype, mask, norm_buf, cvt_buf); -} - -void cv::gpu::normalize(const GpuMat& src, GpuMat& dst, double a, double b, int norm_type, int dtype, const GpuMat& mask, GpuMat& norm_buf, GpuMat& cvt_buf) -{ - double scale = 1, shift = 0; - if (norm_type == NORM_MINMAX) - { - double smin = 0, smax = 0; - double dmin = std::min(a, b), dmax = std::max(a, b); - minMax(src, &smin, &smax, mask, norm_buf); - scale = (dmax - dmin) * (smax - smin > std::numeric_limits::epsilon() ? 1.0 / (smax - smin) : 0.0); - shift = dmin - smin * scale; - } - else if (norm_type == NORM_L2 || norm_type == NORM_L1 || norm_type == NORM_INF) - { - scale = norm(src, norm_type, mask, norm_buf); - scale = scale > std::numeric_limits::epsilon() ? a / scale : 0.0; - shift = 0; - } - else - { - CV_Error(cv::Error::StsBadArg, "Unknown/unsupported norm type"); - } - - if (mask.empty()) - { - src.convertTo(dst, dtype, scale, shift); - } - else - { - src.convertTo(cvt_buf, dtype, scale, shift); - cvt_buf.copyTo(dst, mask); - } -} - -#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/calib3d.cpp b/modules/gpu/src/calib3d.cpp index 5a4e94c..9e91258 100644 --- a/modules/gpu/src/calib3d.cpp +++ b/modules/gpu/src/calib3d.cpp @@ -252,7 +252,7 @@ void cv::gpu::solvePnPRansac(const Mat& object, const Mat& image, const Mat& cam // Find the best hypothesis index Point best_idx; double best_score; - minMaxLoc(d_hypothesis_scores, NULL, &best_score, NULL, &best_idx); + gpu::minMaxLoc(d_hypothesis_scores, NULL, &best_score, NULL, &best_idx); int num_inliers = static_cast(best_score); // Extract the best hypothesis data diff --git a/modules/gpu/src/cascadeclassifier.cpp b/modules/gpu/src/cascadeclassifier.cpp index c7514bb..454c105 100644 --- a/modules/gpu/src/cascadeclassifier.cpp +++ b/modules/gpu/src/cascadeclassifier.cpp @@ -41,8 +41,6 @@ //M*/ #include "precomp.hpp" -#include -#include #include "opencv2/objdetect/objdetect_c.h" using namespace cv; @@ -75,6 +73,37 @@ public: virtual bool read(const String& classifierAsXml) = 0; }; +#ifndef HAVE_OPENCV_GPULEGACY + +struct cv::gpu::CascadeClassifier_GPU::HaarCascade : cv::gpu::CascadeClassifier_GPU::CascadeClassifierImpl +{ +public: + HaarCascade() + { + throw_no_cuda(); + } + + unsigned int process(const GpuMat&, GpuMat&, float, int, bool, bool, cv::Size, cv::Size) + { + throw_no_cuda(); + return 0; + } + + cv::Size getClassifierCvSize() const + { + throw_no_cuda(); + return cv::Size(); + } + + bool read(const String&) + { + throw_no_cuda(); + return false; + } +}; + +#else + struct cv::gpu::CascadeClassifier_GPU::HaarCascade : cv::gpu::CascadeClassifier_GPU::CascadeClassifierImpl { public: @@ -284,6 +313,8 @@ private: virtual ~HaarCascade(){} }; +#endif + cv::Size operator -(const cv::Size& a, const cv::Size& b) { return cv::Size(a.width - b.width, a.height - b.height); @@ -477,6 +508,8 @@ private: resuzeBuffer.create(frame, CV_8UC1); integral.create(frame.height + 1, integralFactor * (frame.width + 1), CV_32SC1); + +#ifdef HAVE_OPENCV_GPULEGACY NcvSize32u roiSize; roiSize.width = frame.width; roiSize.height = frame.height; @@ -487,6 +520,7 @@ private: Ncv32u bufSize; ncvSafeCall( nppiStIntegralGetSize_8u32u(roiSize, &bufSize, prop) ); integralBuffer.create(1, bufSize, CV_8UC1); +#endif candidates.create(1 , frame.width >> 1, CV_32SC4); } @@ -722,240 +756,3 @@ bool cv::gpu::CascadeClassifier_GPU::load(const String& filename) } #endif - -////////////////////////////////////////////////////////////////////////////////////////////////////// - -#if defined (HAVE_CUDA) - -struct RectConvert -{ - Rect operator()(const NcvRect32u& nr) const { return Rect(nr.x, nr.y, nr.width, nr.height); } - NcvRect32u operator()(const Rect& nr) const - { - NcvRect32u rect; - rect.x = nr.x; - rect.y = nr.y; - rect.width = nr.width; - rect.height = nr.height; - return rect; - } -}; - -void groupRectangles(std::vector &hypotheses, int groupThreshold, double eps, std::vector *weights) -{ - std::vector rects(hypotheses.size()); - std::transform(hypotheses.begin(), hypotheses.end(), rects.begin(), RectConvert()); - - if (weights) - { - std::vector weights_int; - weights_int.assign(weights->begin(), weights->end()); - cv::groupRectangles(rects, weights_int, groupThreshold, eps); - } - else - { - cv::groupRectangles(rects, groupThreshold, eps); - } - std::transform(rects.begin(), rects.end(), hypotheses.begin(), RectConvert()); - hypotheses.resize(rects.size()); -} - -NCVStatus loadFromXML(const String &filename, - HaarClassifierCascadeDescriptor &haar, - std::vector &haarStages, - std::vector &haarClassifierNodes, - std::vector &haarFeatures) -{ - NCVStatus ncvStat; - - haar.NumStages = 0; - haar.NumClassifierRootNodes = 0; - haar.NumClassifierTotalNodes = 0; - haar.NumFeatures = 0; - haar.ClassifierSize.width = 0; - haar.ClassifierSize.height = 0; - haar.bHasStumpsOnly = true; - haar.bNeedsTiltedII = false; - Ncv32u curMaxTreeDepth; - - std::vector xmlFileCont; - - std::vector h_TmpClassifierNotRootNodes; - haarStages.resize(0); - haarClassifierNodes.resize(0); - haarFeatures.resize(0); - - Ptr oldCascade = (CvHaarClassifierCascade*)cvLoad(filename.c_str(), 0, 0, 0); - if (oldCascade.empty()) - { - return NCV_HAAR_XML_LOADING_EXCEPTION; - } - - haar.ClassifierSize.width = oldCascade->orig_window_size.width; - haar.ClassifierSize.height = oldCascade->orig_window_size.height; - - int stagesCound = oldCascade->count; - for(int s = 0; s < stagesCound; ++s) // by stages - { - HaarStage64 curStage; - curStage.setStartClassifierRootNodeOffset(static_cast(haarClassifierNodes.size())); - - curStage.setStageThreshold(oldCascade->stage_classifier[s].threshold); - - int treesCount = oldCascade->stage_classifier[s].count; - for(int t = 0; t < treesCount; ++t) // by trees - { - Ncv32u nodeId = 0; - CvHaarClassifier* tree = &oldCascade->stage_classifier[s].classifier[t]; - - int nodesCount = tree->count; - for(int n = 0; n < nodesCount; ++n) //by features - { - CvHaarFeature* feature = &tree->haar_feature[n]; - - HaarClassifierNode128 curNode; - curNode.setThreshold(tree->threshold[n]); - - NcvBool bIsLeftNodeLeaf = false; - NcvBool bIsRightNodeLeaf = false; - - HaarClassifierNodeDescriptor32 nodeLeft; - if ( tree->left[n] <= 0 ) - { - Ncv32f leftVal = tree->alpha[-tree->left[n]]; - ncvStat = nodeLeft.create(leftVal); - ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat); - bIsLeftNodeLeaf = true; - } - else - { - Ncv32u leftNodeOffset = tree->left[n]; - nodeLeft.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + leftNodeOffset - 1)); - haar.bHasStumpsOnly = false; - } - curNode.setLeftNodeDesc(nodeLeft); - - HaarClassifierNodeDescriptor32 nodeRight; - if ( tree->right[n] <= 0 ) - { - Ncv32f rightVal = tree->alpha[-tree->right[n]]; - ncvStat = nodeRight.create(rightVal); - ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat); - bIsRightNodeLeaf = true; - } - else - { - Ncv32u rightNodeOffset = tree->right[n]; - nodeRight.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + rightNodeOffset - 1)); - haar.bHasStumpsOnly = false; - } - curNode.setRightNodeDesc(nodeRight); - - Ncv32u tiltedVal = feature->tilted; - haar.bNeedsTiltedII = (tiltedVal != 0); - - Ncv32u featureId = 0; - for(int l = 0; l < CV_HAAR_FEATURE_MAX; ++l) //by rects - { - Ncv32u rectX = feature->rect[l].r.x; - Ncv32u rectY = feature->rect[l].r.y; - Ncv32u rectWidth = feature->rect[l].r.width; - Ncv32u rectHeight = feature->rect[l].r.height; - - Ncv32f rectWeight = feature->rect[l].weight; - - if (rectWeight == 0/* && rectX == 0 &&rectY == 0 && rectWidth == 0 && rectHeight == 0*/) - break; - - HaarFeature64 curFeature; - ncvStat = curFeature.setRect(rectX, rectY, rectWidth, rectHeight, haar.ClassifierSize.width, haar.ClassifierSize.height); - curFeature.setWeight(rectWeight); - ncvAssertReturn(NCV_SUCCESS == ncvStat, ncvStat); - haarFeatures.push_back(curFeature); - - featureId++; - } - - HaarFeatureDescriptor32 tmpFeatureDesc; - ncvStat = tmpFeatureDesc.create(haar.bNeedsTiltedII, bIsLeftNodeLeaf, bIsRightNodeLeaf, - featureId, static_cast(haarFeatures.size()) - featureId); - ncvAssertReturn(NCV_SUCCESS == ncvStat, ncvStat); - curNode.setFeatureDesc(tmpFeatureDesc); - - if (!nodeId) - { - //root node - haarClassifierNodes.push_back(curNode); - curMaxTreeDepth = 1; - } - else - { - //other node - h_TmpClassifierNotRootNodes.push_back(curNode); - curMaxTreeDepth++; - } - - nodeId++; - } - } - - curStage.setNumClassifierRootNodes(treesCount); - haarStages.push_back(curStage); - } - - //fill in cascade stats - haar.NumStages = static_cast(haarStages.size()); - haar.NumClassifierRootNodes = static_cast(haarClassifierNodes.size()); - haar.NumClassifierTotalNodes = static_cast(haar.NumClassifierRootNodes + h_TmpClassifierNotRootNodes.size()); - haar.NumFeatures = static_cast(haarFeatures.size()); - - //merge root and leaf nodes in one classifiers array - Ncv32u offsetRoot = static_cast(haarClassifierNodes.size()); - for (Ncv32u i=0; i> 2) | - (((uint)green >> 2) << 8) | - (((uint)red >> 2) << 16) | - (uint)alpha); - - return ARGBpixel; - } - - // CUDA kernel for outputing the final ARGB output from NV12 - - #define COLOR_COMPONENT_BIT_SIZE 10 - #define COLOR_COMPONENT_MASK 0x3FF - - __global__ void NV12ToARGB(uchar* srcImage, size_t nSourcePitch, - uint* dstImage, size_t nDestPitch, - uint width, uint height) - { - // Pad borders with duplicate pixels, and we multiply by 2 because we process 2 pixels per thread - const int x = blockIdx.x * (blockDim.x << 1) + (threadIdx.x << 1); - const int y = blockIdx.y * blockDim.y + threadIdx.y; - - if (x >= width || y >= height) - return; - - // Read 2 Luma components at a time, so we don't waste processing since CbCr are decimated this way. - // if we move to texture we could read 4 luminance values - - uint yuv101010Pel[2]; - - yuv101010Pel[0] = (srcImage[y * nSourcePitch + x ]) << 2; - yuv101010Pel[1] = (srcImage[y * nSourcePitch + x + 1]) << 2; - - const size_t chromaOffset = nSourcePitch * height; - - const int y_chroma = y >> 1; - - if (y & 1) // odd scanline ? - { - uint chromaCb = srcImage[chromaOffset + y_chroma * nSourcePitch + x ]; - uint chromaCr = srcImage[chromaOffset + y_chroma * nSourcePitch + x + 1]; - - if (y_chroma < ((height >> 1) - 1)) // interpolate chroma vertically - { - chromaCb = (chromaCb + srcImage[chromaOffset + (y_chroma + 1) * nSourcePitch + x ] + 1) >> 1; - chromaCr = (chromaCr + srcImage[chromaOffset + (y_chroma + 1) * nSourcePitch + x + 1] + 1) >> 1; - } - - yuv101010Pel[0] |= (chromaCb << ( COLOR_COMPONENT_BIT_SIZE + 2)); - yuv101010Pel[0] |= (chromaCr << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2)); - - yuv101010Pel[1] |= (chromaCb << ( COLOR_COMPONENT_BIT_SIZE + 2)); - yuv101010Pel[1] |= (chromaCr << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2)); - } - else - { - yuv101010Pel[0] |= ((uint)srcImage[chromaOffset + y_chroma * nSourcePitch + x ] << ( COLOR_COMPONENT_BIT_SIZE + 2)); - yuv101010Pel[0] |= ((uint)srcImage[chromaOffset + y_chroma * nSourcePitch + x + 1] << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2)); - - yuv101010Pel[1] |= ((uint)srcImage[chromaOffset + y_chroma * nSourcePitch + x ] << ( COLOR_COMPONENT_BIT_SIZE + 2)); - yuv101010Pel[1] |= ((uint)srcImage[chromaOffset + y_chroma * nSourcePitch + x + 1] << ((COLOR_COMPONENT_BIT_SIZE << 1) + 2)); - } - - // this steps performs the color conversion - uint yuvi[6]; - float red[2], green[2], blue[2]; - - yuvi[0] = (yuv101010Pel[0] & COLOR_COMPONENT_MASK ); - yuvi[1] = ((yuv101010Pel[0] >> COLOR_COMPONENT_BIT_SIZE) & COLOR_COMPONENT_MASK); - yuvi[2] = ((yuv101010Pel[0] >> (COLOR_COMPONENT_BIT_SIZE << 1)) & COLOR_COMPONENT_MASK); - - yuvi[3] = (yuv101010Pel[1] & COLOR_COMPONENT_MASK ); - yuvi[4] = ((yuv101010Pel[1] >> COLOR_COMPONENT_BIT_SIZE) & COLOR_COMPONENT_MASK); - yuvi[5] = ((yuv101010Pel[1] >> (COLOR_COMPONENT_BIT_SIZE << 1)) & COLOR_COMPONENT_MASK); - - // YUV to RGB Transformation conversion - YUV2RGB(&yuvi[0], &red[0], &green[0], &blue[0]); - YUV2RGB(&yuvi[3], &red[1], &green[1], &blue[1]); - - // Clamp the results to RGBA - - const size_t dstImagePitch = nDestPitch >> 2; - - dstImage[y * dstImagePitch + x ] = RGBAPACK_10bit(red[0], green[0], blue[0], constAlpha); - dstImage[y * dstImagePitch + x + 1 ] = RGBAPACK_10bit(red[1], green[1], blue[1], constAlpha); - } - - void NV12ToARGB_gpu(const PtrStepb decodedFrame, PtrStepSz interopFrame, cudaStream_t stream) - { - dim3 block(32, 8); - dim3 grid(divUp(interopFrame.cols, 2 * block.x), divUp(interopFrame.rows, block.y)); - - NV12ToARGB<<>>(decodedFrame.data, decodedFrame.step, interopFrame.data, interopFrame.step, - interopFrame.cols, interopFrame.rows); - - cudaSafeCall( cudaGetLastError() ); - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); - } - } -}}} - -#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/element_operations.cu b/modules/gpu/src/cuda/element_operations.cu deleted file mode 100644 index e15ef9f..0000000 --- a/modules/gpu/src/cuda/element_operations.cu +++ /dev/null @@ -1,2636 +0,0 @@ -/*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 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*/ - -#if !defined CUDA_DISABLER - -#include "opencv2/core/cuda/common.hpp" -#include "opencv2/core/cuda/functional.hpp" -#include "opencv2/core/cuda/vec_math.hpp" -#include "opencv2/core/cuda/transform.hpp" -#include "opencv2/core/cuda/limits.hpp" -#include "opencv2/core/cuda/saturate_cast.hpp" -#include "opencv2/core/cuda/simd_functions.hpp" - -using namespace cv::gpu; -using namespace cv::gpu::cudev; - -namespace arithm -{ - template struct ArithmFuncTraits - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 1 }; - }; - - template <> struct ArithmFuncTraits<1, 1> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<1, 2> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<1, 4> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - - template <> struct ArithmFuncTraits<2, 1> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<2, 2> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<2, 4> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - - template <> struct ArithmFuncTraits<4, 1> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<4, 2> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; - template <> struct ArithmFuncTraits<4, 4> - { - enum { simple_block_dim_x = 32 }; - enum { simple_block_dim_y = 8 }; - - enum { smart_block_dim_x = 32 }; - enum { smart_block_dim_y = 8 }; - enum { smart_shift = 4 }; - }; -} - -////////////////////////////////////////////////////////////////////////// -// addMat - -namespace arithm -{ - struct VAdd4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vadd4(a, b); - } - - __host__ __device__ __forceinline__ VAdd4() {} - __host__ __device__ __forceinline__ VAdd4(const VAdd4&) {} - }; - - //////////////////////////////////// - - struct VAdd2 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vadd2(a, b); - } - - __host__ __device__ __forceinline__ VAdd2() {} - __host__ __device__ __forceinline__ VAdd2(const VAdd2&) {} - }; - - //////////////////////////////////// - - template struct AddMat : binary_function - { - __device__ __forceinline__ D operator ()(T a, T b) const - { - return saturate_cast(a + b); - } - - __host__ __device__ __forceinline__ AddMat() {} - __host__ __device__ __forceinline__ AddMat(const AddMat&) {} - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits< arithm::VAdd4 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template <> struct TransformFunctorTraits< arithm::VAdd2 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template struct TransformFunctorTraits< arithm::AddMat > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void addMat_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VAdd4(), WithOutMask(), stream); - } - - void addMat_v2(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VAdd2(), WithOutMask(), stream); - } - - template - void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream) - { - if (mask.data) - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, AddMat(), mask, stream); - else - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, AddMat(), WithOutMask(), stream); - } - - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// addScalar - -namespace arithm -{ - template struct AddScalar : unary_function - { - S val; - - explicit AddScalar(S val_) : val(val_) {} - - __device__ __forceinline__ D operator ()(T a) const - { - return saturate_cast(a + val); - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::AddScalar > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream) - { - AddScalar op(static_cast(val)); - - if (mask.data) - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, mask, stream); - else - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void addScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// subMat - -namespace arithm -{ - struct VSub4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vsub4(a, b); - } - - __host__ __device__ __forceinline__ VSub4() {} - __host__ __device__ __forceinline__ VSub4(const VSub4&) {} - }; - - //////////////////////////////////// - - struct VSub2 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vsub2(a, b); - } - - __host__ __device__ __forceinline__ VSub2() {} - __host__ __device__ __forceinline__ VSub2(const VSub2&) {} - }; - - //////////////////////////////////// - - template struct SubMat : binary_function - { - __device__ __forceinline__ D operator ()(T a, T b) const - { - return saturate_cast(a - b); - } - - __host__ __device__ __forceinline__ SubMat() {} - __host__ __device__ __forceinline__ SubMat(const SubMat&) {} - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits< arithm::VSub4 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template <> struct TransformFunctorTraits< arithm::VSub2 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template struct TransformFunctorTraits< arithm::SubMat > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void subMat_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VSub4(), WithOutMask(), stream); - } - - void subMat_v2(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VSub2(), WithOutMask(), stream); - } - - template - void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream) - { - if (mask.data) - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, SubMat(), mask, stream); - else - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, SubMat(), WithOutMask(), stream); - } - - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// subScalar - -namespace arithm -{ - template - void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream) - { - AddScalar op(-static_cast(val)); - - if (mask.data) - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, mask, stream); - else - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - //template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); - template void subScalar(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// mulMat - -namespace arithm -{ - struct Mul_8uc4_32f : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, float b) const - { - uint res = 0; - - res |= (saturate_cast((0xffu & (a )) * b) ); - res |= (saturate_cast((0xffu & (a >> 8)) * b) << 8); - res |= (saturate_cast((0xffu & (a >> 16)) * b) << 16); - res |= (saturate_cast((0xffu & (a >> 24)) * b) << 24); - - return res; - } - - __host__ __device__ __forceinline__ Mul_8uc4_32f() {} - __host__ __device__ __forceinline__ Mul_8uc4_32f(const Mul_8uc4_32f&) {} - }; - - struct Mul_16sc4_32f : binary_function - { - __device__ __forceinline__ short4 operator ()(short4 a, float b) const - { - return make_short4(saturate_cast(a.x * b), saturate_cast(a.y * b), - saturate_cast(a.z * b), saturate_cast(a.w * b)); - } - - __host__ __device__ __forceinline__ Mul_16sc4_32f() {} - __host__ __device__ __forceinline__ Mul_16sc4_32f(const Mul_16sc4_32f&) {} - }; - - template struct Mul : binary_function - { - __device__ __forceinline__ D operator ()(T a, T b) const - { - return saturate_cast(a * b); - } - - __host__ __device__ __forceinline__ Mul() {} - __host__ __device__ __forceinline__ Mul(const Mul&) {} - }; - - template struct MulScale : binary_function - { - S scale; - - explicit MulScale(S scale_) : scale(scale_) {} - - __device__ __forceinline__ D operator ()(T a, T b) const - { - return saturate_cast(scale * a * b); - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits : arithm::ArithmFuncTraits - { - }; - - template struct TransformFunctorTraits< arithm::Mul > : arithm::ArithmFuncTraits - { - }; - - template struct TransformFunctorTraits< arithm::MulScale > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void mulMat_8uc4_32f(PtrStepSz src1, PtrStepSzf src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, Mul_8uc4_32f(), WithOutMask(), stream); - } - - void mulMat_16sc4_32f(PtrStepSz src1, PtrStepSzf src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, Mul_16sc4_32f(), WithOutMask(), stream); - } - - template - void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream) - { - if (scale == 1) - { - Mul op; - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, op, WithOutMask(), stream); - } - else - { - MulScale op(static_cast(scale)); - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, op, WithOutMask(), stream); - } - } - - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void mulMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// mulScalar - -namespace arithm -{ - template struct MulScalar : unary_function - { - S val; - - explicit MulScalar(S val_) : val(val_) {} - - __device__ __forceinline__ D operator ()(T a) const - { - return saturate_cast(a * val); - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::MulScalar > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream) - { - MulScalar op(static_cast(val)); - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void mulScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// divMat - -namespace arithm -{ - struct Div_8uc4_32f : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, float b) const - { - uint res = 0; - - if (b != 0) - { - b = 1.0f / b; - res |= (saturate_cast((0xffu & (a )) * b) ); - res |= (saturate_cast((0xffu & (a >> 8)) * b) << 8); - res |= (saturate_cast((0xffu & (a >> 16)) * b) << 16); - res |= (saturate_cast((0xffu & (a >> 24)) * b) << 24); - } - - return res; - } - }; - - struct Div_16sc4_32f : binary_function - { - __device__ __forceinline__ short4 operator ()(short4 a, float b) const - { - return b != 0 ? make_short4(saturate_cast(a.x / b), saturate_cast(a.y / b), - saturate_cast(a.z / b), saturate_cast(a.w / b)) - : make_short4(0,0,0,0); - } - }; - - template struct Div : binary_function - { - __device__ __forceinline__ D operator ()(T a, T b) const - { - return b != 0 ? saturate_cast(a / b) : 0; - } - - __host__ __device__ __forceinline__ Div() {} - __host__ __device__ __forceinline__ Div(const Div&) {} - }; - template struct Div : binary_function - { - __device__ __forceinline__ float operator ()(T a, T b) const - { - return b != 0 ? static_cast(a) / b : 0; - } - - __host__ __device__ __forceinline__ Div() {} - __host__ __device__ __forceinline__ Div(const Div&) {} - }; - template struct Div : binary_function - { - __device__ __forceinline__ double operator ()(T a, T b) const - { - return b != 0 ? static_cast(a) / b : 0; - } - - __host__ __device__ __forceinline__ Div() {} - __host__ __device__ __forceinline__ Div(const Div&) {} - }; - - template struct DivScale : binary_function - { - S scale; - - explicit DivScale(S scale_) : scale(scale_) {} - - __device__ __forceinline__ D operator ()(T a, T b) const - { - return b != 0 ? saturate_cast(scale * a / b) : 0; - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits : arithm::ArithmFuncTraits - { - }; - - template struct TransformFunctorTraits< arithm::Div > : arithm::ArithmFuncTraits - { - }; - - template struct TransformFunctorTraits< arithm::DivScale > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void divMat_8uc4_32f(PtrStepSz src1, PtrStepSzf src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, Div_8uc4_32f(), WithOutMask(), stream); - } - - void divMat_16sc4_32f(PtrStepSz src1, PtrStepSzf src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, Div_16sc4_32f(), WithOutMask(), stream); - } - - template - void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream) - { - if (scale == 1) - { - Div op; - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, op, WithOutMask(), stream); - } - else - { - DivScale op(static_cast(scale)); - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, op, WithOutMask(), stream); - } - } - - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - //template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); - template void divMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// divScalar - -namespace arithm -{ - template - void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream) - { - MulScalar op(static_cast(1.0 / val)); - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// divInv - -namespace arithm -{ - template struct DivInv : unary_function - { - S val; - - explicit DivInv(S val_) : val(val_) {} - - __device__ __forceinline__ D operator ()(T a) const - { - return a != 0 ? saturate_cast(val / a) : 0; - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::DivInv > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream) - { - DivInv op(static_cast(val)); - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - //template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); - template void divInv(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// absDiffMat - -namespace arithm -{ - struct VAbsDiff4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vabsdiff4(a, b); - } - - __host__ __device__ __forceinline__ VAbsDiff4() {} - __host__ __device__ __forceinline__ VAbsDiff4(const VAbsDiff4&) {} - }; - - //////////////////////////////////// - - struct VAbsDiff2 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vabsdiff2(a, b); - } - - __host__ __device__ __forceinline__ VAbsDiff2() {} - __host__ __device__ __forceinline__ VAbsDiff2(const VAbsDiff2&) {} - }; - - //////////////////////////////////// - - __device__ __forceinline__ int _abs(int a) - { - return ::abs(a); - } - __device__ __forceinline__ float _abs(float a) - { - return ::fabsf(a); - } - __device__ __forceinline__ double _abs(double a) - { - return ::fabs(a); - } - - template struct AbsDiffMat : binary_function - { - __device__ __forceinline__ T operator ()(T a, T b) const - { - return saturate_cast(_abs(a - b)); - } - - __host__ __device__ __forceinline__ AbsDiffMat() {} - __host__ __device__ __forceinline__ AbsDiffMat(const AbsDiffMat&) {} - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits< arithm::VAbsDiff4 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template <> struct TransformFunctorTraits< arithm::VAbsDiff2 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template struct TransformFunctorTraits< arithm::AbsDiffMat > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void absDiffMat_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VAbsDiff4(), WithOutMask(), stream); - } - - void absDiffMat_v2(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VAbsDiff2(), WithOutMask(), stream); - } - - template - void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src1, (PtrStepSz) src2, (PtrStepSz) dst, AbsDiffMat(), WithOutMask(), stream); - } - - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffMat(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// absDiffScalar - -namespace arithm -{ - template struct AbsDiffScalar : unary_function - { - S val; - - explicit AbsDiffScalar(S val_) : val(val_) {} - - __device__ __forceinline__ T operator ()(T a) const - { - abs_func f; - return saturate_cast(f(a - val)); - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::AbsDiffScalar > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void absDiffScalar(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream) - { - AbsDiffScalar op(static_cast(val)); - - cudev::transform((PtrStepSz) src1, (PtrStepSz) dst, op, WithOutMask(), stream); - } - - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); - template void absDiffScalar(PtrStepSzb src1, double src2, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// absMat - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< abs_func > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src, (PtrStepSz) dst, abs_func(), WithOutMask(), stream); - } - - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void absMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// sqrMat - -namespace arithm -{ - template struct Sqr : unary_function - { - __device__ __forceinline__ T operator ()(T x) const - { - return saturate_cast(x * x); - } - - __host__ __device__ __forceinline__ Sqr() {} - __host__ __device__ __forceinline__ Sqr(const Sqr&) {} - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::Sqr > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src, (PtrStepSz) dst, Sqr(), WithOutMask(), stream); - } - - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// sqrtMat - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< sqrt_func > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src, (PtrStepSz) dst, sqrt_func(), WithOutMask(), stream); - } - - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void sqrtMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// logMat - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< log_func > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src, (PtrStepSz) dst, log_func(), WithOutMask(), stream); - } - - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void logMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////// -// expMat - -namespace arithm -{ - template struct Exp : unary_function - { - __device__ __forceinline__ T operator ()(T x) const - { - exp_func f; - return saturate_cast(f(x)); - } - - __host__ __device__ __forceinline__ Exp() {} - __host__ __device__ __forceinline__ Exp(const Exp&) {} - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template struct TransformFunctorTraits< arithm::Exp > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - template - void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream) - { - cudev::transform((PtrStepSz) src, (PtrStepSz) dst, Exp(), WithOutMask(), stream); - } - - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); - template void expMat(PtrStepSzb src, PtrStepSzb dst, cudaStream_t stream); -} - -////////////////////////////////////////////////////////////////////////////////////// -// cmpMat - -namespace arithm -{ - struct VCmpEq4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vcmpeq4(a, b); - } - - __host__ __device__ __forceinline__ VCmpEq4() {} - __host__ __device__ __forceinline__ VCmpEq4(const VCmpEq4&) {} - }; - struct VCmpNe4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vcmpne4(a, b); - } - - __host__ __device__ __forceinline__ VCmpNe4() {} - __host__ __device__ __forceinline__ VCmpNe4(const VCmpNe4&) {} - }; - struct VCmpLt4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vcmplt4(a, b); - } - - __host__ __device__ __forceinline__ VCmpLt4() {} - __host__ __device__ __forceinline__ VCmpLt4(const VCmpLt4&) {} - }; - struct VCmpLe4 : binary_function - { - __device__ __forceinline__ uint operator ()(uint a, uint b) const - { - return vcmple4(a, b); - } - - __host__ __device__ __forceinline__ VCmpLe4() {} - __host__ __device__ __forceinline__ VCmpLe4(const VCmpLe4&) {} - }; - - //////////////////////////////////// - - template - struct Cmp : binary_function - { - __device__ __forceinline__ uchar operator()(T a, T b) const - { - Op op; - return -op(a, b); - } - }; -} - -namespace cv { namespace gpu { namespace cudev -{ - template <> struct TransformFunctorTraits< arithm::VCmpEq4 > : arithm::ArithmFuncTraits - { - }; - template <> struct TransformFunctorTraits< arithm::VCmpNe4 > : arithm::ArithmFuncTraits - { - }; - template <> struct TransformFunctorTraits< arithm::VCmpLt4 > : arithm::ArithmFuncTraits - { - }; - template <> struct TransformFunctorTraits< arithm::VCmpLe4 > : arithm::ArithmFuncTraits - { - }; - - //////////////////////////////////// - - template struct TransformFunctorTraits< arithm::Cmp > : arithm::ArithmFuncTraits - { - }; -}}} - -namespace arithm -{ - void cmpMatEq_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VCmpEq4(), WithOutMask(), stream); - } - void cmpMatNe_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VCmpNe4(), WithOutMask(), stream); - } - void cmpMatLt_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VCmpLt4(), WithOutMask(), stream); - } - void cmpMatLe_v4(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, cudaStream_t stream) - { - cudev::transform(src1, src2, dst, VCmpLe4(), WithOutMask(), stream); - } - - template