From ddca47040b01ae7fff0f6028fbc1acb3f3f1e0d4 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 16 Aug 2012 16:23:27 +0400 Subject: [PATCH 01/40] updated gpu accuracy tests added posibility to specify device on which tests will be executed --- modules/gpu/test/main.cpp | 91 +++++++++++------ modules/gpu/test/precomp.hpp | 1 + modules/gpu/test/utility.cpp | 183 +++++++++++++++++++++++++++-------- modules/gpu/test/utility.hpp | 21 ++-- 4 files changed, 219 insertions(+), 77 deletions(-) diff --git a/modules/gpu/test/main.cpp b/modules/gpu/test/main.cpp index 6a8c67d79..6df7db0a1 100644 --- a/modules/gpu/test/main.cpp +++ b/modules/gpu/test/main.cpp @@ -49,35 +49,39 @@ using namespace cv::gpu; using namespace cvtest; using namespace testing; -void print_info() +void printInfo() { - printf("\n"); #if defined _WIN32 # if defined _WIN64 - puts("OS: Windows 64"); + puts("OS: Windows x64"); # else - puts("OS: Windows 32"); + puts("OS: Windows x32"); # endif #elif defined linux # if defined _LP64 - puts("OS: Linux 64"); + puts("OS: Linux x64"); # else - puts("OS: Linux 32"); + puts("OS: Linux x32"); # endif #elif defined __APPLE__ # if defined _LP64 - puts("OS: Apple 64"); + puts("OS: Apple x64"); # else - puts("OS: Apple 32"); + puts("OS: Apple x32"); # endif #endif - int deviceCount = getCudaEnabledDeviceCount(); int driver; cudaDriverGetVersion(&driver); printf("CUDA Driver version: %d\n", driver); printf("CUDA Runtime version: %d\n", CUDART_VERSION); + + puts("GPU module was compiled for the following GPU archs:"); + printf(" BIN: %s\n", CUDA_ARCH_BIN); + printf(" PTX: %s\n\n", CUDA_ARCH_PTX); + + int deviceCount = getCudaEnabledDeviceCount(); printf("CUDA device count: %d\n\n", deviceCount); for (int i = 0; i < deviceCount; ++i) @@ -87,17 +91,13 @@ void print_info() printf("Device %d:\n", i); printf(" Name: %s\n", info.name().c_str()); printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion()); + printf(" Multi Processor Count: %d\n", info.multiProcessorCount()); printf(" Total memory: %d Mb\n", static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0)); printf(" Free memory: %d Mb\n", static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0)); - if (info.isCompatible()) - puts(" This device is compatible with current GPU module build\n"); - else - puts(" This device is NOT compatible with current GPU module build\n"); + if (!info.isCompatible()) + puts(" !!! This device is NOT compatible with current GPU module build\n"); + printf("\n"); } - - puts("GPU module was compiled for the following GPU archs:"); - printf(" BIN: %s\n", CUDA_ARCH_BIN); - printf(" PTX: %s\n\n", CUDA_ARCH_PTX); } enum OutputLevel @@ -111,25 +111,56 @@ extern OutputLevel nvidiaTestOutputLevel; int main(int argc, char** argv) { - TS::ptr()->init("gpu"); - InitGoogleTest(&argc, argv); + try + { + CommandLineParser parser(argc, (const char**)argv, + "{ print_info_only | print_info_only | false | Print information about system and exit }" + "{ device | device | -1 | Device on which tests will be executed (-1 means all devices) }" + "{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }"); - const char* keys ="{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }"; + printInfo(); - CommandLineParser parser(argc, (const char**)argv, keys); + if (parser.get("print_info_only")) + return 0; - string outputLevel = parser.get("nvtest_output_level", "none"); + int device = parser.get("device"); + if (device < 0) + { + DeviceManager::instance().loadAll(); + std::cout << "Run tests on all supported devices\n" << std::endl; + } + else + { + DeviceManager::instance().load(device); + std::cout << "Run tests on device " << device << '\n' << std::endl; + } - if (outputLevel == "none") - nvidiaTestOutputLevel = OutputLevelNone; - else if (outputLevel == "compact") - nvidiaTestOutputLevel = OutputLevelCompact; - else if (outputLevel == "full") - nvidiaTestOutputLevel = OutputLevelFull; + string outputLevel = parser.get("nvtest_output_level"); - print_info(); + if (outputLevel == "none") + nvidiaTestOutputLevel = OutputLevelNone; + else if (outputLevel == "compact") + nvidiaTestOutputLevel = OutputLevelCompact; + else if (outputLevel == "full") + nvidiaTestOutputLevel = OutputLevelFull; - return RUN_ALL_TESTS(); + TS::ptr()->init("gpu"); + InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); + } + catch (const exception& e) + { + cerr << e.what() << endl; + return -1; + } + catch (...) + { + cerr << "Unknown error" << endl; + return -1; + } + + return 0; } #else // HAVE_CUDA diff --git a/modules/gpu/test/precomp.hpp b/modules/gpu/test/precomp.hpp index afc3be855..753367cce 100644 --- a/modules/gpu/test/precomp.hpp +++ b/modules/gpu/test/precomp.hpp @@ -56,6 +56,7 @@ #include #include #include +#include #include "cvconfig.h" #include "opencv2/core/core.hpp" diff --git a/modules/gpu/test/utility.cpp b/modules/gpu/test/utility.cpp index bc73d3003..148c9d202 100644 --- a/modules/gpu/test/utility.cpp +++ b/modules/gpu/test/utility.cpp @@ -46,6 +46,7 @@ using namespace cv; using namespace cv::gpu; using namespace cvtest; using namespace testing; +using namespace testing::internal; ////////////////////////////////////////////////////////////////////// // random generators @@ -108,12 +109,12 @@ GpuMat loadMat(const Mat& m, bool useRoi) ////////////////////////////////////////////////////////////////////// // Image load -Mat readImage(const string& fileName, int flags) +Mat readImage(const std::string& fileName, int flags) { - return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags); + return imread(TS::ptr()->get_data_path() + fileName, flags); } -Mat readImageType(const string& fname, int type) +Mat readImageType(const std::string& fname, int type) { Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR); if (CV_MAT_CN(type) == 4) @@ -134,50 +135,150 @@ bool supportFeature(const DeviceInfo& info, FeatureSet feature) return TargetArchs::builtWith(feature) && info.supports(feature); } -const vector& devices() +DeviceManager& DeviceManager::instance() { - static vector devs; - static bool first = true; - - if (first) - { - int deviceCount = getCudaEnabledDeviceCount(); - - devs.reserve(deviceCount); - - for (int i = 0; i < deviceCount; ++i) - { - DeviceInfo info(i); - if (info.isCompatible()) - devs.push_back(info); - } - - first = false; - } - - return devs; + static DeviceManager obj; + return obj; } -vector devices(FeatureSet feature) +void DeviceManager::load(int i) { - const vector& d = devices(); + devices_.clear(); + devices_.reserve(1); - vector devs_filtered; + ostringstream msg; - if (TargetArchs::builtWith(feature)) + if (i < 0 || i >= getCudaEnabledDeviceCount()) { - devs_filtered.reserve(d.size()); - - for (size_t i = 0, size = d.size(); i < size; ++i) - { - const DeviceInfo& info = d[i]; - - if (info.supports(feature)) - devs_filtered.push_back(info); - } + msg << "Incorrect device number - " << i; + throw runtime_error(msg.str()); } - return devs_filtered; + DeviceInfo info(i); + + if (!info.isCompatible()) + { + msg << "Device " << i << " [" << info.name() << "] is NOT compatible with current GPU module build"; + throw runtime_error(msg.str()); + } + + devices_.push_back(info); +} + +void DeviceManager::loadAll() +{ + int deviceCount = getCudaEnabledDeviceCount(); + + devices_.clear(); + devices_.reserve(deviceCount); + + for (int i = 0; i < deviceCount; ++i) + { + DeviceInfo info(i); + if (info.isCompatible()) + { + devices_.push_back(info); + } + } +} + +class DevicesGenerator : public ParamGeneratorInterface +{ +public: + ~DevicesGenerator(); + + ParamIteratorInterface* Begin() const; + ParamIteratorInterface* End() const; + +private: + class Iterator : public ParamIteratorInterface + { + public: + Iterator(const ParamGeneratorInterface* base, vector::const_iterator iterator); + + virtual ~Iterator(); + + virtual const ParamGeneratorInterface* BaseGenerator() const; + + virtual void Advance(); + + virtual ParamIteratorInterface* Clone() const; + + virtual const DeviceInfo* Current() const; + + virtual bool Equals(const ParamIteratorInterface& other) const; + + private: + Iterator(const Iterator& other); + + const ParamGeneratorInterface* const base_; + vector::const_iterator iterator_; + + mutable DeviceInfo value_; + }; +}; + +DevicesGenerator::~DevicesGenerator() +{ +} + +ParamIteratorInterface* DevicesGenerator::Begin() const +{ + return new Iterator(this, DeviceManager::instance().values().begin()); +} + +ParamIteratorInterface* DevicesGenerator::End() const +{ + return new Iterator(this, DeviceManager::instance().values().end()); +} + +DevicesGenerator::Iterator::Iterator(const ParamGeneratorInterface* base, vector::const_iterator iterator) + : base_(base), iterator_(iterator) +{ +} + +DevicesGenerator::Iterator::~Iterator() +{ +} + +const ParamGeneratorInterface* DevicesGenerator::Iterator::BaseGenerator() const +{ + return base_; +} + +void DevicesGenerator::Iterator::Advance() +{ + ++iterator_; +} + +ParamIteratorInterface* DevicesGenerator::Iterator::Clone() const +{ + return new Iterator(*this); +} + +const DeviceInfo* DevicesGenerator::Iterator::Current() const +{ + value_ = *iterator_; + return &value_; +} + +bool DevicesGenerator::Iterator::Equals(const ParamIteratorInterface& other) const +{ + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << endl; + + return iterator_ == CheckedDowncastToActualType(&other)->iterator_; +} + +DevicesGenerator::Iterator::Iterator(const Iterator& other) : + ParamIteratorInterface(), base_(other.base_), iterator_(other.iterator_) +{ +} + +ParamGenerator DevicesGenerator_() +{ + return ParamGenerator(new DevicesGenerator); } ////////////////////////////////////////////////////////////////////// @@ -250,7 +351,7 @@ void minMaxLocGold(const Mat& src, double* minVal_, double* maxVal_, Point* minL namespace { - template string printMatValImpl(const Mat& m, Point p) + template std::string printMatValImpl(const Mat& m, Point p) { const int cn = m.channels(); @@ -269,9 +370,9 @@ namespace return ostr.str(); } - string printMatVal(const Mat& m, Point p) + std::string printMatVal(const Mat& m, Point p) { - typedef string (*func_t)(const Mat& m, Point p); + typedef std::string (*func_t)(const Mat& m, Point p); static const func_t funcs[] = { diff --git a/modules/gpu/test/utility.hpp b/modules/gpu/test/utility.hpp index 3ad02decb..b36f177f6 100644 --- a/modules/gpu/test/utility.hpp +++ b/modules/gpu/test/utility.hpp @@ -80,14 +80,23 @@ cv::Mat readImageType(const std::string& fname, int type); //! return true if device supports specified feature and gpu module was built with support the feature. bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature); -//! return all devices compatible with current gpu module build. -const std::vector& devices(); +class DeviceManager +{ +public: + static DeviceManager& instance(); -//! return all devices compatible with current gpu module build which support specified feature. -std::vector devices(cv::gpu::FeatureSet feature); + void load(int i); + void loadAll(); -#define ALL_DEVICES testing::ValuesIn(devices()) -#define DEVICES(feature) testing::ValuesIn(devices(feature)) + const std::vector& values() const { return devices_; } + +private: + std::vector devices_; +}; + +testing::internal::ParamGenerator DevicesGenerator_(); + +#define ALL_DEVICES DevicesGenerator_() ////////////////////////////////////////////////////////////////////// // Additional assertion From 6e4eb722a6e426960f2e515cf35b28482fc4a8bc Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 15:14:14 +0400 Subject: [PATCH 02/40] updated gpu performance tests now it executes only on one device added posibility to specify device on which tests will be executed --- modules/gpu/perf/perf_calib3d.cpp | 268 ++-- modules/gpu/perf/perf_core.cpp | 1830 ++++++++++---------------- modules/gpu/perf/perf_features2d.cpp | 234 ++-- modules/gpu/perf/perf_filters.cpp | 281 ++-- modules/gpu/perf/perf_imgproc.cpp | 1384 +++++++++---------- modules/gpu/perf/perf_labeling.cpp | 18 +- modules/gpu/perf/perf_main.cpp | 87 ++ modules/gpu/perf/perf_matop.cpp | 134 +- modules/gpu/perf/perf_objdetect.cpp | 83 +- modules/gpu/perf/perf_precomp.hpp | 8 + modules/gpu/perf/perf_utility.cpp | 41 +- modules/gpu/perf/perf_utility.hpp | 74 +- modules/gpu/perf/perf_video.cpp | 490 +++---- 13 files changed, 2079 insertions(+), 2853 deletions(-) diff --git a/modules/gpu/perf/perf_calib3d.cpp b/modules/gpu/perf/perf_calib3d.cpp index 7a9c6c395..343a4e9fa 100644 --- a/modules/gpu/perf/perf_calib3d.cpp +++ b/modules/gpu/perf/perf_calib3d.cpp @@ -1,207 +1,180 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////////////////////// // StereoBM -GPU_PERF_TEST_1(StereoBM, cv::gpu::DeviceInfo) +typedef pair pair_string; +DEF_PARAM_TEST_1(ImagePair, pair_string); + +PERF_TEST_P(ImagePair, Calib3D_StereoBM, Values(make_pair("gpu/perf/aloe.jpg", "gpu/perf/aloeR.jpg"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat img_l_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_l_host.empty()); - - cv::Mat img_r_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_r_host.empty()); - - cv::gpu::StereoBM_GPU bm(0, 256); - cv::gpu::GpuMat img_l(img_l_host); - cv::gpu::GpuMat img_r(img_r_host); - cv::gpu::GpuMat dst; - - bm(img_l, img_r, dst); - declare.time(5.0); + cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(imgLeft.empty()); + + cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(imgRight.empty()); + + cv::gpu::StereoBM_GPU d_bm(0, 256); + cv::gpu::GpuMat d_imgLeft(imgLeft); + cv::gpu::GpuMat d_imgRight(imgRight); + cv::gpu::GpuMat d_dst; + + d_bm(d_imgLeft, d_imgRight, d_dst); + TEST_CYCLE() { - bm(img_l, img_r, dst); + d_bm(d_imgLeft, d_imgRight, d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, StereoBM, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // StereoBeliefPropagation -GPU_PERF_TEST_1(StereoBeliefPropagation, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, Values(make_pair("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat img_l_host = readImage("gpu/stereobp/aloe-L.png"); - ASSERT_FALSE(img_l_host.empty()); - - cv::Mat img_r_host = readImage("gpu/stereobp/aloe-R.png"); - ASSERT_FALSE(img_r_host.empty()); - - cv::gpu::StereoBeliefPropagation bp(64); - cv::gpu::GpuMat img_l(img_l_host); - cv::gpu::GpuMat img_r(img_r_host); - cv::gpu::GpuMat dst; - - bp(img_l, img_r, dst); - declare.time(10.0); + cv::Mat imgLeft = readImage(GetParam().first); + ASSERT_FALSE(imgLeft.empty()); + + cv::Mat imgRight = readImage(GetParam().second); + ASSERT_FALSE(imgRight.empty()); + + cv::gpu::StereoBeliefPropagation d_bp(64); + cv::gpu::GpuMat d_imgLeft(imgLeft); + cv::gpu::GpuMat d_imgRight(imgRight); + cv::gpu::GpuMat d_dst; + + d_bp(d_imgLeft, d_imgRight, d_dst); + TEST_CYCLE() { - bp(img_l, img_r, dst); + d_bp(d_imgLeft, d_imgRight, d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // StereoConstantSpaceBP -GPU_PERF_TEST_1(StereoConstantSpaceBP, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Calib3D_StereoConstantSpaceBP, Values(make_pair("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-R.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat img_l_host = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_l_host.empty()); - - cv::Mat img_r_host = readImage("gpu/stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_r_host.empty()); - - cv::gpu::StereoConstantSpaceBP csbp(128); - cv::gpu::GpuMat img_l(img_l_host); - cv::gpu::GpuMat img_r(img_r_host); - cv::gpu::GpuMat dst; - - csbp(img_l, img_r, dst); - declare.time(10.0); + cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(imgLeft.empty()); + + cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(imgRight.empty()); + + cv::gpu::StereoConstantSpaceBP d_csbp(128); + cv::gpu::GpuMat d_imgLeft(imgLeft); + cv::gpu::GpuMat d_imgRight(imgRight); + cv::gpu::GpuMat d_dst; + + d_csbp(d_imgLeft, d_imgRight, d_dst); + TEST_CYCLE() { - csbp(img_l, img_r, dst); + d_csbp(d_imgLeft, d_imgRight, d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, StereoConstantSpaceBP, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // DisparityBilateralFilter -GPU_PERF_TEST_1(DisparityBilateralFilter, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Calib3D_DisparityBilateralFilter, Values(make_pair("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); + cv::Mat disp = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(disp.empty()); - cv::Mat disp_host = readImage("gpu/stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(disp_host.empty()); + cv::gpu::DisparityBilateralFilter d_filter(128); + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_disp(disp); + cv::gpu::GpuMat d_dst; - cv::gpu::DisparityBilateralFilter f(128); - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat disp(disp_host); - cv::gpu::GpuMat dst; - - f(disp, img, dst); + d_filter(d_disp, d_img, d_dst); TEST_CYCLE() { - f(disp, img, dst); + d_filter(d_disp, d_img, d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, DisparityBilateralFilter, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // TransformPoints -IMPLEMENT_PARAM_CLASS(Count, int) +DEF_PARAM_TEST_1(Count, int); -GPU_PERF_TEST(TransformPoints, cv::gpu::DeviceInfo, Count) +PERF_TEST_P(Count, Calib3D_TransformPoints, Values(5000, 10000, 20000)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + int count = GetParam(); - int count = GET_PARAM(1); + cv::Mat src(1, count, CV_32FC3); + fillRandom(src, -100, 100); - cv::Mat src_host(1, count, CV_32FC3); - fill(src_host, -100, 100); - - cv::gpu::GpuMat src(src_host); cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::gpu::GpuMat dst; - cv::gpu::transformPoints(src, rvec, tvec, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); TEST_CYCLE() { - cv::gpu::transformPoints(src, rvec, tvec, dst); + cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, TransformPoints, testing::Combine( - ALL_DEVICES, - testing::Values(5000, 10000, 20000))); - ////////////////////////////////////////////////////////////////////// // ProjectPoints -GPU_PERF_TEST(ProjectPoints, cv::gpu::DeviceInfo, Count) +PERF_TEST_P(Count, Calib3D_ProjectPoints, Values(5000, 10000, 20000)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + int count = GetParam(); - int count = GET_PARAM(1); + cv::Mat src(1, count, CV_32FC3); + fillRandom(src, -100, 100); - cv::Mat src_host(1, count, CV_32FC3); - fill(src_host, -100, 100); - - cv::gpu::GpuMat src(src_host); cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat dst; - cv::gpu::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(), dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); TEST_CYCLE() { - cv::gpu::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(), dst); + cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); } } -INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, testing::Combine( - ALL_DEVICES, - testing::Values(5000, 10000, 20000))); - ////////////////////////////////////////////////////////////////////// // SolvePnPRansac -GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count) +PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(3.0); - int count = GET_PARAM(1); + int count = GetParam(); cv::Mat object(1, count, CV_32FC3); - fill(object, -100, 100); + fillRandom(object, -100, 100); cv::Mat camera_mat(3, 3, CV_32FC1); - fill(camera_mat, 0.5, 1); + fillRandom(camera_mat, 0.5, 1); camera_mat.at(0, 1) = 0.f; camera_mat.at(1, 0) = 0.f; camera_mat.at(2, 0) = 0.f; @@ -211,9 +184,9 @@ GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count) std::vector image_vec; cv::Mat rvec_gold(1, 3, CV_32FC1); - fill(rvec_gold, 0, 1); + fillRandom(rvec_gold, 0, 1); cv::Mat tvec_gold(1, 3, CV_32FC1); - fill(tvec_gold, 0, 1); + fillRandom(tvec_gold, 0, 1); cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec); cv::Mat image(1, count, CV_32FC2, &image_vec[0]); @@ -223,80 +196,57 @@ GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count) cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); - declare.time(3.0); - TEST_CYCLE() { cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); } } -INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, testing::Combine( - ALL_DEVICES, - testing::Values(5000, 10000, 20000))); - ////////////////////////////////////////////////////////////////////// // ReprojectImageTo3D -GPU_PERF_TEST(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src_host(size, depth); - fill(src_host, 5.0, 30.0); + cv::Mat src(size, depth); + fillRandom(src, 5.0, 30.0); cv::Mat Q(4, 4, CV_32FC1); - fill(Q, 0.1, 1.0); + fillRandom(Q, 0.1, 1.0); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::reprojectImageTo3D(src, dst, Q); + cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); TEST_CYCLE() { - cv::gpu::reprojectImageTo3D(src, dst, Q); + cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); } } -INSTANTIATE_TEST_CASE_P(Calib3D, ReprojectImageTo3D, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S))); - ////////////////////////////////////////////////////////////////////// // DrawColorDisp -GPU_PERF_TEST(DrawColorDisp, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Calib3D_DrawColorDisp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Mat src(size, type); + fillRandom(src, 0, 255); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::drawColorDisp(src, dst, 255); + cv::gpu::drawColorDisp(d_src, d_dst, 255); TEST_CYCLE() { - cv::gpu::drawColorDisp(src, dst, 255); + cv::gpu::drawColorDisp(d_src, d_dst, 255); } } -INSTANTIATE_TEST_CASE_P(Calib3D, DrawColorDisp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16S)))); - -#endif - +} // namespace diff --git a/modules/gpu/perf/perf_core.cpp b/modules/gpu/perf/perf_core.cpp index f41343204..b56713a70 100644 --- a/modules/gpu/perf/perf_core.cpp +++ b/modules/gpu/perf/perf_core.cpp @@ -1,1883 +1,1513 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { + +#define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F) ////////////////////////////////////////////////////////////////////// // Merge -GPU_PERF_TEST(Merge, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_Merge, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, Values(2, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - std::vector src(channels); + std::vector d_src(channels); for (int i = 0; i < channels; ++i) - src[i] = cv::gpu::GpuMat(size, depth, cv::Scalar::all(i)); + d_src[i] = cv::gpu::GpuMat(size, depth, cv::Scalar::all(i)); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_dst; - cv::gpu::merge(src, dst); + cv::gpu::merge(d_src, d_dst); TEST_CYCLE() { - cv::gpu::merge(src, dst); + cv::gpu::merge(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Merge, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(2, 3, 4))); - ////////////////////////////////////////////////////////////////////// // Split -GPU_PERF_TEST(Split, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_Split, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, Values(2, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::gpu::GpuMat d_src(size, CV_MAKE_TYPE(depth, channels), cv::Scalar(1, 2, 3, 4)); - cv::gpu::GpuMat src(size, CV_MAKE_TYPE(depth, channels), cv::Scalar(1, 2, 3, 4)); + std::vector d_dst; - std::vector dst; - - cv::gpu::split(src, dst); + cv::gpu::split(d_src, d_dst); TEST_CYCLE() { - cv::gpu::split(src, dst); + cv::gpu::split(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Split, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(2, 3, 4))); - ////////////////////////////////////////////////////////////////////// -// Add_Mat +// AddMat -GPU_PERF_TEST(Add_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_AddMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0.0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::add(src1, src2, dst); + cv::gpu::add(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::add(src1, src2, dst); + cv::gpu::add(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Add_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Add_Scalar +// AddScalar -GPU_PERF_TEST(Add_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_AddScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat dst; - cv::gpu::add(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::add(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::add(src, s, dst); + cv::gpu::add(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Add_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Subtract_Mat +// SubtractMat -GPU_PERF_TEST(Subtract_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_SubtractMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0.0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::subtract(src1, src2, dst); + cv::gpu::subtract(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::subtract(src1, src2, dst); + cv::gpu::subtract(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Subtract_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Subtract_Scalar +// SubtractScalar -GPU_PERF_TEST(Subtract_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_SubtractScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat dst; - cv::gpu::subtract(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::subtract(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::subtract(src, s, dst); + cv::gpu::subtract(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Subtract_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Multiply_Mat +// MultiplyMat -GPU_PERF_TEST(Multiply_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MultiplyMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0.0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::multiply(src1, src2, dst); + cv::gpu::multiply(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::multiply(src1, src2, dst); + cv::gpu::multiply(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Multiply_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Multiply_Scalar +// MultiplyScalar -GPU_PERF_TEST(Multiply_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MultiplyScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat dst; - cv::gpu::multiply(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::multiply(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::multiply(src, s, dst); + cv::gpu::multiply(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Multiply_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Divide_Mat +// DivideMat -GPU_PERF_TEST(Divide_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_DivideMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0.0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::divide(src1, src2, dst); + cv::gpu::divide(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::divide(src1, src2, dst); + cv::gpu::divide(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Divide_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Divide_Scalar +// DivideScalar -GPU_PERF_TEST(Divide_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_DivideScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat dst; - cv::gpu::divide(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::divide(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::divide(src, s, dst); + cv::gpu::divide(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Divide_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// Divide_Scalar_Inv +// DivideScalarInv -GPU_PERF_TEST(Divide_Scalar_Inv, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_DivideScalarInv, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); + double s = 100.0; - cv::gpu::GpuMat src(src_host); - double scale = 100.0; - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::divide(scale, src, dst); + cv::gpu::divide(s, d_src, d_dst); TEST_CYCLE() { - cv::gpu::divide(scale, src, dst); + cv::gpu::divide(s, d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Divide_Scalar_Inv, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// AbsDiff_Mat +// AbsDiffMat -GPU_PERF_TEST(AbsDiff_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_AbsDiffMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0.0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::absdiff(src1, src2, dst); + cv::gpu::absdiff(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::absdiff(src1, src2, dst); + cv::gpu::absdiff(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, AbsDiff_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// -// AbsDiff_Scalar +// AbsDiffScalar -GPU_PERF_TEST(AbsDiff_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_AbsDiffScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat dst; - cv::gpu::absdiff(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::absdiff(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::absdiff(src, s, dst); + cv::gpu::absdiff(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, AbsDiff_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// // Abs -GPU_PERF_TEST(Abs, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_Abs, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_16S, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::abs(src, dst); + cv::gpu::abs(d_src, d_dst); TEST_CYCLE() { - cv::gpu::abs(src, dst); + cv::gpu::abs(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Abs, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// // Sqr -GPU_PERF_TEST(Sqr, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_Sqr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::sqr(src, dst); + cv::gpu::sqr(d_src, d_dst); TEST_CYCLE() { - cv::gpu::sqr(src, dst); + cv::gpu::sqr(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Sqr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// // Sqrt -GPU_PERF_TEST(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_Sqrt, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::sqrt(src, dst); + cv::gpu::sqrt(d_src, d_dst); TEST_CYCLE() { - cv::gpu::sqrt(src, dst); + cv::gpu::sqrt(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Sqrt, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// // Log -GPU_PERF_TEST(Log, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_Log, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src, 1.0, 255.0); - cv::Mat src_host(size, depth); - fill(src_host, 1.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::log(src, dst); + cv::gpu::log(d_src, d_dst); TEST_CYCLE() { - cv::gpu::log(src, dst); + cv::gpu::log(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Log, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// // Exp -GPU_PERF_TEST(Exp, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_Exp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src, 1.0, 10.0); - cv::Mat src_host(size, depth); - fill(src_host, 1.0, 10.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::exp(src, dst); + cv::gpu::exp(d_src, d_dst); TEST_CYCLE() { - cv::gpu::exp(src, dst); + cv::gpu::exp(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Exp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// // Pow -GPU_PERF_TEST(Pow, cv::gpu::DeviceInfo, cv::Size, MatDepth) +DEF_PARAM_TEST(Sz_Depth_Power, cv::Size, MatDepth, double); + +PERF_TEST_P(Sz_Depth_Power, Core_Pow, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F), Values(0.3, 2.0, 2.4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + double power = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src, 1.0, 10.0); - cv::Mat src_host(size, depth); - fill(src_host, 1.0, 10.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::pow(src, 2.3, dst); + cv::gpu::pow(d_src, power, d_dst); TEST_CYCLE() { - cv::gpu::pow(src, 2.3, dst); + cv::gpu::pow(d_src, power, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Pow, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - ////////////////////////////////////////////////////////////////////// -// Compare_Mat +// CompareMat CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE) -#define ALL_CMP_CODES testing::Values(CmpCode(cv::CMP_EQ), CmpCode(cv::CMP_NE), CmpCode(cv::CMP_GT), CmpCode(cv::CMP_GE), CmpCode(cv::CMP_LT), CmpCode(cv::CMP_LE)) +#define ALL_CMP_CODES ValuesIn(CmpCode::all()) -GPU_PERF_TEST(Compare_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode) +DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CmpCode); + +PERF_TEST_P(Sz_Depth_Code, Core_CompareMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, ALL_CMP_CODES)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int cmp_code = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int cmp_code = GET_PARAM(3); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::compare(src1, src2, dst, cmp_code); + cv::gpu::compare(d_src1, d_src2, d_dst, cmp_code); TEST_CYCLE() { - cv::gpu::compare(src1, src2, dst, cmp_code); + cv::gpu::compare(d_src1, d_src2, d_dst, cmp_code); } } -INSTANTIATE_TEST_CASE_P(Core, Compare_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - ALL_CMP_CODES)); - ////////////////////////////////////////////////////////////////////// -// Compare_Scalar +// CompareScalar -GPU_PERF_TEST(Compare_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode) +PERF_TEST_P(Sz_Depth_Code, Core_CompareScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, ALL_CMP_CODES)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int cmp_code = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int cmp_code = GET_PARAM(3); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 100.0); + cv::Scalar s = cv::Scalar::all(100); - cv::gpu::GpuMat src(src_host); - cv::Scalar s = cv::Scalar::all(50); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::compare(src, s, dst, cmp_code); + cv::gpu::compare(d_src, s, d_dst, cmp_code); TEST_CYCLE() { - cv::gpu::compare(src, s, dst, cmp_code); + cv::gpu::compare(d_src, s, d_dst, cmp_code); } } -INSTANTIATE_TEST_CASE_P(Core, Compare_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - ALL_CMP_CODES)); - ////////////////////////////////////////////////////////////////////// -// Bitwise_Not +// BitwiseNot -GPU_PERF_TEST(Bitwise_Not, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_BitwiseNot, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::bitwise_not(src, dst); + cv::gpu::bitwise_not(d_src, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_not(src, dst); + cv::gpu::bitwise_not(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Not, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_And_Mat +// BitwiseAndMat -GPU_PERF_TEST(Bitwise_And_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_BitwiseAndMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::bitwise_and(src1, src2, dst); + cv::gpu::bitwise_and(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_and(src1, src2, dst); + cv::gpu::bitwise_and(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_And_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_And_Scalar +// BitwiseAndScalar -GPU_PERF_TEST(Bitwise_And_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseAndScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 100.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::gpu::GpuMat dst; + cv::Scalar s = cv::Scalar::all(100); - cv::gpu::bitwise_and(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::bitwise_and(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_and(src, s, dst); + cv::gpu::bitwise_and(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_And_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_Or_Mat +// BitwiseOrMat -GPU_PERF_TEST(Bitwise_Or_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_BitwiseOrMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::bitwise_or(src1, src2, dst); + cv::gpu::bitwise_or(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_or(src1, src2, dst); + cv::gpu::bitwise_or(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Or_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_Or_Scalar +// BitwiseOrScalar -GPU_PERF_TEST(Bitwise_Or_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseOrScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 100.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::gpu::GpuMat dst; + cv::Scalar s = cv::Scalar::all(100); - cv::gpu::bitwise_or(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::bitwise_or(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_or(src, s, dst); + cv::gpu::bitwise_or(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Or_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_Xor_Mat +// BitwiseXorMat -GPU_PERF_TEST(Bitwise_Xor_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_BitwiseXorMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 100.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::bitwise_xor(src1, src2, dst); + cv::gpu::bitwise_xor(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_xor(src1, src2, dst); + cv::gpu::bitwise_xor(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Xor_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - ////////////////////////////////////////////////////////////////////// -// Bitwise_Xor_Scalar +// BitwiseXorScalar -GPU_PERF_TEST(Bitwise_Xor_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseXorScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 100.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::gpu::GpuMat dst; + cv::Scalar s = cv::Scalar::all(100); - cv::gpu::bitwise_xor(src, s, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::bitwise_xor(d_src, s, d_dst); TEST_CYCLE() { - cv::gpu::bitwise_xor(src, s, dst); + cv::gpu::bitwise_xor(d_src, s, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Xor_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - ////////////////////////////////////////////////////////////////////// // RShift -GPU_PERF_TEST(RShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_RShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); cv::Scalar_ val = cv::Scalar_::all(4); - cv::gpu::GpuMat dst; - cv::gpu::rshift(src, val, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::rshift(d_src, val, d_dst); TEST_CYCLE() { - cv::gpu::rshift(src, val, dst); + cv::gpu::rshift(d_src, val, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, RShift, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - ////////////////////////////////////////////////////////////////////// // LShift -GPU_PERF_TEST(LShift, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) +PERF_TEST_P(Sz_Depth_Cn, Core_LShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); cv::Scalar_ val = cv::Scalar_::all(4); - cv::gpu::GpuMat dst; - cv::gpu::lshift(src, val, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::lshift(d_src, val, d_dst); TEST_CYCLE() { - cv::gpu::lshift(src, val, dst); + cv::gpu::lshift(d_src, val, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, LShift, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - ////////////////////////////////////////////////////////////////////// -// Min_Mat +// MinMat -GPU_PERF_TEST(Min_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MinMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 255.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 255.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::min(src1, src2, dst); + cv::gpu::min(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::min(src1, src2, dst); + cv::gpu::min(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Min_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - ////////////////////////////////////////////////////////////////////// -// Min_Scalar +// MinScalar -GPU_PERF_TEST(Min_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MinScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 255.0); - - cv::gpu::GpuMat src(src_host); double val = 50.0; - cv::gpu::GpuMat dst; - cv::gpu::min(src, val, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::min(d_src, val, d_dst); TEST_CYCLE() { - cv::gpu::min(src, val, dst); + cv::gpu::min(d_src, val, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Min_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - ////////////////////////////////////////////////////////////////////// -// Max_Mat +// MaxMat -GPU_PERF_TEST(Max_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MaxMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src1(size, depth); + fillRandom(src1); - cv::Mat src1_host(size, depth); - fill(src1_host, 0, 255.0); + cv::Mat src2(size, depth); + fillRandom(src2); - cv::Mat src2_host(size, depth); - fill(src2_host, 0, 255.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::max(src1, src2, dst); + cv::gpu::max(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::max(src1, src2, dst); + cv::gpu::max(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Max_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - ////////////////////////////////////////////////////////////////////// -// Max_Scalar +// MaxScalar -GPU_PERF_TEST(Max_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MaxScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 255.0); - - cv::gpu::GpuMat src(src_host); double val = 50.0; - cv::gpu::GpuMat dst; - cv::gpu::max(src, val, dst); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::max(d_src, val, d_dst); TEST_CYCLE() { - cv::gpu::max(src, val, dst); + cv::gpu::max(d_src, val, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Max_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - ////////////////////////////////////////////////////////////////////// // AddWeighted -GPU_PERF_TEST(AddWeighted, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth, MatDepth) +DEF_PARAM_TEST(Sz_3Depth, cv::Size, MatDepth, MatDepth, MatDepth); + +PERF_TEST_P(Sz_3Depth, Core_AddWeighted, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F, CV_64F), + Values(CV_8U, CV_16U, CV_32F, CV_64F), + Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth1 = GET_PARAM(1); + int depth2 = GET_PARAM(2); + int dst_depth = GET_PARAM(3); - cv::Size size = GET_PARAM(1); - int depth1 = GET_PARAM(2); - int depth2 = GET_PARAM(3); - int dst_depth = GET_PARAM(4); + cv::Mat src1(size, depth1); + fillRandom(src1); - cv::Mat src1_host(size, depth1); - fill(src1_host, 0, 100.0); + cv::Mat src2(size, depth2); + fillRandom(src2); - cv::Mat src2_host(size, depth2); - fill(src2_host, 0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); + cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, d_dst, dst_depth); TEST_CYCLE() { - cv::gpu::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); + cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, d_dst, dst_depth); } } -INSTANTIATE_TEST_CASE_P(Core, AddWeighted, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// // GEMM -#ifdef HAVE_CUBLAS CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T) -#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T)) +#define ALL_GEMM_FLAGS Values(0, CV_GEMM_A_T, CV_GEMM_B_T, CV_GEMM_C_T, CV_GEMM_A_T | CV_GEMM_B_T, CV_GEMM_A_T | CV_GEMM_C_T, CV_GEMM_A_T | CV_GEMM_B_T | CV_GEMM_C_T) -GPU_PERF_TEST(GEMM, cv::gpu::DeviceInfo, cv::Size, MatType, GemmFlags) +DEF_PARAM_TEST(Sz_Type_Flags, cv::Size, MatType, GemmFlags); + +PERF_TEST_P(Sz_Type_Flags, Core_GEMM, Combine( + Values(cv::Size(512, 512), cv::Size(1024, 1024)), + Values(CV_32FC1, CV_32FC2, CV_64FC1, CV_64FC2), + ALL_GEMM_FLAGS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int flags = GET_PARAM(3); - - cv::Mat src1_host(size, type); - fill(src1_host, 0.0, 10.0); - - cv::Mat src2_host(size, type); - fill(src2_host, 0.0, 10.0); - - cv::Mat src3_host(size, type); - fill(src3_host, 0.0, 10.0); - - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat src3(src3_host); - cv::gpu::GpuMat dst; - - cv::gpu::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); - declare.time(5.0); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int flags = GET_PARAM(2); + + cv::Mat src1(size, type); + fillRandom(src1); + + cv::Mat src2(size, type); + fillRandom(src2); + + cv::Mat src3(size, type); + fillRandom(src3); + + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_src3(src3); + cv::gpu::GpuMat d_dst; + + cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst, flags); + TEST_CYCLE() { - cv::gpu::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); + cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst, flags); } } -INSTANTIATE_TEST_CASE_P(Core, GEMM, testing::Combine( - ALL_DEVICES, - testing::Values(cv::Size(512, 512), cv::Size(1024, 1024)), - testing::Values(CV_32FC1, CV_32FC2, CV_64FC1, CV_64FC2), - ALL_GEMM_FLAGS)); - -#endif ////////////////////////////////////////////////////////////////////// // Transpose -GPU_PERF_TEST(Transpose, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Type, Core_Transpose, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::transpose(src, dst); + cv::gpu::transpose(d_src, d_dst); TEST_CYCLE() { - cv::gpu::transpose(src, dst); + cv::gpu::transpose(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Transpose, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1))); - ////////////////////////////////////////////////////////////////////// // Flip enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1}; CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y) -#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y)) +#define ALL_FLIP_CODES ValuesIn(FlipCode::all()) -GPU_PERF_TEST(Flip, cv::gpu::DeviceInfo, cv::Size, MatType, FlipCode) +DEF_PARAM_TEST(Sz_Depth_Cn_Code, cv::Size, MatDepth, int, FlipCode); + +PERF_TEST_P(Sz_Depth_Cn_Code, Core_Flip, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + ALL_FLIP_CODES)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int flipCode = GET_PARAM(3); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 100.0); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::flip(src, dst, flipCode); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::flip(d_src, d_dst, flipCode); TEST_CYCLE() { - cv::gpu::flip(src, dst, flipCode); + cv::gpu::flip(d_src, d_dst, flipCode); } } -INSTANTIATE_TEST_CASE_P(Core, Flip, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4), - ALL_FLIP_CODES)); - ////////////////////////////////////////////////////////////////////// -// LUT_OneChannel +// LutOneChannel -GPU_PERF_TEST(LUT_OneChannel, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Type, Core_LutOneChannel, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8UC1, CV_8UC3))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src_host(size, type); - fill(src_host, 0.0, 100.0); + cv::Mat src(size, type); + fillRandom(src); cv::Mat lut(1, 256, CV_8UC1); - fill(lut, 0.0, 100.0); + fillRandom(lut); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::LUT(src, lut, dst); + cv::gpu::LUT(d_src, lut, d_dst); TEST_CYCLE() { - cv::gpu::LUT(src, lut, dst); + cv::gpu::LUT(d_src, lut, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, LUT_OneChannel, testing::Combine( - ALL_DEVICES, +////////////////////////////////////////////////////////////////////// +// LutMultiChannel + +PERF_TEST_P(Sz_Type, Core_LutMultiChannel, Combine( GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3))); - -////////////////////////////////////////////////////////////////////// -// LUT_MultiChannel - -GPU_PERF_TEST(LUT_MultiChannel, cv::gpu::DeviceInfo, cv::Size, MatType) + Values(CV_8UC3))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 100.0); + cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels())); + fillRandom(lut); - cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src_host.channels())); - fill(lut, 0.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::LUT(src, lut, dst); + cv::gpu::LUT(d_src, lut, d_dst); TEST_CYCLE() { - cv::gpu::LUT(src, lut, dst); + cv::gpu::LUT(d_src, lut, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, LUT_MultiChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC3))); - ////////////////////////////////////////////////////////////////////// -// Magnitude_Complex +// MagnitudeComplex -GPU_PERF_TEST(Magnitude_Complex, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, Core_MagnitudeComplex, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_32FC2); + fillRandom(src, -100.0, 100.0); - cv::Mat src_host(size, CV_32FC2); - fill(src_host, -100.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::magnitude(src, dst); + cv::gpu::magnitude(d_src, d_dst); TEST_CYCLE() { - cv::gpu::magnitude(src, dst); + cv::gpu::magnitude(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Magnitude_Complex, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// -// Magnitude_Sqr_Complex +// MagnitudeSqrComplex -GPU_PERF_TEST(Magnitude_Sqr_Complex, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, Core_MagnitudeSqrComplex, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_32FC2); + fillRandom(src, -100.0, 100.0); - cv::Mat src_host(size, CV_32FC2); - fill(src_host, -100.0, 100.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::magnitudeSqr(src, dst); + cv::gpu::magnitudeSqr(d_src, d_dst); TEST_CYCLE() { - cv::gpu::magnitudeSqr(src, dst); + cv::gpu::magnitudeSqr(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Magnitude_Sqr_Complex, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Magnitude -GPU_PERF_TEST(Magnitude, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, Core_Magnitude, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src1(size, CV_32FC1); + fillRandom(src1, -100.0, 100.0); - cv::Mat src1_host(size, CV_32FC1); - fill(src1_host, -100.0, 100.0); + cv::Mat src2(size, CV_32FC1); + fillRandom(src2, -100.0, 100.0); - cv::Mat src2_host(size, CV_32FC1); - fill(src2_host, -100.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::magnitude(src1, src2, dst); + cv::gpu::magnitude(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::magnitude(src1, src2, dst); + cv::gpu::magnitude(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Magnitude, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// -// Magnitude_Sqr +// MagnitudeSqr -GPU_PERF_TEST(Magnitude_Sqr, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, Core_MagnitudeSqr, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src1(size, CV_32FC1); + fillRandom(src1, -100.0, 100.0); - cv::Mat src1_host(size, CV_32FC1); - fill(src1_host, -100.0, 100.0); + cv::Mat src2(size, CV_32FC1); + fillRandom(src2, -100.0, 100.0); - cv::Mat src2_host(size, CV_32FC1); - fill(src2_host, -100.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::magnitudeSqr(src1, src2, dst); + cv::gpu::magnitudeSqr(d_src1, d_src2, d_dst); TEST_CYCLE() { - cv::gpu::magnitudeSqr(src1, src2, dst); + cv::gpu::magnitudeSqr(d_src1, d_src2, d_dst); } } -INSTANTIATE_TEST_CASE_P(Core, Magnitude_Sqr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Phase -IMPLEMENT_PARAM_CLASS(AngleInDegrees, bool) +DEF_PARAM_TEST(Sz_AngleInDegrees, cv::Size, bool); -GPU_PERF_TEST(Phase, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) +PERF_TEST_P(Sz_AngleInDegrees, Core_Phase, Combine(GPU_TYPICAL_MAT_SIZES, Bool())) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + bool angleInDegrees = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); + cv::Mat src1(size, CV_32FC1); + fillRandom(src1, -100.0, 100.0); - cv::Mat src1_host(size, CV_32FC1); - fill(src1_host, -100.0, 100.0); + cv::Mat src2(size, CV_32FC1); + fillRandom(src2, -100.0, 100.0); - cv::Mat src2_host(size, CV_32FC1); - fill(src2_host, -100.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; - - cv::gpu::phase(src1, src2, dst, angleInDegrees); + cv::gpu::phase(d_src1, d_src2, d_dst, angleInDegrees); TEST_CYCLE() { - cv::gpu::phase(src1, src2, dst, angleInDegrees); + cv::gpu::phase(d_src1, d_src2, d_dst, angleInDegrees); } } -INSTANTIATE_TEST_CASE_P(Core, Phase, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - ////////////////////////////////////////////////////////////////////// // CartToPolar -GPU_PERF_TEST(CartToPolar, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) +PERF_TEST_P(Sz_AngleInDegrees, Core_CartToPolar, Combine(GPU_TYPICAL_MAT_SIZES, Bool())) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + bool angleInDegrees = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); + cv::Mat src1(size, CV_32FC1); + fillRandom(src1, -100.0, 100.0); - cv::Mat src1_host(size, CV_32FC1); - fill(src1_host, -100.0, 100.0); + cv::Mat src2(size, CV_32FC1); + fillRandom(src2, -100.0, 100.0); - cv::Mat src2_host(size, CV_32FC1); - fill(src2_host, -100.0, 100.0); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_magnitude; + cv::gpu::GpuMat d_angle; - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat magnitude; - cv::gpu::GpuMat angle; - - cv::gpu::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); + cv::gpu::cartToPolar(d_src1, d_src2, d_magnitude, d_angle, angleInDegrees); TEST_CYCLE() { - cv::gpu::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); + cv::gpu::cartToPolar(d_src1, d_src2, d_magnitude, d_angle, angleInDegrees); } } -INSTANTIATE_TEST_CASE_P(Core, CartToPolar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - ////////////////////////////////////////////////////////////////////// // PolarToCart -GPU_PERF_TEST(PolarToCart, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) +PERF_TEST_P(Sz_AngleInDegrees, Core_PolarToCart, Combine(GPU_TYPICAL_MAT_SIZES, Bool())) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + bool angleInDegrees = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); + cv::Mat magnitude(size, CV_32FC1); + fillRandom(magnitude, 0.0, 100.0); - cv::Mat magnitude_host(size, CV_32FC1); - fill(magnitude_host, 0.0, 100.0); + cv::Mat angle(size, CV_32FC1); + fillRandom(angle, 0.0, angleInDegrees ? 360.0 : 2 * CV_PI); - cv::Mat angle_host(size, CV_32FC1); - fill(angle_host, 0.0, angleInDegrees ? 360.0 : 2 * CV_PI); + cv::gpu::GpuMat d_magnitude(magnitude); + cv::gpu::GpuMat d_angle(angle); + cv::gpu::GpuMat d_x; + cv::gpu::GpuMat d_y; - cv::gpu::GpuMat magnitude(magnitude_host); - cv::gpu::GpuMat angle(angle_host); - cv::gpu::GpuMat x; - cv::gpu::GpuMat y; - - cv::gpu::polarToCart(magnitude, angle, x, y, angleInDegrees); + cv::gpu::polarToCart(d_magnitude, d_angle, d_x, d_y, angleInDegrees); TEST_CYCLE() { - cv::gpu::polarToCart(magnitude, angle, x, y, angleInDegrees); + cv::gpu::polarToCart(d_magnitude, d_angle, d_x, d_y, angleInDegrees); } } -INSTANTIATE_TEST_CASE_P(Core, PolarToCart, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - ////////////////////////////////////////////////////////////////////// // MeanStdDev -GPU_PERF_TEST(MeanStdDev, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, Core_MeanStdDev, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_8UC1); + fillRandom(src); - cv::Mat src_host(size, CV_8UC1); - fill(src_host, 0.0, 255.0); - - cv::gpu::GpuMat src(src_host); cv::Scalar mean; cv::Scalar stddev; - cv::gpu::GpuMat buf; - cv::gpu::meanStdDev(src, mean, stddev, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + cv::gpu::meanStdDev(d_src, mean, stddev, d_buf); TEST_CYCLE() { - cv::gpu::meanStdDev(src, mean, stddev, buf); + cv::gpu::meanStdDev(d_src, mean, stddev, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, MeanStdDev, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Norm -GPU_PERF_TEST(Norm, cv::gpu::DeviceInfo, cv::Size, MatDepth, NormType) +DEF_PARAM_TEST(Sz_Depth_Norm, cv::Size, MatDepth, NormType); + +PERF_TEST_P(Sz_Depth_Norm, Core_Norm, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32S, CV_32F), + Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int normType = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int normType = GET_PARAM(3); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 255.0); - - cv::gpu::GpuMat src(src_host); double dst; - cv::gpu::GpuMat buf; - dst = cv::gpu::norm(src, normType, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + dst = cv::gpu::norm(d_src, normType, d_buf); TEST_CYCLE() { - dst = cv::gpu::norm(src, normType, buf); + dst = cv::gpu::norm(d_src, normType, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, Norm, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S, CV_32F), - testing::Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))); - ////////////////////////////////////////////////////////////////////// // NormDiff -GPU_PERF_TEST(NormDiff, cv::gpu::DeviceInfo, cv::Size, NormType) +DEF_PARAM_TEST(Sz_Norm, cv::Size, NormType); + +PERF_TEST_P(Sz_Norm, Core_NormDiff, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int normType = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int normType = GET_PARAM(2); + cv::Mat src1(size, CV_8UC1); + fillRandom(src1); - cv::Mat src1_host(size, CV_8UC1); - fill(src1_host, 0.0, 255.0); + cv::Mat src2(size, CV_8UC1); + fillRandom(src2); - cv::Mat src2_host(size, CV_8UC1); - fill(src2_host, 0.0, 255.0); - - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); double dst; - dst = cv::gpu::norm(src1, src2, normType); + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + + dst = cv::gpu::norm(d_src1, d_src2, normType); TEST_CYCLE() { - dst = cv::gpu::norm(src1, src2, normType); + dst = cv::gpu::norm(d_src1, d_src2, normType); } } -INSTANTIATE_TEST_CASE_P(Core, NormDiff, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))); - ////////////////////////////////////////////////////////////////////// // Sum -GPU_PERF_TEST(Sum, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, Core_Sum, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); cv::Scalar dst; - cv::gpu::GpuMat buf; - dst = cv::gpu::sum(src, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + dst = cv::gpu::sum(d_src, d_buf); TEST_CYCLE() { - dst = cv::gpu::sum(src, buf); + dst = cv::gpu::sum(d_src, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, Sum, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4))); - ////////////////////////////////////////////////////////////////////// -// Sum_Abs +// SumAbs -GPU_PERF_TEST(Sum_Abs, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, Core_SumAbs, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); cv::Scalar dst; - cv::gpu::GpuMat buf; - dst = cv::gpu::absSum(src, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + dst = cv::gpu::absSum(d_src, d_buf); TEST_CYCLE() { - dst = cv::gpu::absSum(src, buf); + dst = cv::gpu::absSum(d_src, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, Sum_Abs, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4))); - ////////////////////////////////////////////////////////////////////// -// Sum_Sqr +// SumSqr -GPU_PERF_TEST(Sum_Sqr, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, Core_SumSqr, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); cv::Scalar dst; - cv::gpu::GpuMat buf; - dst = cv::gpu::sqrSum(src, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + dst = cv::gpu::sqrSum(d_src, d_buf); TEST_CYCLE() { - dst = cv::gpu::sqrSum(src, buf); + dst = cv::gpu::sqrSum(d_src, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, Sum_Sqr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4))); - ////////////////////////////////////////////////////////////////////// // MinMax -GPU_PERF_TEST(MinMax, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MinMax, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 255.0); - - cv::gpu::GpuMat src(src_host); double minVal, maxVal; - cv::gpu::GpuMat buf; - cv::gpu::minMax(src, &minVal, &maxVal, cv::gpu::GpuMat(), buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + cv::gpu::minMax(d_src, &minVal, &maxVal, cv::gpu::GpuMat(), d_buf); TEST_CYCLE() { - cv::gpu::minMax(src, &minVal, &maxVal, cv::gpu::GpuMat(), buf); + cv::gpu::minMax(d_src, &minVal, &maxVal, cv::gpu::GpuMat(), d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, MinMax, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// // MinMaxLoc -GPU_PERF_TEST(MinMaxLoc, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_MinMaxLoc, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 255.0); - - cv::gpu::GpuMat src(src_host); double minVal, maxVal; cv::Point minLoc, maxLoc; - cv::gpu::GpuMat valbuf, locbuf; - cv::gpu::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), valbuf, locbuf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_valbuf, d_locbuf; + + cv::gpu::minMaxLoc(d_src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); TEST_CYCLE() { - cv::gpu::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), valbuf, locbuf); + cv::gpu::minMaxLoc(d_src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); } } -INSTANTIATE_TEST_CASE_P(Core, MinMaxLoc, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// // CountNonZero -GPU_PERF_TEST(CountNonZero, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, Core_CountNonZero, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0.0, 1.5); - - cv::gpu::GpuMat src(src_host); int dst; - cv::gpu::GpuMat buf; - dst = cv::gpu::countNonZero(src, buf); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + + dst = cv::gpu::countNonZero(d_src, d_buf); TEST_CYCLE() { - dst = cv::gpu::countNonZero(src, buf); + dst = cv::gpu::countNonZero(d_src, d_buf); } } -INSTANTIATE_TEST_CASE_P(Core, CountNonZero, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - ////////////////////////////////////////////////////////////////////// // Reduce CV_ENUM(ReduceCode, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) -#define ALL_REDUCE_CODES testing::Values(CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) +#define ALL_REDUCE_CODES ValuesIn(ReduceCode::all()) enum {Rows = 0, Cols = 1}; CV_ENUM(ReduceDim, Rows, Cols) +#define ALL_REDUCE_DIMS ValuesIn(ReduceDim::all()) -GPU_PERF_TEST(Reduce, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, ReduceCode, ReduceDim) +DEF_PARAM_TEST(Sz_Depth_Cn_Code_Dim, cv::Size, MatDepth, int, ReduceCode, ReduceDim); + +PERF_TEST_P(Sz_Depth_Cn_Code_Dim, Core_Reduce, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_16S, CV_32F), + Values(1, 2, 3, 4), + ALL_REDUCE_CODES, + ALL_REDUCE_DIMS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - int reduceOp = GET_PARAM(4); - int dim = GET_PARAM(5); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); + int reduceOp = GET_PARAM(3); + int dim = GET_PARAM(4); int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 10.0); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::reduce(src, dst, dim, reduceOp); + cv::gpu::reduce(d_src, d_dst, dim, reduceOp); TEST_CYCLE() { - cv::gpu::reduce(src, dst, dim, reduceOp); + cv::gpu::reduce(d_src, d_dst, dim, reduceOp); } } -INSTANTIATE_TEST_CASE_P(Core, Reduce, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_16S, CV_32F), - testing::Values(1, 2, 3, 4), - ALL_REDUCE_CODES, - testing::Values(ReduceDim(Rows), ReduceDim(Cols)))); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_features2d.cpp b/modules/gpu/perf/perf_features2d.cpp index 8a8186017..ef9612b54 100644 --- a/modules/gpu/perf/perf_features2d.cpp +++ b/modules/gpu/perf/perf_features2d.cpp @@ -1,209 +1,179 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////////////////////// // SURF -GPU_PERF_TEST_1(SURF, cv::gpu::DeviceInfo) +DEF_PARAM_TEST_1(Image, string); + +PERF_TEST_P(Image, Features2D_SURF, Values("gpu/perf/aloe.jpg")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); - - cv::gpu::SURF_GPU surf; - - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat keypoints, descriptors; - - surf(img, cv::gpu::GpuMat(), keypoints, descriptors); - declare.time(2.0); + cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); + + cv::gpu::SURF_GPU d_surf; + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints, d_descriptors; + + d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); + TEST_CYCLE() { - surf(img, cv::gpu::GpuMat(), keypoints, descriptors); + d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); } } -INSTANTIATE_TEST_CASE_P(Features2D, SURF, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // FAST -GPU_PERF_TEST_1(FAST, cv::gpu::DeviceInfo) +PERF_TEST_P(Image, Features2D_FAST, Values("gpu/perf/aloe.jpg")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); + cv::gpu::FAST_GPU d_fast(20); - cv::gpu::FAST_GPU fast(20); + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints; - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat keypoints; - - fast(img, cv::gpu::GpuMat(), keypoints); + d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); TEST_CYCLE() { - fast(img, cv::gpu::GpuMat(), keypoints); + d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); } } -INSTANTIATE_TEST_CASE_P(Features2D, FAST, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // ORB -GPU_PERF_TEST_1(ORB, cv::gpu::DeviceInfo) +PERF_TEST_P(Image, Features2D_ORB, Values("gpu/perf/aloe.jpg")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); + cv::gpu::ORB_GPU d_orb(4000); - cv::gpu::ORB_GPU orb(4000); + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints, d_descriptors; - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat keypoints, descriptors; + d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); TEST_CYCLE() { - orb(img, cv::gpu::GpuMat(), keypoints, descriptors); + d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); } } -INSTANTIATE_TEST_CASE_P(Features2D, ORB, ALL_DEVICES); +////////////////////////////////////////////////////////////////////// +// BFMatch + +DEF_PARAM_TEST(DescSize_Norm, int, NormType); + +PERF_TEST_P(DescSize_Norm, Features2D_BFMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) +{ + declare.time(3.0); + + int desc_size = GET_PARAM(0); + int normType = GET_PARAM(1); + + int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; + + cv::Mat query(3000, desc_size, type); + fillRandom(query); + + cv::Mat train(3000, desc_size, type); + fillRandom(train); + + cv::gpu::BFMatcher_GPU d_matcher(normType); + + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_distance; + + d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); + + TEST_CYCLE() + { + d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); + } +} ////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_match +// BFKnnMatch -IMPLEMENT_PARAM_CLASS(DescriptorSize, int) +DEF_PARAM_TEST(DescSize_K_Norm, int, int, NormType); -GPU_PERF_TEST(BruteForceMatcher_match, cv::gpu::DeviceInfo, DescriptorSize, NormType) +PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine( + Values(64, 128, 256), + Values(2, 3), + Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(3.0); - int desc_size = GET_PARAM(1); + int desc_size = GET_PARAM(0); + int k = GET_PARAM(1); int normType = GET_PARAM(2); int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - cv::Mat query_host(3000, desc_size, type); - fill(query_host, 0.0, 10.0); + cv::Mat query(3000, desc_size, type); + fillRandom(query); - cv::Mat train_host(3000, desc_size, type); - fill(train_host, 0.0, 10.0); + cv::Mat train(3000, desc_size, type); + fillRandom(train); - cv::gpu::BFMatcher_GPU matcher(normType); + cv::gpu::BFMatcher_GPU d_matcher(normType); - cv::gpu::GpuMat query(query_host); - cv::gpu::GpuMat train(train_host); - cv::gpu::GpuMat trainIdx, distance; + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist; - matcher.matchSingle(query, train, trainIdx, distance); - - declare.time(3.0); + d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); TEST_CYCLE() { - matcher.matchSingle(query, train, trainIdx, distance); + d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); } } -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_match, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - ////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_knnMatch +// BFRadiusMatch -IMPLEMENT_PARAM_CLASS(K, int) - -GPU_PERF_TEST(BruteForceMatcher_knnMatch, cv::gpu::DeviceInfo, DescriptorSize, K, NormType) +PERF_TEST_P(DescSize_Norm, Features2D_BFRadiusMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(3.0); - int desc_size = GET_PARAM(1); - int k = GET_PARAM(2); - int normType = GET_PARAM(3); + int desc_size = GET_PARAM(0); + int normType = GET_PARAM(1); int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - cv::Mat query_host(3000, desc_size, type); - fill(query_host, 0.0, 10.0); + cv::Mat query(3000, desc_size, type); + fillRandom(query, 0.0, 1.0); - cv::Mat train_host(3000, desc_size, type); - fill(train_host, 0.0, 10.0); + cv::Mat train(3000, desc_size, type); + fillRandom(train, 0.0, 1.0); - cv::gpu::BFMatcher_GPU matcher(normType); + cv::gpu::BFMatcher_GPU d_matcher(normType); - cv::gpu::GpuMat query(query_host); - cv::gpu::GpuMat train(train_host); - cv::gpu::GpuMat trainIdx, distance, allDist; + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance; - matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k); - - declare.time(3.0); + d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); TEST_CYCLE() { - matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k); + d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); } } -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_knnMatch, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(K(2), K(3)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - -////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_radiusMatch - -GPU_PERF_TEST(BruteForceMatcher_radiusMatch, cv::gpu::DeviceInfo, DescriptorSize, NormType) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - int desc_size = GET_PARAM(1); - int normType = GET_PARAM(2); - - int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - - cv::Mat query_host(3000, desc_size, type); - fill(query_host, 0.0, 1.0); - - cv::Mat train_host(3000, desc_size, type); - fill(train_host, 0.0, 1.0); - - cv::gpu::BFMatcher_GPU matcher(normType); - - cv::gpu::GpuMat query(query_host); - cv::gpu::GpuMat train(train_host); - cv::gpu::GpuMat trainIdx, nMatches, distance; - - matcher.radiusMatchSingle(query, train, trainIdx, distance, nMatches, 2.0); - - declare.time(3.0); - - TEST_CYCLE() - { - matcher.radiusMatchSingle(query, train, trainIdx, distance, nMatches, 2.0); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_radiusMatch, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_filters.cpp b/modules/gpu/perf/perf_filters.cpp index 0263e8063..71dcd49e2 100644 --- a/modules/gpu/perf/perf_filters.cpp +++ b/modules/gpu/perf/perf_filters.cpp @@ -1,308 +1,235 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////////////////////// // Blur -IMPLEMENT_PARAM_CLASS(KernelSize, int) +DEF_PARAM_TEST(Sz_Type_KernelSz, cv::Size, MatType, int); -GPU_PERF_TEST(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) +PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), Values(3, 5, 7))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int ksize = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::blur(src, dst, cv::Size(ksize, ksize)); + cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); TEST_CYCLE() { - cv::gpu::blur(src, dst, cv::Size(ksize, ksize)); + cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); } } -INSTANTIATE_TEST_CASE_P(Filters, Blur, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7)))); - ////////////////////////////////////////////////////////////////////// // Sobel -GPU_PERF_TEST(Sobel, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) +PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int ksize = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; - - cv::gpu::Sobel(src, dst, -1, 1, 1, buf, ksize); + cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); TEST_CYCLE() { - cv::gpu::Sobel(src, dst, -1, 1, 1, buf, ksize); + cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); } } -INSTANTIATE_TEST_CASE_P(Filters, Sobel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - ////////////////////////////////////////////////////////////////////// // Scharr -GPU_PERF_TEST(Scharr, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Type, Filters_Scharr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; - - cv::gpu::Scharr(src, dst, -1, 1, 0, buf); + cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); TEST_CYCLE() { - cv::gpu::Scharr(src, dst, -1, 1, 0, buf); + cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); } } -INSTANTIATE_TEST_CASE_P(Filters, Scharr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)))); - ////////////////////////////////////////////////////////////////////// // GaussianBlur -GPU_PERF_TEST(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) +PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int ksize = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; - - cv::gpu::GaussianBlur(src, dst, cv::Size(ksize, ksize), buf, 0.5); + cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); TEST_CYCLE() { - cv::gpu::GaussianBlur(src, dst, cv::Size(ksize, ksize), buf, 0.5); + cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); } } -INSTANTIATE_TEST_CASE_P(Filters, GaussianBlur, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - ////////////////////////////////////////////////////////////////////// // Laplacian -GPU_PERF_TEST(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) +PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int ksize = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::Laplacian(src, dst, -1, ksize); + cv::gpu::Laplacian(d_src, d_dst, -1, ksize); TEST_CYCLE() { - cv::gpu::Laplacian(src, dst, -1, ksize); + cv::gpu::Laplacian(d_src, d_dst, -1, ksize); } } -INSTANTIATE_TEST_CASE_P(Filters, Laplacian, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)), - testing::Values(KernelSize(1), KernelSize(3)))); - ////////////////////////////////////////////////////////////////////// // Erode -GPU_PERF_TEST(Erode, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::erode(src, dst, ker, buf); + cv::gpu::erode(d_src, d_dst, ker, d_buf); TEST_CYCLE() { - cv::gpu::erode(src, dst, ker, buf); + cv::gpu::erode(d_src, d_dst, ker, d_buf); } } -INSTANTIATE_TEST_CASE_P(Filters, Erode, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); - ////////////////////////////////////////////////////////////////////// // Dilate -GPU_PERF_TEST(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Type, Filters_Dilate, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::dilate(src, dst, ker, buf); + cv::gpu::dilate(d_src, d_dst, ker, d_buf); TEST_CYCLE() { - cv::gpu::dilate(src, dst, ker, buf); + cv::gpu::dilate(d_src, d_dst, ker, d_buf); } } -INSTANTIATE_TEST_CASE_P(Filters, Dilate, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); - ////////////////////////////////////////////////////////////////////// // MorphologyEx CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT) -#define ALL_MORPH_OPS testing::Values(MorphOp(cv::MORPH_OPEN), MorphOp(cv::MORPH_CLOSE), MorphOp(cv::MORPH_GRADIENT), MorphOp(cv::MORPH_TOPHAT), MorphOp(cv::MORPH_BLACKHAT)) +#define ALL_MORPH_OPS ValuesIn(MorphOp::all()) -GPU_PERF_TEST(MorphologyEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp) +DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, MorphOp); + +PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), ALL_MORPH_OPS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int morphOp = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int morphOp = GET_PARAM(3); - - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf1; - cv::gpu::GpuMat buf2; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf1; + cv::gpu::GpuMat d_buf2; - cv::gpu::morphologyEx(src, dst, morphOp, ker, buf1, buf2); + cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); TEST_CYCLE() { - cv::gpu::morphologyEx(src, dst, morphOp, ker, buf1, buf2); + cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); } } -INSTANTIATE_TEST_CASE_P(Filters, MorphologyEx, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), - ALL_MORPH_OPS)); - ////////////////////////////////////////////////////////////////////// // Filter2D -GPU_PERF_TEST(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) +PERF_TEST_P(Sz_Type_KernelSz, Filters_Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(3, 5, 7, 9, 11, 13, 15))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int ksize = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src_host(size, type); - fill(src_host, 0.0, 255.0); + cv::Mat src(size, type); + fillRandom(src); cv::Mat kernel(ksize, ksize, CV_32FC1); - fill(kernel, 0.0, 1.0); + fillRandom(kernel, 0.0, 1.0); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::filter2D(src, dst, -1, kernel); + cv::gpu::filter2D(d_src, d_dst, -1, kernel); TEST_CYCLE() { - cv::gpu::filter2D(src, dst, -1, kernel); + cv::gpu::filter2D(d_src, d_dst, -1, kernel); } } -INSTANTIATE_TEST_CASE_P(Filters, Filter2D, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 0dbcd34c6..a1614a79f 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -1,188 +1,226 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////////////////////// // Remap -GPU_PERF_TEST(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) +enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH}; +CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH); +#define ALL_REMAP_MODES ValuesIn(RemapMode::all()) + +void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = GET_PARAM(3); - int borderMode = GET_PARAM(4); - - cv::Mat src_host(size, type); - fill(src_host, 0, 255); - - cv::Mat xmap_host(size, CV_32FC1); - fill(xmap_host, 0, size.width); - - cv::Mat ymap_host(size, CV_32FC1); - fill(ymap_host, 0, size.height); - - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat xmap(xmap_host); - cv::gpu::GpuMat ymap(ymap_host); - cv::gpu::GpuMat dst; - - cv::gpu::remap(src, dst, xmap, ymap, interpolation, borderMode); - - declare.time(3.0); - - TEST_CYCLE() + for (int j = 0; j < map_x.rows; ++j) { - cv::gpu::remap(src, dst, xmap, ymap, interpolation, borderMode); + 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 * (i - map_x.cols * 0.25) + 0.5; + map_y.at(j,i) = 2 * (j - map_x.rows * 0.25) + 0.5; + } + else + { + map_x.at(j,i) = 0; + map_y.at(j,i) = 0; + } + break; + case UPSIDE_DOWN: + map_x.at(j,i) = i; + map_y.at(j,i) = map_x.rows - j; + break; + case REFLECTION_X: + map_x.at(j,i) = map_x.cols - i; + map_y.at(j,i) = j; + break; + case REFLECTION_BOTH: + map_x.at(j,i) = map_x.cols - i; + map_y.at(j,i) = map_x.rows - j; + break; + } // end of switch + } } } -INSTANTIATE_TEST_CASE_P(ImgProc, Remap, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); +DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, int, 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), + Values(1, 3, 4), + Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), + ALL_BORDER_MODES, + ALL_REMAP_MODES)) +{ + declare.time(3.0); + + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); + int interpolation = GET_PARAM(3); + int borderMode = GET_PARAM(4); + int remapMode = GET_PARAM(5); + + int type = CV_MAKE_TYPE(depth, channels); + + cv::Mat src(size, type); + fillRandom(src); + + cv::Mat xmap(size, CV_32FC1); + cv::Mat ymap(size, CV_32FC1); + + generateMap(xmap, ymap, remapMode); + + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_xmap(xmap); + cv::gpu::GpuMat d_ymap(ymap); + cv::gpu::GpuMat d_dst; + + cv::gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode); + + TEST_CYCLE() + { + cv::gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode); + } +} ////////////////////////////////////////////////////////////////////// // Resize -IMPLEMENT_PARAM_CLASS(Scale, double) +DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, int, Interpolation, double); -GPU_PERF_TEST(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Scale) +PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + ALL_INTERPOLATIONS, + Values(0.5, 0.3, 2.0))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(1.0); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int interpolation = GET_PARAM(3); double f = GET_PARAM(4); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::resize(src, dst, cv::Size(), f, f, interpolation); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - declare.time(1.0); + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); TEST_CYCLE() { - cv::gpu::resize(src, dst, cv::Size(), f, f, interpolation); + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Resize, testing::Combine( - ALL_DEVICES, +////////////////////////////////////////////////////////////////////// +// ResizeArea + +DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, int, double); + +PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea, Combine( GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), - Interpolation(cv::INTER_CUBIC), Interpolation(cv::INTER_AREA)), - testing::Values(Scale(0.5), Scale(0.3), Scale(2.0)))); - -GPU_PERF_TEST(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, Scale) + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + Values(0.2, 0.1, 0.05))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(1.0); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int interpolation = cv::INTER_AREA; double f = GET_PARAM(3); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::resize(src, dst, cv::Size(), f, f, interpolation); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - declare.time(1.0); + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); TEST_CYCLE() { - cv::gpu::resize(src, dst, cv::Size(), f, f, interpolation); + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); } } -INSTANTIATE_TEST_CASE_P(ImgProc, ResizeArea, testing::Combine( - ALL_DEVICES, - testing::Values(perf::sz1080p/*, cv::Size(4096, 2048)*/), - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Scale(0.2),Scale(0.1),Scale(0.05)))); - ////////////////////////////////////////////////////////////////////// // WarpAffine -GPU_PERF_TEST(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); +DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, int, Interpolation, BorderMode); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); +PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), + ALL_BORDER_MODES)) +{ + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int interpolation = GET_PARAM(3); int borderMode = GET_PARAM(4); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); const double aplha = CV_PI / 4; double mat[2][3] = { {std::cos(aplha), -std::sin(aplha), src.cols / 2}, {std::sin(aplha), std::cos(aplha), 0}}; cv::Mat M(2, 3, CV_64F, (void*) mat); - cv::gpu::warpAffine(src, dst, M, size, interpolation, borderMode); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::warpAffine(d_src, d_dst, M, size, interpolation, borderMode); TEST_CYCLE() { - cv::gpu::warpAffine(src, dst, M, size, interpolation, borderMode); + cv::gpu::warpAffine(d_src, d_dst, M, size, interpolation, borderMode); } } -INSTANTIATE_TEST_CASE_P(ImgProc, WarpAffine, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - ////////////////////////////////////////////////////////////////////// // WarpPerspective -GPU_PERF_TEST(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) +PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), + ALL_BORDER_MODES)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int interpolation = GET_PARAM(3); int borderMode = GET_PARAM(4); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); const double aplha = CV_PI / 4; double mat[3][3] = { {std::cos(aplha), -std::sin(aplha), src.cols / 2}, @@ -190,1160 +228,958 @@ GPU_PERF_TEST(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Interpola {0.0, 0.0, 1.0}}; cv::Mat M(3, 3, CV_64F, (void*) mat); - cv::gpu::warpPerspective(src, dst, M, size, interpolation, borderMode); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::warpPerspective(d_src, d_dst, M, size, interpolation, borderMode); TEST_CYCLE() { - cv::gpu::warpPerspective(src, dst, M, size, interpolation, borderMode); + cv::gpu::warpPerspective(d_src, d_dst, M, size, interpolation, borderMode); } } -INSTANTIATE_TEST_CASE_P(ImgProc, WarpPerspective, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - ////////////////////////////////////////////////////////////////////// // CopyMakeBorder -GPU_PERF_TEST(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, BorderMode) +DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, int, BorderMode); + +PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + ALL_BORDER_MODES)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); + int borderMode = GET_PARAM(3); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int borderType = GET_PARAM(3); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::copyMakeBorder(src, dst, 5, 5, 5, 5, borderType); + cv::gpu::copyMakeBorder(d_src, d_dst, 5, 5, 5, 5, borderMode); TEST_CYCLE() { - cv::gpu::copyMakeBorder(src, dst, 5, 5, 5, 5, borderType); + cv::gpu::copyMakeBorder(d_src, d_dst, 5, 5, 5, 5, borderMode); } } -INSTANTIATE_TEST_CASE_P(ImgProc, CopyMakeBorder, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - ////////////////////////////////////////////////////////////////////// // Threshold CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV) -#define ALL_THRESH_OPS testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV)) +#define ALL_THRESH_OPS ValuesIn(ThreshOp::all()) -GPU_PERF_TEST(Threshold, cv::gpu::DeviceInfo, cv::Size, MatDepth, ThreshOp) +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), + ALL_THRESH_OPS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int threshOp = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int threshOp = GET_PARAM(3); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::threshold(src, dst, 100.0, 255.0, threshOp); + cv::gpu::threshold(d_src, d_dst, 100.0, 255.0, threshOp); TEST_CYCLE() { - cv::gpu::threshold(src, dst, 100.0, 255.0, threshOp); + cv::gpu::threshold(d_src, d_dst, 100.0, 255.0, threshOp); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Threshold, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)), - ALL_THRESH_OPS)); - ////////////////////////////////////////////////////////////////////// // Integral -GPU_PERF_TEST(Integral, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_Integral, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_8UC1); + fillRandom(src); - cv::Mat src_host(size, CV_8UC1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat buf; - - cv::gpu::integralBuffered(src, dst, buf); + cv::gpu::integralBuffered(d_src, d_dst, d_buf); TEST_CYCLE() { - cv::gpu::integralBuffered(src, dst, buf); + cv::gpu::integralBuffered(d_src, d_dst, d_buf); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Integral, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// -// Integral_Sqr +// IntegralSqr -GPU_PERF_TEST(Integral_Sqr, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_IntegralSqr, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_8UC1); + fillRandom(src); - cv::Mat src_host(size, CV_8UC1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::sqrIntegral(src, dst); + cv::gpu::sqrIntegral(d_src, d_dst); TEST_CYCLE() { - cv::gpu::sqrIntegral(src, dst); + cv::gpu::sqrIntegral(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Integral_Sqr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// -// HistEven_OneChannel +// HistEvenC1 -GPU_PERF_TEST(HistEven_OneChannel, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC1, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_16S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, depth); + fillRandom(src); - cv::Mat src_host(size, depth); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat hist; - cv::gpu::GpuMat buf; - - cv::gpu::histEven(src, hist, buf, 30, 0, 180); + cv::gpu::histEven(d_src, d_hist, d_buf, 30, 0, 180); TEST_CYCLE() { - cv::gpu::histEven(src, hist, buf, 30, 0, 180); + cv::gpu::histEven(d_src, d_hist, d_buf, 30, 0, 180); } } -INSTANTIATE_TEST_CASE_P(ImgProc, HistEven_OneChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S)))); - ////////////////////////////////////////////////////////////////////// -// HistEven_FourChannel +// HistEvenC4 -GPU_PERF_TEST(HistEven_FourChannel, cv::gpu::DeviceInfo, cv::Size, MatDepth) +PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC4, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_16S))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); + cv::Mat src(size, CV_MAKE_TYPE(depth, 4)); + fillRandom(src); - cv::Mat src_host(size, CV_MAKE_TYPE(depth, 4)); - fill(src_host, 0, 255); - - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat hist[4]; - cv::gpu::GpuMat buf; int histSize[] = {30, 30, 30, 30}; int lowerLevel[] = {0, 0, 0, 0}; int upperLevel[] = {180, 180, 180, 180}; - cv::gpu::histEven(src, hist, buf, histSize, lowerLevel, upperLevel); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist[4]; + cv::gpu::GpuMat d_buf; + + cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); TEST_CYCLE() { - cv::gpu::histEven(src, hist, buf, histSize, lowerLevel, upperLevel); + cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); } } -INSTANTIATE_TEST_CASE_P(ImgProc, HistEven_FourChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S)))); - ////////////////////////////////////////////////////////////////////// // CalcHist -GPU_PERF_TEST(CalcHist, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_CalcHist, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_8UC1); + fillRandom(src); - cv::Mat src_host(size, CV_8UC1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat hist; - cv::gpu::GpuMat buf; - - cv::gpu::calcHist(src, hist, buf); + cv::gpu::calcHist(d_src, d_hist, d_buf); TEST_CYCLE() { - cv::gpu::calcHist(src, hist, buf); + cv::gpu::calcHist(d_src, d_hist, d_buf); } } -INSTANTIATE_TEST_CASE_P(ImgProc, CalcHist, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // EqualizeHist -GPU_PERF_TEST(EqualizeHist, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_EqualizeHist, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_8UC1); + fillRandom(src); - cv::Mat src_host(size, CV_8UC1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat hist; - cv::gpu::GpuMat buf; - - cv::gpu::equalizeHist(src, dst, hist, buf); + cv::gpu::equalizeHist(d_src, d_dst, d_hist, d_buf); TEST_CYCLE() { - cv::gpu::equalizeHist(src, dst, hist, buf); + cv::gpu::equalizeHist(d_src, d_dst, d_hist, d_buf); } } -INSTANTIATE_TEST_CASE_P(ImgProc, EqualizeHist, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // ColumnSum -GPU_PERF_TEST(ColumnSum, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_ColumnSum, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); + cv::Mat src(size, CV_32FC1); + fillRandom(src); - cv::Mat src_host(size, CV_32FC1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::columnSum(src, dst); + cv::gpu::columnSum(d_src, d_dst); TEST_CYCLE() { - cv::gpu::columnSum(src, dst); + cv::gpu::columnSum(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(ImgProc, ColumnSum, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Canny -IMPLEMENT_PARAM_CLASS(AppertureSize, int) -IMPLEMENT_PARAM_CLASS(L2gradient, bool) +DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool); -GPU_PERF_TEST(Canny, cv::gpu::DeviceInfo, AppertureSize, L2gradient) +PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny, Combine( + Values("perf/800x600.jpg", "perf/1280x1024.jpg", "perf/1680x1050.jpg"), + Values(3, 5), + Bool())) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - + string fileName = GET_PARAM(0); int apperture_size = GET_PARAM(1); bool useL2gradient = GET_PARAM(2); - cv::Mat image_host = readImage("perf/1280x1024.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image_host.empty()); + cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(image.empty()); - cv::gpu::GpuMat image(image_host); - cv::gpu::GpuMat dst; - cv::gpu::CannyBuf buf; + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_dst; + cv::gpu::CannyBuf d_buf; - cv::gpu::Canny(image, buf, dst, 50.0, 100.0, apperture_size, useL2gradient); + cv::gpu::Canny(d_image, d_buf, d_dst, 50.0, 100.0, apperture_size, useL2gradient); TEST_CYCLE() { - cv::gpu::Canny(image, buf, dst, 50.0, 100.0, apperture_size, useL2gradient); + cv::gpu::Canny(d_image, d_buf, d_dst, 50.0, 100.0, apperture_size, useL2gradient); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine( - ALL_DEVICES, - testing::Values(AppertureSize(3), AppertureSize(5)), - testing::Values(L2gradient(false), L2gradient(true)))); - ////////////////////////////////////////////////////////////////////// // MeanShiftFiltering -GPU_PERF_TEST_1(MeanShiftFiltering, cv::gpu::DeviceInfo) -{ - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); +DEF_PARAM_TEST_1(Image, string); - cv::Mat img = readImage("gpu/meanshift/cones.png"); +PERF_TEST_P(Image, ImgProc_MeanShiftFiltering, Values("gpu/meanshift/cones.png")) +{ + declare.time(5.0); + + cv::Mat img = readImage(GetParam()); ASSERT_FALSE(img.empty()); cv::Mat rgba; cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - cv::gpu::GpuMat src(rgba); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(rgba); + cv::gpu::GpuMat d_dst; - cv::gpu::meanShiftFiltering(src, dst, 50, 50); - - declare.time(5.0); + cv::gpu::meanShiftFiltering(d_src, d_dst, 50, 50); TEST_CYCLE() { - cv::gpu::meanShiftFiltering(src, dst, 50, 50); + cv::gpu::meanShiftFiltering(d_src, d_dst, 50, 50); } } -INSTANTIATE_TEST_CASE_P(ImgProc, MeanShiftFiltering, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // MeanShiftProc -GPU_PERF_TEST_1(MeanShiftProc, cv::gpu::DeviceInfo) +PERF_TEST_P(Image, ImgProc_MeanShiftProc, Values("gpu/meanshift/cones.png")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(5.0); - cv::Mat img = readImage("gpu/meanshift/cones.png"); + cv::Mat img = readImage(GetParam()); ASSERT_FALSE(img.empty()); cv::Mat rgba; cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - cv::gpu::GpuMat src(rgba); - cv::gpu::GpuMat dstr; - cv::gpu::GpuMat dstsp; + cv::gpu::GpuMat d_src(rgba); + cv::gpu::GpuMat d_dstr; + cv::gpu::GpuMat d_dstsp; - cv::gpu::meanShiftProc(src, dstr, dstsp, 50, 50); - - declare.time(5.0); + cv::gpu::meanShiftProc(d_src, d_dstr, d_dstsp, 50, 50); TEST_CYCLE() { - cv::gpu::meanShiftProc(src, dstr, dstsp, 50, 50); + cv::gpu::meanShiftProc(d_src, d_dstr, d_dstsp, 50, 50); } } -INSTANTIATE_TEST_CASE_P(ImgProc, MeanShiftProc, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // MeanShiftSegmentation -GPU_PERF_TEST_1(MeanShiftSegmentation, cv::gpu::DeviceInfo) +PERF_TEST_P(Image, ImgProc_MeanShiftSegmentation, Values("gpu/meanshift/cones.png")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(5.0); - cv::Mat img = readImage("gpu/meanshift/cones.png"); + cv::Mat img = readImage(GetParam()); ASSERT_FALSE(img.empty()); cv::Mat rgba; cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - cv::gpu::GpuMat src(rgba); cv::Mat dst; - meanShiftSegmentation(src, dst, 10, 10, 20); + cv::gpu::GpuMat d_src(rgba); - declare.time(5.0); + cv::gpu::meanShiftSegmentation(d_src, dst, 10, 10, 20); TEST_CYCLE() { - meanShiftSegmentation(src, dst, 10, 10, 20); + cv::gpu::meanShiftSegmentation(d_src, dst, 10, 10, 20); } } -INSTANTIATE_TEST_CASE_P(ImgProc, MeanShiftSegmentation, ALL_DEVICES); - ////////////////////////////////////////////////////////////////////// // BlendLinear -GPU_PERF_TEST(BlendLinear, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_32F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat img1_host(size, type); - fill(img1_host, 0, 255); + cv::Mat img1(size, type); + fillRandom(img1); - cv::Mat img2_host(size, type); - fill(img2_host, 0, 255); + cv::Mat img2(size, type); + fillRandom(img2); - cv::gpu::GpuMat img1(img1_host); - cv::gpu::GpuMat img2(img2_host); - cv::gpu::GpuMat weights1(size, CV_32FC1, cv::Scalar::all(0.5)); - cv::gpu::GpuMat weights2(size, CV_32FC1, cv::Scalar::all(0.5)); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_img1(img1); + cv::gpu::GpuMat d_img2(img2); + cv::gpu::GpuMat d_weights1(size, CV_32FC1, cv::Scalar::all(0.5)); + cv::gpu::GpuMat d_weights2(size, CV_32FC1, cv::Scalar::all(0.5)); + cv::gpu::GpuMat d_dst; - cv::gpu::blendLinear(img1, img2, weights1, weights2, dst); + cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, d_dst); TEST_CYCLE() { - cv::gpu::blendLinear(img1, img2, weights1, weights2, dst); + cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, d_dst); } } -INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - ////////////////////////////////////////////////////////////////////// // Convolve -IMPLEMENT_PARAM_CLASS(KSize, int) -IMPLEMENT_PARAM_CLASS(Ccorr, bool) +DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool); -GPU_PERF_TEST(Convolve, cv::gpu::DeviceInfo, cv::Size, KSize, Ccorr) +PERF_TEST_P(Sz_KernelSz_Ccorr, ImgProc_Convolve, Combine(GPU_TYPICAL_MAT_SIZES, Values(17, 27, 32, 64), Bool())) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int templ_size = GET_PARAM(2); - bool ccorr = GET_PARAM(3); - - cv::gpu::GpuMat image = cv::gpu::createContinuous(size, CV_32FC1); - image.setTo(cv::Scalar(1.0)); - - cv::gpu::GpuMat templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1); - templ.setTo(cv::Scalar(1.0)); - - cv::gpu::GpuMat dst; - cv::gpu::ConvolveBuf buf; - - cv::gpu::convolve(image, templ, dst, ccorr, buf); - declare.time(2.0); + cv::Size size = GET_PARAM(0); + int templ_size = GET_PARAM(1); + bool ccorr = GET_PARAM(2); + + cv::gpu::GpuMat d_image = cv::gpu::createContinuous(size, CV_32FC1); + d_image.setTo(cv::Scalar(1.0)); + + cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1); + d_templ.setTo(cv::Scalar(1.0)); + + cv::gpu::GpuMat d_dst; + cv::gpu::ConvolveBuf d_buf; + + cv::gpu::convolve(d_image, d_templ, d_dst, ccorr, d_buf); + TEST_CYCLE() { - cv::gpu::convolve(image, templ, dst, ccorr, buf); + cv::gpu::convolve(d_image, d_templ, d_dst, ccorr, d_buf); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Convolve, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(KSize(3), KSize(9), KSize(17), KSize(27), KSize(32), KSize(64)), - testing::Values(Ccorr(false), Ccorr(true)))); - //////////////////////////////////////////////////////////////////////////////// -// MatchTemplate_8U +// MatchTemplate8U CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED) -#define ALL_TEMPLATE_METHODS testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_SQDIFF_NORMED), TemplateMethod(cv::TM_CCORR), TemplateMethod(cv::TM_CCORR_NORMED), TemplateMethod(cv::TM_CCOEFF), TemplateMethod(cv::TM_CCOEFF_NORMED)) +#define ALL_TEMPLATE_METHODS ValuesIn(TemplateMethod::all()) -IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size) +DEF_PARAM_TEST(Sz_TemplateSz_Cn_Method, cv::Size, cv::Size, int, TemplateMethod); -GPU_PERF_TEST(MatchTemplate_8U, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Channels, 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)), + Values(1, 3, 4), + ALL_TEMPLATE_METHODS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + cv::Size templ_size = GET_PARAM(1); + int cn = GET_PARAM(2); + int method = GET_PARAM(3); - cv::Size size = GET_PARAM(1); - cv::Size templ_size = GET_PARAM(2); - int cn = GET_PARAM(3); - int method = GET_PARAM(4); + cv::Mat image(size, CV_MAKE_TYPE(CV_8U, cn)); + fillRandom(image); - cv::Mat image_host(size, CV_MAKE_TYPE(CV_8U, cn)); - fill(image_host, 0, 255); + cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_8U, cn)); + fillRandom(templ); - cv::Mat templ_host(templ_size, CV_MAKE_TYPE(CV_8U, cn)); - fill(templ_host, 0, 255); + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_templ(templ); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat image(image_host); - cv::gpu::GpuMat templ(templ_host); - cv::gpu::GpuMat dst; - - cv::gpu::matchTemplate(image, templ, dst, method); + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); TEST_CYCLE() { - cv::gpu::matchTemplate(image, templ, dst, method); + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); } }; -INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate_8U, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))), - testing::Values(Channels(1), Channels(3), Channels(4)), - ALL_TEMPLATE_METHODS)); - //////////////////////////////////////////////////////////////////////////////// -// MatchTemplate_32F +// MatchTemplate32F -GPU_PERF_TEST(MatchTemplate_32F, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Channels, TemplateMethod) +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)), + Values(1, 3, 4), + Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + cv::Size templ_size = GET_PARAM(1); + int cn = GET_PARAM(2); + int method = GET_PARAM(3); - cv::Size size = GET_PARAM(1); - cv::Size templ_size = GET_PARAM(2); - int cn = GET_PARAM(3); - int method = GET_PARAM(4); + cv::Mat image(size, CV_MAKE_TYPE(CV_32F, cn)); + fillRandom(image); - cv::Mat image_host(size, CV_MAKE_TYPE(CV_32F, cn)); - fill(image_host, 0, 255); + cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_32F, cn)); + fillRandom(templ); - cv::Mat templ_host(templ_size, CV_MAKE_TYPE(CV_32F, cn)); - fill(templ_host, 0, 255); + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_templ(templ); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat image(image_host); - cv::gpu::GpuMat templ(templ_host); - cv::gpu::GpuMat dst; - - cv::gpu::matchTemplate(image, templ, dst, method); + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); TEST_CYCLE() { - cv::gpu::matchTemplate(image, templ, dst, method); + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); } }; -INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate_32F, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))), - testing::Values(Channels(1), Channels(3), Channels(4)), - testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR)))); - ////////////////////////////////////////////////////////////////////// // MulSpectrums CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT) -GPU_PERF_TEST(MulSpectrums, cv::gpu::DeviceInfo, cv::Size, DftFlags) +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)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int flag = GET_PARAM(1); - cv::Size size = GET_PARAM(1); - int flag = GET_PARAM(2); + cv::Mat a(size, CV_32FC2); + fillRandom(a, 0, 100); - cv::Mat a_host(size, CV_32FC2); - fill(a_host, 0, 100); + cv::Mat b(size, CV_32FC2); + fillRandom(b, 0, 100); - cv::Mat b_host(size, CV_32FC2); - fill(b_host, 0, 100); + cv::gpu::GpuMat d_a(a); + cv::gpu::GpuMat d_b(b); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat a(a_host); - cv::gpu::GpuMat b(b_host); - cv::gpu::GpuMat dst; - - cv::gpu::mulSpectrums(a, b, dst, flag); + cv::gpu::mulSpectrums(d_a, d_b, d_dst, flag); TEST_CYCLE() { - cv::gpu::mulSpectrums(a, b, dst, flag); + cv::gpu::mulSpectrums(d_a, d_b, d_dst, flag); } } -INSTANTIATE_TEST_CASE_P(ImgProc, MulSpectrums, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS)))); - ////////////////////////////////////////////////////////////////////// // MulAndScaleSpectrums -GPU_PERF_TEST(MulAndScaleSpectrums, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_MulAndScaleSpectrums, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); + cv::Size size = GetParam(); float scale = 1.f / size.area(); - cv::Mat src1_host(size, CV_32FC2); - fill(src1_host, 0, 100); + cv::Mat src1(size, CV_32FC2); + fillRandom(src1, 0, 100); - cv::Mat src2_host(size, CV_32FC2); - fill(src2_host, 0, 100); + cv::Mat src2(size, CV_32FC2); + fillRandom(src2, 0, 100); - cv::gpu::GpuMat src1(src1_host); - cv::gpu::GpuMat src2(src2_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; - cv::gpu::mulAndScaleSpectrums(src1, src2, dst, cv::DFT_ROWS, scale, false); + cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, d_dst, cv::DFT_ROWS, scale, false); TEST_CYCLE() { - cv::gpu::mulAndScaleSpectrums(src1, src2, dst, cv::DFT_ROWS, scale, false); + cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, d_dst, cv::DFT_ROWS, scale, false); } } -INSTANTIATE_TEST_CASE_P(ImgProc, MulAndScaleSpectrums, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Dft -GPU_PERF_TEST(Dft, cv::gpu::DeviceInfo, cv::Size, DftFlags) +PERF_TEST_P(Sz_Flags, ImgProc_Dft, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); - int flag = GET_PARAM(2); - - cv::Mat src_host(size, CV_32FC2); - fill(src_host, 0, 100); - - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - cv::gpu::dft(src, dst, size, flag); - declare.time(2.0); + cv::Size size = GET_PARAM(0); + int flag = GET_PARAM(1); + + cv::Mat src(size, CV_32FC2); + fillRandom(src, 0, 100); + + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::dft(d_src, d_dst, size, flag); + TEST_CYCLE() { - cv::gpu::dft(src, dst, size, flag); + cv::gpu::dft(d_src, d_dst, size, flag); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Dft, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))); - ////////////////////////////////////////////////////////////////////// // CornerHarris -IMPLEMENT_PARAM_CLASS(BlockSize, int) -IMPLEMENT_PARAM_CLASS(ApertureSize, int) +DEF_PARAM_TEST(Image_Type_Border_BlockSz_ApertureSz, string, MatType, BorderMode, int, int); -GPU_PERF_TEST(CornerHarris, cv::gpu::DeviceInfo, MatType, BorderMode, BlockSize, ApertureSize) +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))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + double k = 0.5; + string fileName = GET_PARAM(0); int type = GET_PARAM(1); - int borderType = GET_PARAM(2); + int borderMode = GET_PARAM(2); int blockSize = GET_PARAM(3); int apertureSize = GET_PARAM(4); - cv::Mat img = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); + 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); - cv::gpu::GpuMat src(img); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat Dx; - cv::gpu::GpuMat Dy; - cv::gpu::GpuMat buf; + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_Dx; + cv::gpu::GpuMat d_Dy; + cv::gpu::GpuMat d_buf; - double k = 0.5; - - cv::gpu::cornerHarris(src, dst, Dx, Dy, buf, blockSize, apertureSize, k, borderType); + cv::gpu::cornerHarris(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); TEST_CYCLE() { - cv::gpu::cornerHarris(src, dst, Dx, Dy, buf, blockSize, apertureSize, k, borderType); + cv::gpu::cornerHarris(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); } } -INSTANTIATE_TEST_CASE_P(ImgProc, CornerHarris, testing::Combine( - ALL_DEVICES, - testing::Values(MatType(CV_8UC1), MatType(CV_32FC1)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - testing::Values(BlockSize(3), BlockSize(5), BlockSize(7)), - testing::Values(ApertureSize(0), ApertureSize(3), ApertureSize(5), ApertureSize(7)))); - ////////////////////////////////////////////////////////////////////// // CornerMinEigenVal -GPU_PERF_TEST(CornerMinEigenVal, cv::gpu::DeviceInfo, MatType, BorderMode, BlockSize, ApertureSize) +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))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - + string fileName = GET_PARAM(0); int type = GET_PARAM(1); - int borderType = GET_PARAM(2); + int borderMode = GET_PARAM(2); int blockSize = GET_PARAM(3); int apertureSize = GET_PARAM(4); - cv::Mat img = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); + 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); - cv::gpu::GpuMat src(img); - cv::gpu::GpuMat dst; - cv::gpu::GpuMat Dx; - cv::gpu::GpuMat Dy; - cv::gpu::GpuMat buf; + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_Dx; + cv::gpu::GpuMat d_Dy; + cv::gpu::GpuMat d_buf; - cv::gpu::cornerMinEigenVal(src, dst, Dx, Dy, buf, blockSize, apertureSize, borderType); + cv::gpu::cornerMinEigenVal(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); TEST_CYCLE() { - cv::gpu::cornerMinEigenVal(src, dst, Dx, Dy, buf, blockSize, apertureSize, borderType); + cv::gpu::cornerMinEigenVal(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); } } -INSTANTIATE_TEST_CASE_P(ImgProc, CornerMinEigenVal, testing::Combine( - ALL_DEVICES, - testing::Values(MatType(CV_8UC1), MatType(CV_32FC1)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - testing::Values(BlockSize(3), BlockSize(5), BlockSize(7)), - testing::Values(ApertureSize(0), ApertureSize(3), ApertureSize(5), ApertureSize(7)))); - ////////////////////////////////////////////////////////////////////// // BuildWarpPlaneMaps -GPU_PERF_TEST(BuildWarpPlaneMaps, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_BuildWarpPlaneMaps, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); + cv::Size size = GetParam(); cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); cv::Mat T = cv::Mat::zeros(1, 3, CV_32F); - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, map_x, map_y); + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + + cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, d_map_x, d_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); + cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, d_map_x, d_map_y); } } -INSTANTIATE_TEST_CASE_P(ImgProc, BuildWarpPlaneMaps, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // BuildWarpCylindricalMaps -GPU_PERF_TEST(BuildWarpCylindricalMaps, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_BuildWarpCylindricalMaps, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); + cv::Size size = GetParam(); cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + + cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); TEST_CYCLE() { - cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); + cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); } } -INSTANTIATE_TEST_CASE_P(ImgProc, BuildWarpCylindricalMaps, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // BuildWarpSphericalMaps -GPU_PERF_TEST(BuildWarpSphericalMaps, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_BuildWarpSphericalMaps, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Size size = GET_PARAM(1); + cv::Size size = GetParam(); cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat map_x; - cv::gpu::GpuMat map_y; - cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + + cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); TEST_CYCLE() { - cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y); + cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); } } -INSTANTIATE_TEST_CASE_P(ImgProc, BuildWarpSphericalMaps, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // Rotate -GPU_PERF_TEST(Rotate, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); +DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, int, Interpolation); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); +PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4), + Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))) +{ + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); int interpolation = GET_PARAM(3); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::rotate(src, dst, size, 30.0, 0, 0, interpolation); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::rotate(d_src, d_dst, size, 30.0, 0, 0, interpolation); TEST_CYCLE() { - cv::gpu::rotate(src, dst, size, 30.0, 0, 0, interpolation); + cv::gpu::rotate(d_src, d_dst, size, 30.0, 0, 0, interpolation); } } -INSTANTIATE_TEST_CASE_P(ImgProc, Rotate, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)))); - ////////////////////////////////////////////////////////////////////// // PyrDown -GPU_PERF_TEST(PyrDown, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrDown, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::pyrDown(src, dst); + cv::gpu::pyrDown(d_src, d_dst); TEST_CYCLE() { - cv::gpu::pyrDown(src, dst); + cv::gpu::pyrDown(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(ImgProc, PyrDown, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - ////////////////////////////////////////////////////////////////////// // PyrUp -GPU_PERF_TEST(PyrUp, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrUp, Combine( + GPU_TYPICAL_MAT_SIZES, + Values(CV_8U, CV_16U, CV_32F), + Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::pyrUp(src, dst); + cv::gpu::pyrUp(d_src, d_dst); TEST_CYCLE() { - cv::gpu::pyrUp(src, dst); + cv::gpu::pyrUp(d_src, d_dst); } } -INSTANTIATE_TEST_CASE_P(ImgProc, PyrUp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - ////////////////////////////////////////////////////////////////////// // CvtColor -GPU_PERF_TEST(CvtColor, cv::gpu::DeviceInfo, cv::Size, MatDepth, CvtColorInfo) +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_16U, 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_RGB2Lab), + CvtColorInfo(3, 3, cv::COLOR_BGR2Luv), + CvtColorInfo(3, 3, cv::COLOR_RGB2Luv), + CvtColorInfo(3, 3, cv::COLOR_Lab2BGR), + CvtColorInfo(3, 3, cv::COLOR_Lab2RGB), + CvtColorInfo(3, 3, cv::COLOR_Luv2BGR), + CvtColorInfo(3, 3, cv::COLOR_Luv2RGB), + 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(4, 4, cv::COLOR_RGBA2mRGBA)))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + CvtColorInfo info = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - CvtColorInfo info = GET_PARAM(3); + cv::Mat src(size, CV_MAKETYPE(depth, info.scn)); + fillRandom(src); - cv::Mat src_host(size, CV_MAKETYPE(depth, info.scn)); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - if (info.code >= cv::COLOR_BayerBG2BGR && info.code <= cv::COLOR_BayerGR2BGR) - info.dcn = 4; - - cv::gpu::cvtColor(src, dst, info.code, info.dcn); + cv::gpu::cvtColor(d_src, d_dst, info.code, info.dcn); TEST_CYCLE() { - cv::gpu::cvtColor(src, dst, info.code, info.dcn); + cv::gpu::cvtColor(d_src, d_dst, info.code, info.dcn); } } -INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F)), - testing::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_RGB2Lab), - CvtColorInfo(3, 3, cv::COLOR_BGR2Luv), - CvtColorInfo(3, 3, cv::COLOR_RGB2Luv), - CvtColorInfo(3, 3, cv::COLOR_Lab2BGR), - CvtColorInfo(3, 3, cv::COLOR_Lab2RGB), - CvtColorInfo(3, 3, cv::COLOR_Luv2BGR), - CvtColorInfo(3, 3, cv::COLOR_Luv2RGB), - 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(4, 4, cv::COLOR_RGBA2mRGBA)))); - ////////////////////////////////////////////////////////////////////// // SwapChannels -GPU_PERF_TEST(SwapChannels, cv::gpu::DeviceInfo, cv::Size) +PERF_TEST_P(Sz, ImgProc_SwapChannels, GPU_TYPICAL_MAT_SIZES) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GetParam(); - cv::Size size = GET_PARAM(1); - - cv::Mat src_host(size, CV_8UC4); - fill(src_host, 0, 255); - - cv::gpu::GpuMat src(src_host); + cv::Mat src(size, CV_8UC4); + fillRandom(src); const int dstOrder[] = {2, 1, 0, 3}; - cv::gpu::swapChannels(src, dstOrder); + cv::gpu::GpuMat d_src(src); + + cv::gpu::swapChannels(d_src, dstOrder); TEST_CYCLE() { - cv::gpu::swapChannels(src, dstOrder); + cv::gpu::swapChannels(d_src, dstOrder); } } -INSTANTIATE_TEST_CASE_P(ImgProc, SwapChannels, testing::Combine(ALL_DEVICES, GPU_TYPICAL_MAT_SIZES)); - ////////////////////////////////////////////////////////////////////// // AlphaComp CV_ENUM(AlphaOp, cv::gpu::ALPHA_OVER, cv::gpu::ALPHA_IN, cv::gpu::ALPHA_OUT, cv::gpu::ALPHA_ATOP, cv::gpu::ALPHA_XOR, cv::gpu::ALPHA_PLUS, cv::gpu::ALPHA_OVER_PREMUL, cv::gpu::ALPHA_IN_PREMUL, cv::gpu::ALPHA_OUT_PREMUL, cv::gpu::ALPHA_ATOP_PREMUL, cv::gpu::ALPHA_XOR_PREMUL, cv::gpu::ALPHA_PLUS_PREMUL, cv::gpu::ALPHA_PREMUL) +#define ALL_ALPHA_OPS ValuesIn(AlphaOp::all()) -GPU_PERF_TEST(AlphaComp, cv::gpu::DeviceInfo, cv::Size, MatType, AlphaOp) +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), ALL_ALPHA_OPS)) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int type = GET_PARAM(1); + int alpha_op = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int alpha_op = GET_PARAM(3); + cv::Mat img1(size, type); + fillRandom(img1); - cv::Mat img1_host(size, type); - fill(img1_host, 0, 255); + cv::Mat img2(size, type); + fillRandom(img2); - cv::Mat img2_host(size, type); - fill(img2_host, 0, 255); + cv::gpu::GpuMat d_img1(img1); + cv::gpu::GpuMat d_img2(img2); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat img1(img1_host); - cv::gpu::GpuMat img2(img2_host); - cv::gpu::GpuMat dst; - - cv::gpu::alphaComp(img1, img2, dst, alpha_op); + cv::gpu::alphaComp(d_img1, d_img2, d_dst, alpha_op); TEST_CYCLE() { - cv::gpu::alphaComp(img1, img2, dst, alpha_op); + cv::gpu::alphaComp(d_img1, d_img2, d_dst, alpha_op); } } -INSTANTIATE_TEST_CASE_P(ImgProc, AlphaComp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC4), MatType(CV_16UC4), MatType(CV_32SC4), MatType(CV_32FC4)), - testing::Values(AlphaOp(cv::gpu::ALPHA_OVER), - AlphaOp(cv::gpu::ALPHA_IN), - AlphaOp(cv::gpu::ALPHA_OUT), - AlphaOp(cv::gpu::ALPHA_ATOP), - AlphaOp(cv::gpu::ALPHA_XOR), - AlphaOp(cv::gpu::ALPHA_PLUS), - AlphaOp(cv::gpu::ALPHA_OVER_PREMUL), - AlphaOp(cv::gpu::ALPHA_IN_PREMUL), - AlphaOp(cv::gpu::ALPHA_OUT_PREMUL), - AlphaOp(cv::gpu::ALPHA_ATOP_PREMUL), - AlphaOp(cv::gpu::ALPHA_XOR_PREMUL), - AlphaOp(cv::gpu::ALPHA_PLUS_PREMUL), - AlphaOp(cv::gpu::ALPHA_PREMUL)))); - ////////////////////////////////////////////////////////////////////// -// ImagePyramid +// ImagePyramidBuild -GPU_PERF_TEST(ImagePyramid_build, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidBuild, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); + cv::gpu::GpuMat d_src(src); - cv::gpu::ImagePyramid pyr; + cv::gpu::ImagePyramid d_pyr; - pyr.build(src, 5); + d_pyr.build(d_src, 5); TEST_CYCLE() { - pyr.build(src, 5); + d_pyr.build(d_src, 5); } } -INSTANTIATE_TEST_CASE_P(ImgProc, ImagePyramid_build, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); +////////////////////////////////////////////////////////////////////// +// ImagePyramidGetLayer -GPU_PERF_TEST(ImagePyramid_getLayer, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidGetLayer, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; + cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10); - cv::gpu::ImagePyramid pyr(src, 3); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - pyr.getLayer(dst, cv::Size(size.width / 2 + 10, size.height / 2 + 10)); + cv::gpu::ImagePyramid d_pyr(d_src, 3); + + d_pyr.getLayer(d_dst, dstSize); TEST_CYCLE() { - pyr.getLayer(dst, cv::Size(size.width / 2 + 10, size.height / 2 + 10)); + d_pyr.getLayer(d_dst, dstSize); } } -INSTANTIATE_TEST_CASE_P(ImgProc, ImagePyramid_getLayer, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - ////////////////////////////////////////////////////////////////////// // HoughLines -IMPLEMENT_PARAM_CLASS(DoSort, bool) +DEF_PARAM_TEST(Sz_DoSort, cv::Size, bool); -GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort) +PERF_TEST_P(Sz_DoSort, ImgProc_HoughLines, Combine(GPU_TYPICAL_MAT_SIZES, Bool())) { declare.time(30.0); - const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - const cv::Size size = GET_PARAM(1); - const bool doSort = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const bool doSort = GET_PARAM(1); const float rho = 1.0f; const float theta = CV_PI / 180.0f; @@ -1365,6 +1201,7 @@ GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort) cv::gpu::GpuMat d_lines; cv::gpu::GpuMat d_accum; cv::gpu::GpuMat d_buf; + cv::gpu::HoughLines(d_src, d_lines, d_accum, d_buf, rho, theta, threshold, doSort); TEST_CYCLE() @@ -1373,9 +1210,4 @@ GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort) } } -INSTANTIATE_TEST_CASE_P(ImgProc, HoughLines, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DoSort(false), DoSort(true)))); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_labeling.cpp b/modules/gpu/perf/perf_labeling.cpp index 2c537ebbe..86d67ff93 100644 --- a/modules/gpu/perf/perf_labeling.cpp +++ b/modules/gpu/perf/perf_labeling.cpp @@ -41,14 +41,16 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; -GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size) +namespace { + +DEF_PARAM_TEST_1(Image, string); + +PERF_TEST_P(Image, Labeling_ConnectedComponents, Values("gpu/labeling/aloe-disp.png")) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat image = readImage("gpu/labeling/aloe-disp.png", cv::IMREAD_GRAYSCALE); + cv::Mat image = readImage(GetParam(), cv::IMREAD_GRAYSCALE); // cv::threshold(image, image, 150, 255, CV_THRESH_BINARY); @@ -70,6 +72,4 @@ GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size) } } -INSTANTIATE_TEST_CASE_P(Labeling, ConnectedComponents, testing::Combine(ALL_DEVICES, testing::Values(cv::Size(261, 262)))); - -#endif \ No newline at end of file +} // namespace diff --git a/modules/gpu/perf/perf_main.cpp b/modules/gpu/perf/perf_main.cpp index 0cd400277..988c95ae0 100644 --- a/modules/gpu/perf/perf_main.cpp +++ b/modules/gpu/perf/perf_main.cpp @@ -2,11 +2,98 @@ #ifdef HAVE_CUDA +using namespace std; +using namespace cv; +using namespace cv::gpu; +using namespace cvtest; +using namespace testing; + +void printInfo() +{ +#if defined _WIN32 +# if defined _WIN64 + puts("OS: Windows x64"); +# else + puts("OS: Windows x32"); +# endif +#elif defined linux +# if defined _LP64 + puts("OS: Linux x64"); +# else + puts("OS: Linux x32"); +# endif +#elif defined __APPLE__ +# if defined _LP64 + puts("OS: Apple x64"); +# else + puts("OS: Apple x32"); +# endif +#endif + + int driver; + cudaDriverGetVersion(&driver); + + printf("CUDA Driver version: %d\n", driver); + printf("CUDA Runtime version: %d\n", CUDART_VERSION); + + puts("GPU module was compiled for the following GPU archs:"); + printf(" BIN: %s\n", CUDA_ARCH_BIN); + printf(" PTX: %s\n\n", CUDA_ARCH_PTX); + + int deviceCount = getCudaEnabledDeviceCount(); + printf("CUDA device count: %d\n\n", deviceCount); + + for (int i = 0; i < deviceCount; ++i) + { + DeviceInfo info(i); + + printf("Device %d:\n", i); + printf(" Name: %s\n", info.name().c_str()); + printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion()); + printf(" Multi Processor Count: %d\n", info.multiProcessorCount()); + printf(" Total memory: %d Mb\n", static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0)); + printf(" Free memory: %d Mb\n", static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0)); + if (!info.isCompatible()) + puts(" !!! This device is NOT compatible with current GPU module build\n"); + printf("\n"); + } +} + int main(int argc, char **argv) { + CommandLineParser parser(argc, (const char**)argv, + "{ print_info_only | print_info_only | false | Print information about system and exit }" + "{ device | device | 0 | Device on which tests will be executed }"); + + printInfo(); + + if (parser.get("print_info_only")) + return 0; + + int device = parser.get("device"); + + if (device < 0 || device >= getCudaEnabledDeviceCount()) + { + cerr << "Incorrect device number - " << device << endl; + return -1; + } + + DeviceInfo info(device); + if (!info.isCompatible()) + { + cerr << "Device " << device << " [" << info.name() << "] is NOT compatible with current GPU module build" << endl; + return -1; + } + + std::cout << "Run tests on device " << device << '\n' << std::endl; + + setDevice(device); + testing::InitGoogleTest(&argc, argv); perf::TestBase::Init(argc, argv); return RUN_ALL_TESTS(); + + return 0; } #else diff --git a/modules/gpu/perf/perf_matop.cpp b/modules/gpu/perf/perf_matop.cpp index 5cc24402c..c014b19da 100644 --- a/modules/gpu/perf/perf_matop.cpp +++ b/modules/gpu/perf/perf_matop.cpp @@ -1,141 +1,115 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////////////////////// // SetTo -GPU_PERF_TEST(SetTo, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::gpu::GpuMat src(size, type); cv::Scalar val(1, 2, 3, 4); - src.setTo(val); + cv::gpu::GpuMat d_src(size, type); + + d_src.setTo(val); TEST_CYCLE() { - src.setTo(val); + d_src.setTo(val); } } -INSTANTIATE_TEST_CASE_P(MatOp, SetTo, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - ////////////////////////////////////////////////////////////////////// // SetToMasked -GPU_PERF_TEST(SetToMasked, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat mask_host(size, CV_8UC1); - fill(mask_host, 0, 2); + cv::Mat mask(size, CV_8UC1); + fillRandom(mask, 0, 2); - cv::gpu::GpuMat src(src_host); cv::Scalar val(1, 2, 3, 4); - cv::gpu::GpuMat mask(mask_host); - src.setTo(val, mask); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_mask(mask); + + d_src.setTo(val, d_mask); TEST_CYCLE() { - src.setTo(val, mask); + d_src.setTo(val, d_mask); } } -INSTANTIATE_TEST_CASE_P(MatOp, SetToMasked, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - ////////////////////////////////////////////////////////////////////// // CopyToMasked -GPU_PERF_TEST(CopyToMasked, cv::gpu::DeviceInfo, cv::Size, MatType) +PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth = GET_PARAM(1); + int channels = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); + int type = CV_MAKE_TYPE(depth, channels); - cv::Mat src_host(size, type); - fill(src_host, 0, 255); + cv::Mat src(size, type); + fillRandom(src); - cv::Mat mask_host(size, CV_8UC1); - fill(mask_host, 0, 2); + cv::Mat mask(size, CV_8UC1); + fillRandom(mask, 0, 2); - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat mask(mask_host); - cv::gpu::GpuMat dst; + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_mask(mask); + cv::gpu::GpuMat d_dst; - src.copyTo(dst, mask); + d_src.copyTo(d_dst, d_mask); TEST_CYCLE() { - src.copyTo(dst, mask); + d_src.copyTo(d_dst, d_mask); } } -INSTANTIATE_TEST_CASE_P(MatOp, CopyToMasked, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - ////////////////////////////////////////////////////////////////////// // ConvertTo -GPU_PERF_TEST(ConvertTo, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth) +DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth); + +PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Size size = GET_PARAM(0); + int depth1 = GET_PARAM(1); + int depth2 = GET_PARAM(2); - cv::Size size = GET_PARAM(1); - int depth1 = GET_PARAM(2); - int depth2 = GET_PARAM(3); + cv::Mat src(size, depth1); + fillRandom(src); - cv::Mat src_host(size, depth1); - fill(src_host, 0, 255); + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat src(src_host); - cv::gpu::GpuMat dst; - - src.convertTo(dst, depth2, 0.5, 1.0); + d_src.convertTo(d_dst, depth2, 0.5, 1.0); TEST_CYCLE() { - src.convertTo(dst, depth2, 0.5, 1.0); + d_src.convertTo(d_dst, depth2, 0.5, 1.0); } } -INSTANTIATE_TEST_CASE_P(MatOp, ConvertTo, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)), - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)))); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_objdetect.cpp b/modules/gpu/perf/perf_objdetect.cpp index c376586c9..9c1f7919f 100644 --- a/modules/gpu/perf/perf_objdetect.cpp +++ b/modules/gpu/perf/perf_objdetect.cpp @@ -1,85 +1,84 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { /////////////////////////////////////////////////////////////// // HOG -GPU_PERF_TEST_1(HOG, cv::gpu::DeviceInfo) +DEF_PARAM_TEST_1(Image, string); + +PERF_TEST_P(Image, ObjDetect_HOG, Values("gpu/hog/road.png")) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/hog/road.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); - - cv::gpu::GpuMat img(img_host); std::vector found_locations; - cv::gpu::HOGDescriptor hog; - hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); + cv::gpu::GpuMat d_img(img); - hog.detectMultiScale(img, found_locations); + cv::gpu::HOGDescriptor d_hog; + d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); + + d_hog.detectMultiScale(d_img, found_locations); TEST_CYCLE() { - hog.detectMultiScale(img, found_locations); + d_hog.detectMultiScale(d_img, found_locations); } } -INSTANTIATE_TEST_CASE_P(ObjDetect, HOG, ALL_DEVICES); - /////////////////////////////////////////////////////////////// // HaarClassifier -GPU_PERF_TEST_1(HaarClassifier, cv::gpu::DeviceInfo) +typedef pair pair_string; +DEF_PARAM_TEST_1(ImageAndCascade, pair_string); + +PERF_TEST_P(ImageAndCascade, ObjDetect_HaarClassifier, + Values(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/perf/haarcascade_frontalface_alt.xml"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); + cv::gpu::CascadeClassifier_GPU d_cascade; - cv::gpu::CascadeClassifier_GPU cascade; + ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); - ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml"))); + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_objects_buffer; - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat objects_buffer; - - cascade.detectMultiScale(img, objects_buffer); + d_cascade.detectMultiScale(d_img, d_objects_buffer); TEST_CYCLE() { - cascade.detectMultiScale(img, objects_buffer); + d_cascade.detectMultiScale(d_img, d_objects_buffer); } } -INSTANTIATE_TEST_CASE_P(ObjDetect, HaarClassifier, ALL_DEVICES); +/////////////////////////////////////////////////////////////// +// LBP cascade -//===================== LBP cascade ==========================// -GPU_PERF_TEST_1(LBPClassifier, cv::gpu::DeviceInfo) +PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier, + Values(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/lbpcascade/lbpcascade_frontalface.xml"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); - cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_host.empty()); + cv::gpu::CascadeClassifier_GPU d_cascade; + ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_gpu_rects; - cv::gpu::GpuMat img(img_host); - cv::gpu::GpuMat gpu_rects; - cv::gpu::CascadeClassifier_GPU cascade; - ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml"))); + d_cascade.detectMultiScale(d_img, d_gpu_rects); - cascade.detectMultiScale(img, gpu_rects); TEST_CYCLE() { - cascade.detectMultiScale(img, gpu_rects); + d_cascade.detectMultiScale(d_img, d_gpu_rects); } } -INSTANTIATE_TEST_CASE_P(ObjDetect, LBPClassifier, ALL_DEVICES); - -#endif +} // namespace diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp index 19608bde1..be3f234a3 100644 --- a/modules/gpu/perf/perf_precomp.hpp +++ b/modules/gpu/perf/perf_precomp.hpp @@ -11,6 +11,10 @@ #include "cvconfig.h" +#ifdef HAVE_CUDA +#include +#endif + #include "opencv2/ts/ts.hpp" #include "opencv2/ts/ts_perf.hpp" @@ -18,6 +22,10 @@ #include "opencv2/highgui/highgui.hpp" #include "opencv2/gpu/gpu.hpp" #include "opencv2/calib3d/calib3d.hpp" +#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/video/video.hpp" +#include "opencv2/nonfree/nonfree.hpp" +#include "opencv2/legacy/legacy.hpp" #include "perf_utility.hpp" diff --git a/modules/gpu/perf/perf_utility.cpp b/modules/gpu/perf/perf_utility.cpp index bf6bdfe73..42862f49d 100644 --- a/modules/gpu/perf/perf_utility.cpp +++ b/modules/gpu/perf/perf_utility.cpp @@ -4,12 +4,17 @@ using namespace std; using namespace cv; using namespace cv::gpu; -void fill(Mat& m, double a, double b) +void fillRandom(Mat& m, double a, double b) { RNG rng(123456789); rng.fill(m, RNG::UNIFORM, Scalar::all(a), Scalar::all(b)); } +Mat readImage(const string& fileName, int flags) +{ + return imread(perf::TestBase::getDataPath(fileName), flags); +} + void PrintTo(const CvtColorInfo& info, ostream* os) { static const char* str[] = @@ -184,37 +189,3 @@ void PrintTo(const CvtColorInfo& info, ostream* os) *os << str[info.code]; } - -void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os) -{ - *os << info.name(); -} - -Mat readImage(const string& fileName, int flags) -{ - return imread(perf::TestBase::getDataPath(fileName), flags); -} - -const vector& devices() -{ - static vector devs; - static bool first = true; - - if (first) - { - int deviceCount = getCudaEnabledDeviceCount(); - - devs.reserve(deviceCount); - - for (int i = 0; i < deviceCount; ++i) - { - DeviceInfo info(i); - if (info.isCompatible()) - devs.push_back(info); - } - - first = false; - } - - return devs; -} diff --git a/modules/gpu/perf/perf_utility.hpp b/modules/gpu/perf/perf_utility.hpp index 8693cfc3c..b717030ff 100644 --- a/modules/gpu/perf/perf_utility.hpp +++ b/modules/gpu/perf/perf_utility.hpp @@ -1,13 +1,21 @@ #ifndef __OPENCV_PERF_GPU_UTILITY_HPP__ #define __OPENCV_PERF_GPU_UTILITY_HPP__ -void fill(cv::Mat& m, double a, double b); +#include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" +#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/ts/ts_perf.hpp" + +void fillRandom(cv::Mat& m, double a = 0.0, double b = 255.0); +cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR); using perf::MatType; using perf::MatDepth; CV_ENUM(BorderMode, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP) - CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA) +#define ALL_BORDER_MODES testing::ValuesIn(BorderMode::all()) +CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA) +#define ALL_INTERPOLATIONS testing::ValuesIn(Interpolation::all()) CV_ENUM(NormType, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_HAMMING) struct CvtColorInfo @@ -18,60 +26,18 @@ struct CvtColorInfo explicit CvtColorInfo(int scn_=0, int dcn_=0, int code_=0) : scn(scn_), dcn(dcn_), code(code_) {} }; - void PrintTo(const CvtColorInfo& info, std::ostream* os); -#define IMPLEMENT_PARAM_CLASS(name, type) \ - class name \ - { \ - public: \ - name ( type arg = type ()) : val_(arg) {} \ - operator type () const {return val_;} \ - private: \ - type val_; \ - }; \ - inline void PrintTo( name param, std::ostream* os) \ - { \ - *os << #name << " = " << testing::PrintToString(static_cast< type >(param)); \ - } - -IMPLEMENT_PARAM_CLASS(Channels, int) - -namespace cv { namespace gpu -{ - void PrintTo(const cv::gpu::DeviceInfo& info, std::ostream* os); -}} - -#define GPU_PERF_TEST(name, ...) \ - struct name : perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > \ - { \ - public: \ - name() {} \ - protected: \ - void PerfTestBody(); \ - }; \ - TEST_P(name, perf){ RunPerfTestBody(); } \ - void name :: PerfTestBody() - -#define GPU_PERF_TEST_1(name, param_type) \ - struct name : perf::TestBaseWithParam< param_type > \ - { \ - public: \ - name() {} \ - protected: \ - void PerfTestBody(); \ - }; \ - TEST_P(name, perf){ RunPerfTestBody(); } \ - void name :: PerfTestBody() - -#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz1080p, cv::Size(1800, 1500)) - -cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR); - -const std::vector& devices(); - -#define ALL_DEVICES testing::ValuesIn(devices()) - #define GET_PARAM(k) std::tr1::get< k >(GetParam()) +#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 + +DEF_PARAM_TEST_1(Sz, cv::Size); +typedef perf::Size_MatType Sz_Type; +DEF_PARAM_TEST(Sz_Depth, cv::Size, MatDepth); +DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, int); + +#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz720p, perf::sz1080p) + #endif // __OPENCV_PERF_GPU_UTILITY_HPP__ diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index 6e577a4a4..a5a1e4da5 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -1,305 +1,277 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA +using namespace std; +using namespace testing; + +namespace { ////////////////////////////////////////////////////// // BroxOpticalFlow -GPU_PERF_TEST_1(BroxOpticalFlow, cv::gpu::DeviceInfo) +typedef pair pair_string; + +DEF_PARAM_TEST_1(ImagePair, pair_string); + +PERF_TEST_P(ImagePair, Video_BroxOpticalFlow, Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + declare.time(10); - cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0_host.empty()); + cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame0.empty()); - cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1_host.empty()); + cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame1.empty()); - frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); - frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); + frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); + frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_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(frame0, frame1, u, v); - - declare.time(10); + d_flow(d_frame0, d_frame1, d_u, d_v); TEST_CYCLE() { - d_flow(frame0, frame1, u, v); + d_flow(d_frame0, d_frame1, d_u, d_v); } } -INSTANTIATE_TEST_CASE_P(Video, BroxOpticalFlow, ALL_DEVICES); - ////////////////////////////////////////////////////// // InterpolateFrames -GPU_PERF_TEST_1(InterpolateFrames, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Video_InterpolateFrames, Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame0.empty()); - cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0_host.empty()); + cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame1.empty()); - cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1_host.empty()); + frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); + frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); - frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); - - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat fu, fv; - cv::gpu::GpuMat bu, bv; + cv::gpu::GpuMat d_frame0(frame0); + 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(frame0, frame1, fu, fv); - d_flow(frame1, frame0, bu, bv); + 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 buf; + cv::gpu::GpuMat d_newFrame; + cv::gpu::GpuMat d_buf; - cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf); + cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); TEST_CYCLE() { - cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf); + cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); } } -INSTANTIATE_TEST_CASE_P(Video, InterpolateFrames, ALL_DEVICES); - ////////////////////////////////////////////////////// // CreateOpticalFlowNeedleMap -GPU_PERF_TEST_1(CreateOpticalFlowNeedleMap, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap, Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); + cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame0.empty()); - cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0_host.empty()); + cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame1.empty()); - cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1_host.empty()); + frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); + frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); - frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); - - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat u, v; + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_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(frame0, frame1, u, v); + d_flow(d_frame0, d_frame1, d_u, d_v); - cv::gpu::GpuMat vertex, colors; + cv::gpu::GpuMat d_vertex, d_colors; - cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors); + cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); TEST_CYCLE() { - cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors); + cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); } } -INSTANTIATE_TEST_CASE_P(Video, CreateOpticalFlowNeedleMap, ALL_DEVICES); - ////////////////////////////////////////////////////// // GoodFeaturesToTrack -IMPLEMENT_PARAM_CLASS(MinDistance, double) +DEF_PARAM_TEST(Image_MinDistance, string, double); -GPU_PERF_TEST(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) +PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack, Combine(Values("gpu/perf/aloe.jpg"), Values(0.0, 3.0))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - + string fileName = GET_PARAM(0); double minDistance = GET_PARAM(1); - cv::Mat image_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image_host.empty()); + cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(image.empty()); - cv::gpu::GoodFeaturesToTrackDetector_GPU detector(8000, 0.01, minDistance); + cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance); - cv::gpu::GpuMat image(image_host); - cv::gpu::GpuMat pts; + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_pts; - detector(image, pts); + d_detector(d_image, d_pts); TEST_CYCLE() { - detector(image, pts); + d_detector(d_image, d_pts); } } -INSTANTIATE_TEST_CASE_P(Video, GoodFeaturesToTrack, testing::Combine( - ALL_DEVICES, - testing::Values(MinDistance(0.0), MinDistance(3.0)))); - ////////////////////////////////////////////////////// // PyrLKOpticalFlowSparse -IMPLEMENT_PARAM_CLASS(GraySource, bool) -IMPLEMENT_PARAM_CLASS(Points, int) -IMPLEMENT_PARAM_CLASS(WinSize, int) -IMPLEMENT_PARAM_CLASS(Levels, int) -IMPLEMENT_PARAM_CLASS(Iters, int) +DEF_PARAM_TEST(ImagePair_Gray_NPts_WinSz_Levels_Iters, pair_string, bool, int, int, int, int); -GPU_PERF_TEST(PyrLKOpticalFlowSparse, cv::gpu::DeviceInfo, GraySource, Points, WinSize, Levels, Iters) +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(1000, 2000, 4000, 8000), + Values(9, 13, 17, 21), + Values(1, 2, 3), + Values(1, 10, 30))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - + pair_string imagePair = GET_PARAM(0); bool useGray = GET_PARAM(1); int points = GET_PARAM(2); int winSize = GET_PARAM(3); int levels = GET_PARAM(4); int iters = GET_PARAM(5); - cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - ASSERT_FALSE(frame0_host.empty()); + cv::Mat frame0 = readImage(imagePair.first, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); + ASSERT_FALSE(frame0.empty()); - cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - ASSERT_FALSE(frame1_host.empty()); + 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_host; + gray_frame = frame0; else - cv::cvtColor(frame0_host, gray_frame, cv::COLOR_BGR2GRAY); + cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY); - cv::gpu::GpuMat pts; + cv::gpu::GpuMat d_pts; - cv::gpu::GoodFeaturesToTrackDetector_GPU detector(points, 0.01, 0.0); - detector(cv::gpu::GpuMat(gray_frame), pts); + cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(points, 0.01, 0.0); + d_detector(cv::gpu::GpuMat(gray_frame), d_pts); - cv::gpu::PyrLKOpticalFlow pyrLK; - pyrLK.winSize = cv::Size(winSize, winSize); - pyrLK.maxLevel = levels - 1; - pyrLK.iters = iters; + cv::gpu::PyrLKOpticalFlow d_pyrLK; + d_pyrLK.winSize = cv::Size(winSize, winSize); + d_pyrLK.maxLevel = levels - 1; + d_pyrLK.iters = iters; - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat nextPts; - cv::gpu::GpuMat status; + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_nextPts; + cv::gpu::GpuMat d_status; - pyrLK.sparse(frame0, frame1, pts, nextPts, status); + d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); TEST_CYCLE() { - pyrLK.sparse(frame0, frame1, pts, nextPts, status); + d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); } } -INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowSparse, testing::Combine( - ALL_DEVICES, - testing::Values(GraySource(true), GraySource(false)), - testing::Values(Points(1000), Points(2000), Points(4000), Points(8000)), - testing::Values(WinSize(9), WinSize(13), WinSize(17), WinSize(21)), - testing::Values(Levels(1), Levels(2), Levels(3)), - testing::Values(Iters(1), Iters(10), Iters(30)))); - ////////////////////////////////////////////////////// // PyrLKOpticalFlowDense -GPU_PERF_TEST(PyrLKOpticalFlowDense, cv::gpu::DeviceInfo, WinSize, Levels, Iters) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); +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, 2, 3), + Values(1, 10))) +{ + declare.time(30); + + pair_string imagePair = GET_PARAM(0); int winSize = GET_PARAM(1); int levels = GET_PARAM(2); int iters = GET_PARAM(3); - cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0_host.empty()); + cv::Mat frame0 = readImage(imagePair.first, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame0.empty()); - cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1_host.empty()); + cv::Mat frame1 = readImage(imagePair.second, cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(frame1.empty()); - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_v; - cv::gpu::PyrLKOpticalFlow pyrLK; + cv::gpu::PyrLKOpticalFlow d_pyrLK; + d_pyrLK.winSize = cv::Size(winSize, winSize); + d_pyrLK.maxLevel = levels - 1; + d_pyrLK.iters = iters; - pyrLK.winSize = cv::Size(winSize, winSize); - pyrLK.maxLevel = levels - 1; - pyrLK.iters = iters; - - pyrLK.dense(frame0, frame1, u, v); - - declare.time(30); + d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); TEST_CYCLE() { - pyrLK.dense(frame0, frame1, u, v); + d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); } } -INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowDense, testing::Combine( - ALL_DEVICES, - testing::Values(WinSize(3), WinSize(5), WinSize(7), WinSize(9), WinSize(13), WinSize(17), WinSize(21)), - testing::Values(Levels(1), Levels(2), Levels(3)), - testing::Values(Iters(1), Iters(10)))); - ////////////////////////////////////////////////////// -// FarnebackOpticalFlowTest +// FarnebackOpticalFlow -GPU_PERF_TEST_1(FarnebackOpticalFlowTest, cv::gpu::DeviceInfo) +PERF_TEST_P(ImagePair, Video_FarnebackOpticalFlow, Values(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png"))) { - cv::gpu::DeviceInfo devInfo = GetParam(); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0_host.empty()); - - cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1_host.empty()); - - cv::gpu::GpuMat frame0(frame0_host); - cv::gpu::GpuMat frame1(frame1_host); - cv::gpu::GpuMat u; - cv::gpu::GpuMat v; - - cv::gpu::FarnebackOpticalFlow farneback; - - farneback(frame0, frame1, u, v); - declare.time(10); + 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()); + + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_v; + + cv::gpu::FarnebackOpticalFlow d_farneback; + + d_farneback(d_frame0, d_frame1, d_u, d_v); + TEST_CYCLE() { - farneback(frame0, frame1, u, v); + d_farneback(d_frame0, d_frame1, d_u, d_v); } } -INSTANTIATE_TEST_CASE_P(Video, FarnebackOpticalFlowTest, ALL_DEVICES); - ////////////////////////////////////////////////////// // FGDStatModel -GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); +DEF_PARAM_TEST_1(Video, string); - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); +PERF_TEST_P(Video, Video_FGDStatModel, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) +{ + declare.time(10); + + string inputFile = perf::TestBase::getDataPath(GetParam()); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -312,8 +284,6 @@ GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string) cv::gpu::FGDStatModel d_model(4); d_model.create(d_frame); - declare.time(10); - for (int i = 0; i < 10; ++i) { cap >> frame; @@ -327,23 +297,16 @@ GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string) } } -INSTANTIATE_TEST_CASE_P(Video, FGDStatModel, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - ////////////////////////////////////////////////////// // MOG -IMPLEMENT_PARAM_CLASS(LearningRate, double) +DEF_PARAM_TEST(Video_Cn_LearningRate, string, int, double); -GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) +PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(0.0, 0.01))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - double learningRate = GET_PARAM(3); + string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + int cn = GET_PARAM(1); + double learningRate = GET_PARAM(2); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -351,8 +314,8 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) cv::Mat frame; cv::gpu::GpuMat d_frame; - cv::gpu::MOG_GPU mog; - cv::gpu::GpuMat foreground; + cv::gpu::MOG_GPU d_mog; + cv::gpu::GpuMat d_foreground; cap >> frame; ASSERT_FALSE(frame.empty()); @@ -369,7 +332,7 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) d_frame.upload(frame); - mog(d_frame, foreground, learningRate); + d_mog(d_frame, d_foreground, learningRate); for (int i = 0; i < 10; ++i) { @@ -389,27 +352,20 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) d_frame.upload(frame); startTimer(); next(); - mog(d_frame, foreground, learningRate); + d_mog(d_frame, d_foreground, learningRate); stopTimer(); } } -INSTANTIATE_TEST_CASE_P(Video, MOG, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)), - testing::Values(LearningRate(0.0), LearningRate(0.01)))); - ////////////////////////////////////////////////////// // MOG2 -GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); +DEF_PARAM_TEST(Video_Cn, string, int); - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); +PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4))) +{ + string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + int cn = GET_PARAM(1); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -417,8 +373,8 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) cv::Mat frame; cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU mog2; - cv::gpu::GpuMat foreground; + cv::gpu::MOG2_GPU d_mog2; + cv::gpu::GpuMat d_foreground; cap >> frame; ASSERT_FALSE(frame.empty()); @@ -435,7 +391,7 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) d_frame.upload(frame); - mog2(d_frame, foreground); + d_mog2(d_frame, d_foreground); for (int i = 0; i < 10; ++i) { @@ -455,23 +411,18 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) d_frame.upload(frame); startTimer(); next(); - mog2(d_frame, foreground); + d_mog2(d_frame, d_foreground); stopTimer(); } } -INSTANTIATE_TEST_CASE_P(Video, MOG2_update, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)))); +////////////////////////////////////////////////////// +// MOG2GetBackgroundImage -GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channels) +PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); + string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + int cn = GET_PARAM(1); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -479,8 +430,8 @@ GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channel cv::Mat frame; cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU mog2; - cv::gpu::GpuMat foreground; + cv::gpu::MOG2_GPU d_mog2; + cv::gpu::GpuMat d_foreground; for (int i = 0; i < 10; ++i) { @@ -499,33 +450,25 @@ GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channel d_frame.upload(frame); - mog2(d_frame, foreground); + d_mog2(d_frame, d_foreground); } - cv::gpu::GpuMat background; - mog2.getBackgroundImage(background); + cv::gpu::GpuMat d_background; + d_mog2.getBackgroundImage(d_background); TEST_CYCLE() { - mog2.getBackgroundImage(background); + d_mog2.getBackgroundImage(d_background); } } -INSTANTIATE_TEST_CASE_P(Video, MOG2_getBackgroundImage, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)))); - ////////////////////////////////////////////////////// // VIBE -GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels) +PERF_TEST_P(Video_Cn, Video_VIBE, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); + string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + int cn = GET_PARAM(1); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -545,10 +488,10 @@ GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels) } cv::gpu::GpuMat d_frame(frame); - cv::gpu::VIBE_GPU vibe; - cv::gpu::GpuMat foreground; + cv::gpu::VIBE_GPU d_vibe; + cv::gpu::GpuMat d_foreground; - vibe(d_frame, foreground); + d_vibe(d_frame, d_foreground); for (int i = 0; i < 10; ++i) { @@ -568,28 +511,21 @@ GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels) d_frame.upload(frame); startTimer(); next(); - vibe(d_frame, foreground); + d_vibe(d_frame, d_foreground); stopTimer(); } } -INSTANTIATE_TEST_CASE_P(Video, VIBE, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)))); - ////////////////////////////////////////////////////// // GMG -IMPLEMENT_PARAM_CLASS(MaxFeatures, int) +DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, int, int); -GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures) +PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(20, 40, 60))) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - int maxFeatures = GET_PARAM(3); + std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); + int cn = GET_PARAM(1); + int maxFeatures = GET_PARAM(2); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); @@ -611,10 +547,10 @@ GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures) cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_fgmask; - cv::gpu::GMG_GPU gmg; - gmg.maxFeatures = maxFeatures; + cv::gpu::GMG_GPU d_gmg; + d_gmg.maxFeatures = maxFeatures; - gmg(d_frame, d_fgmask); + d_gmg(d_frame, d_fgmask); for (int i = 0; i < 150; ++i) { @@ -638,32 +574,21 @@ GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures) d_frame.upload(frame); startTimer(); next(); - gmg(d_frame, d_fgmask); + d_gmg(d_frame, d_fgmask); stopTimer(); } } -INSTANTIATE_TEST_CASE_P(Video, GMG, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)), - testing::Values(MaxFeatures(20), MaxFeatures(40), MaxFeatures(60)))); - ////////////////////////////////////////////////////// // VideoWriter -#ifdef WIN32 - -GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string) +PERF_TEST_P(Video, Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) { + string inputFile = perf::TestBase::getDataPath(GetParam()); + string outputFile = cv::tempfile(".avi"); + const double FPS = 25.0; - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - std::string outputFile = cv::tempfile(".avi"); - cv::VideoCapture reader(inputFile); ASSERT_TRUE( reader.isOpened() ); @@ -690,39 +615,26 @@ GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string) } } -INSTANTIATE_TEST_CASE_P(Video, VideoWriter, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - -#endif // WIN32 - ////////////////////////////////////////////////////// // VideoReader -GPU_PERF_TEST(VideoReader, cv::gpu::DeviceInfo, std::string) +PERF_TEST_P(Video, Video_VideoReader, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) { - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - - cv::gpu::VideoReader_GPU reader(inputFile); - ASSERT_TRUE( reader.isOpened() ); - - cv::gpu::GpuMat frame; - - reader.read(frame); - declare.time(20); + string inputFile = perf::TestBase::getDataPath(GetParam()); + + cv::gpu::VideoReader_GPU d_reader(inputFile); + ASSERT_TRUE( d_reader.isOpened() ); + + cv::gpu::GpuMat d_frame; + + d_reader.read(d_frame); + TEST_CYCLE_N(10) { - reader.read(frame); + d_reader.read(d_frame); } } -INSTANTIATE_TEST_CASE_P(Video, VideoReader, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - -#endif +} // namespace From 362df96cb9670c1757f1aae77541010da6bbe0a4 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 15:16:45 +0400 Subject: [PATCH 03/40] renamed perf_main.cpp to main.cpp --- modules/gpu/perf/{perf_main.cpp => main.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename modules/gpu/perf/{perf_main.cpp => main.cpp} (100%) diff --git a/modules/gpu/perf/perf_main.cpp b/modules/gpu/perf/main.cpp similarity index 100% rename from modules/gpu/perf/perf_main.cpp rename to modules/gpu/perf/main.cpp From 2634dc6cce264af42379961c64c0ac84a9ba0074 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 15:22:29 +0400 Subject: [PATCH 04/40] removed license comments --- modules/gpu/perf/perf_labeling.cpp | 41 ------------------------------ 1 file changed, 41 deletions(-) diff --git a/modules/gpu/perf/perf_labeling.cpp b/modules/gpu/perf/perf_labeling.cpp index 86d67ff93..bd1bcf144 100644 --- a/modules/gpu/perf/perf_labeling.cpp +++ b/modules/gpu/perf/perf_labeling.cpp @@ -1,44 +1,3 @@ -/*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) 2008-2011, 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: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions 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; From 00546f24e006c0454dd138f8faec81891543dabe Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 15:50:35 +0400 Subject: [PATCH 05/40] updated mark_nvidia.py script --- modules/gpu/misc/mark_nvidia.py | 357 +++++++++++++++----------------- 1 file changed, 168 insertions(+), 189 deletions(-) diff --git a/modules/gpu/misc/mark_nvidia.py b/modules/gpu/misc/mark_nvidia.py index fd543e9f5..88070117d 100644 --- a/modules/gpu/misc/mark_nvidia.py +++ b/modules/gpu/misc/mark_nvidia.py @@ -1,255 +1,234 @@ import sys, re spaces = '[\s]*' -symbols = '[\s\w\d,.=:|]*' +symbols = '[\s\w\d,.:|]*' def pattern1(prefix, test): - return re.compile(spaces + 'perf::' + prefix + '/' + test + '::' + '\(' + symbols + '\)' + spaces) + return re.compile(spaces + prefix + '_' + test + '::' + symbols + '::' + '\(' + symbols + '\)' + spaces) -def pattern2(prefix, test, cvtype): - return re.compile(spaces + 'perf::' + prefix + '/' + test + '::' + '\(' + symbols + cvtype + symbols + '\)' + spaces) +def pattern2(prefix, test, param1): + return re.compile(spaces + prefix + '_' + test + '::' + symbols + '::' + '\(' + symbols + param1 + symbols + '\)' + spaces) -def pattern3(prefix, test, cvtype, param1): - return re.compile(spaces + 'perf::' + prefix + '/' + test + '::' + '\(' + symbols + cvtype + symbols + param1 + symbols + '\)' + spaces) +def pattern3(prefix, test, param1, param2): + return re.compile(spaces + prefix + '_' + test + '::' + symbols + '::' + '\(' + symbols + param1 + symbols + param2 + symbols + '\)' + spaces) -def pattern4(prefix, test, cvtype, param1, param2): - return re.compile(spaces + 'perf::' + prefix + '/' + test + '::' + '\(' + symbols + cvtype + symbols + param1 + symbols + param2 + symbols + '\)' + spaces) +def pattern4(prefix, test, param1, param2, param3): + return re.compile(spaces + prefix + '_' + test + '::' + symbols + '::' + '\(' + symbols + param1 + symbols + param2 + symbols + param3 + symbols + '\)' + spaces) + +def pattern5(prefix, test, param1, param2, param3, param5): + return re.compile(spaces + prefix + '_' + test + '::' + symbols + '::' + '\(' + symbols + param1 + symbols + param2 + symbols + param3 + symbols + param4 + symbols + '\)' + spaces) npp_patterns = [ ############################################################## # Core - - # Core/Add_Mat (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Add_Mat', '8U'), - pattern2('Core', 'Add_Mat', '16U'), - pattern2('Core', 'Add_Mat', '32F'), - - # Core/Add_Scalar (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Add_Scalar', '8U'), - pattern2('Core', 'Add_Scalar', '16U'), - pattern2('Core', 'Add_Scalar', '32F'), - - # Core/Subtract_Mat (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Subtract_Mat', '8U'), - pattern2('Core', 'Subtract_Mat', '16U'), - pattern2('Core', 'Subtract_Mat', '32F'), - - # Core/Subtract_Scalar (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Subtract_Scalar', '8U'), - pattern2('Core', 'Subtract_Scalar', '16U'), - pattern2('Core', 'Subtract_Scalar', '32F'), - - # Core/Multiply_Mat (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Multiply_Mat', '8U'), - pattern2('Core', 'Multiply_Mat', '16U'), - pattern2('Core', 'Multiply_Mat', '32F'), - - # Core/Multiply_Scalar (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Multiply_Scalar', '8U'), - pattern2('Core', 'Multiply_Scalar', '16U'), - pattern2('Core', 'Multiply_Scalar', '32F'), - - # Core/Divide_Mat (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Divide_Mat', '8U'), - pattern2('Core', 'Divide_Mat', '16U'), - pattern2('Core', 'Divide_Mat', '32F'), - - # Core/Divide_Scalar (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'Divide_Scalar', '8U'), - pattern2('Core', 'Divide_Scalar', '16U'), - pattern2('Core', 'Divide_Scalar', '32F'), - - # Core/AbsDiff_Mat (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'AbsDiff_Mat', '8U'), - pattern2('Core', 'AbsDiff_Mat', '16U'), - pattern2('Core', 'AbsDiff_Mat', '32F'), - - # Core/AbsDiff_Scalar (CV_8U | CV_16U | CV_32F) - pattern2('Core', 'AbsDiff_Scalar', '8U'), - pattern2('Core', 'AbsDiff_Scalar', '16U'), - pattern2('Core', 'AbsDiff_Scalar', '32F'), - # Core/Abs + # Core_AddMat (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'AddMat', '8U'), + pattern2('Core', 'AddMat', '16U'), + pattern2('Core', 'AddMat', '32F'), + + # Core_AddScalar (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'AddScalar', '8U'), + pattern2('Core', 'AddScalar', '16U'), + pattern2('Core', 'AddScalar', '32F'), + + # Core_SubtractMat (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'SubtractMat', '8U'), + pattern2('Core', 'SubtractMat', '16U'), + pattern2('Core', 'SubtractMat', '32F'), + + # Core_SubtractScalar (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'SubtractScalar', '8U'), + pattern2('Core', 'SubtractScalar', '16U'), + pattern2('Core', 'SubtractScalar', '32F'), + + # Core_MultiplyMat (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'MultiplyMat', '8U'), + pattern2('Core', 'MultiplyMat', '16U'), + pattern2('Core', 'MultiplyMat', '32F'), + + # Core_MultiplyScalar (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'MultiplyScalar', '8U'), + pattern2('Core', 'MultiplyScalar', '16U'), + pattern2('Core', 'MultiplyScalar', '32F'), + + # Core_DivideMat (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'DivideMat', '8U'), + pattern2('Core', 'DivideMat', '16U'), + pattern2('Core', 'DivideMat', '32F'), + + # Core_Divide_Scalar (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'DivideScalar', '8U'), + pattern2('Core', 'DivideScalar', '16U'), + pattern2('Core', 'DivideScalar', '32F'), + + # Core_AbsDiff_Mat (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'AbsDiffMat', '8U'), + pattern2('Core', 'AbsDiffMat', '16U'), + pattern2('Core', 'AbsDiffMat', '32F'), + + # Core_AbsDiffScalar (CV_8U | CV_16U | CV_32F) + pattern2('Core', 'AbsDiffScalar', '8U'), + pattern2('Core', 'AbsDiffScalar', '16U'), + pattern2('Core', 'AbsDiffScalar', '32F'), + + # Core_Abs pattern1('Core', 'Abs'), - # Core/Sqr + # Core_Sqr pattern1('Core', 'Sqr'), - # Core/Sqrt + # Core_Sqrt pattern1('Core', 'Sqrt'), - # Core/Log + # Core_Log pattern1('Core', 'Log'), - # Core/Exp + # Core_Exp pattern1('Core', 'Exp'), - # Core/Bitwise_And_Scalar - pattern1('Core', 'Bitwise_And_Scalar'), + # Core_BitwiseAndScalar + pattern1('Core', 'BitwiseAndScalar'), - # Core/Bitwise_Or_Scalar - pattern1('Core', 'Bitwise_Or_Scalar'), + # Core_BitwiseOrScalar + pattern1('Core', 'BitwiseOrScalar'), - # Core/Bitwise_Xor_Scalar - pattern1('Core', 'Bitwise_Xor_Scalar'), + # Core_BitwiseXorScalar + pattern1('Core', 'BitwiseXorScalar'), - # Core/RShift + # Core_RShift pattern1('Core', 'RShift'), - # Core/LShift + # Core_LShift pattern1('Core', 'LShift'), - # Core/Transpose + # Core_Transpose pattern1('Core', 'Transpose'), - # Core/Flip + # Core_Flip pattern1('Core', 'Flip'), - # Core/LUT_OneChannel - pattern1('Core', 'LUT_OneChannel'), + # Core_LutOneChannel + pattern1('Core', 'LutOneChannel'), - # Core/LUT_MultiChannel - pattern1('Core', 'LUT_MultiChannel'), + # Core_LutMultiChannel + pattern1('Core', 'LutMultiChannel'), - # Core/Magnitude_Complex - pattern1('Core', 'Magnitude_Complex'), + # Core_MagnitudeComplex + pattern1('Core', 'MagnitudeComplex'), - # Core/Magnitude_Sqr_Complex - pattern1('Core', 'Magnitude_Sqr_Complex'), + # Core_MagnitudeSqrComplex + pattern1('Core', 'MagnitudeSqrComplex'), - # Core/MeanStdDev + # Core_MeanStdDev pattern1('Core', 'MeanStdDev'), - # Core/NormDiff + # Core_NormDiff pattern1('Core', 'NormDiff'), - + ############################################################## # Filters - # Filters/Blur + # Filters_Blur pattern1('Filters', 'Blur'), - - # Filters/Erode + + # Filters_Erode pattern1('Filters', 'Erode'), - - # Filters/Dilate + + # Filters_Dilate pattern1('Filters', 'Dilate'), - - # Filters/MorphologyEx + + # Filters_MorphologyEx pattern1('Filters', 'MorphologyEx'), - + ############################################################## # ImgProc - - # ImgProc/Resize (8UC1 | 8UC4, INTER_NEAREST | INTER_LINEAR) - pattern3('ImgProc', 'Resize', '8UC1', 'INTER_NEAREST'), - pattern3('ImgProc', 'Resize', '8UC4', 'INTER_NEAREST'), - pattern3('ImgProc', 'Resize', '8UC1', 'INTER_LINEAR'), - pattern3('ImgProc', 'Resize', '8UC4', 'INTER_LINEAR'), - - # ImgProc/Resize (8UC4, INTER_CUBIC) - pattern3('ImgProc', 'Resize', '8UC4', 'INTER_CUBIC'), - - # ImgProc/WarpAffine (8UC1 | 8UC3 | 8UC4 | 32FC1 | 32FC3 | 32FC4, INTER_NEAREST | INTER_LINEAR | INTER_CUBIC, BORDER_CONSTANT) - pattern4('ImgProc', 'WarpAffine', '8UC1', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC1', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC1', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC3', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC3', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC3', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC4', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC4', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '8UC4', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC1', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC1', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC1', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC3', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC3', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC3', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC4', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC4', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpAffine', '32FC4', 'INTER_CUBIC', 'BORDER_CONSTANT'), - - # ImgProc/WarpPerspective (8UC1 | 8UC3 | 8UC4 | 32FC1 | 32FC3 | 32FC4, INTER_NEAREST | INTER_LINEAR | INTER_CUBIC, BORDER_CONSTANT) - pattern4('ImgProc', 'WarpPerspective', '8UC1', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC1', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC1', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC3', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC3', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC3', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC4', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC4', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '8UC4', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC1', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC1', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC1', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC3', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC3', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC3', 'INTER_CUBIC', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC4', 'INTER_NEAREST', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC4', 'INTER_LINEAR', 'BORDER_CONSTANT'), - pattern4('ImgProc', 'WarpPerspective', '32FC4', 'INTER_CUBIC', 'BORDER_CONSTANT'), - - # ImgProc/CopyMakeBorder (8UC1 | 8UC4 | 32SC1 | 32FC1, BORDER_CONSTANT) - pattern3('ImgProc', 'CopyMakeBorder', '8UC1', 'BORDER_CONSTANT'), - pattern3('ImgProc', 'CopyMakeBorder', '8UC4', 'BORDER_CONSTANT'), - pattern3('ImgProc', 'CopyMakeBorder', '32SC1', 'BORDER_CONSTANT'), - pattern3('ImgProc', 'CopyMakeBorder', '32FC1', 'BORDER_CONSTANT'), - - # ImgProc/Threshold (32F, THRESH_TRUNC) + + # ImgProc_Resize (8U, 1 | 4, INTER_NEAREST | INTER_LINEAR) + pattern4('ImgProc', 'Resize', '8U', '1', 'INTER_NEAREST'), + pattern4('ImgProc', 'Resize', '8U', '4', 'INTER_NEAREST'), + pattern4('ImgProc', 'Resize', '8U', '1', 'INTER_LINEAR'), + pattern4('ImgProc', 'Resize', '8U', '4', 'INTER_LINEAR'), + + # ImgProc_Resize (8U, 4, INTER_CUBIC) + pattern4('ImgProc', 'Resize', '8U', '4', 'INTER_CUBIC'), + + # ImgProc_WarpAffine (8U | 32F, INTER_NEAREST | INTER_LINEAR | INTER_CUBIC, BORDER_CONSTANT) + pattern4('ImgProc', 'WarpAffine', '8U' , 'INTER_NEAREST', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpAffine', '8U' , 'INTER_LINEAR', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpAffine', '8U' , 'INTER_CUBIC', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpAffine', '32F', 'INTER_NEAREST', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpAffine', '32F', 'INTER_LINEAR', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpAffine', '32F', 'INTER_CUBIC', 'BORDER_CONSTANT'), + + # ImgProc_WarpPerspective (8U | 32F, INTER_NEAREST | INTER_LINEAR | INTER_CUBIC, BORDER_CONSTANT) + pattern4('ImgProc', 'WarpPerspective', '8U' , 'INTER_NEAREST', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpPerspective', '8U' , 'INTER_LINEAR', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpPerspective', '8U' , 'INTER_CUBIC', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpPerspective', '32F', 'INTER_NEAREST', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpPerspective', '32F', 'INTER_LINEAR', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'WarpPerspective', '32F', 'INTER_CUBIC', 'BORDER_CONSTANT'), + + # ImgProc_CopyMakeBorder (8UC1 | 8UC4 | 32SC1 | 32FC1, BORDER_CONSTANT) + pattern4('ImgProc', 'CopyMakeBorder', '8U' , '1', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'CopyMakeBorder', '8U' , '4', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'CopyMakeBorder', '32S', '1', 'BORDER_CONSTANT'), + pattern4('ImgProc', 'CopyMakeBorder', '32F', '1', 'BORDER_CONSTANT'), + + # ImgProc_Threshold (32F, THRESH_TRUNC) pattern3('ImgProc', 'Threshold', '32F', 'THRESH_TRUNC'), - # ImgProc/Integral_Sqr - pattern1('ImgProc', 'Integral_Sqr'), + # ImgProc_IntegralSqr + pattern1('ImgProc', 'IntegralSqr'), - # ImgProc/HistEven_OneChannel - pattern1('ImgProc', 'HistEven_OneChannel'), + # ImgProc_HistEven_OneChannel + pattern1('ImgProc', 'HistEvenOneChannel'), - # ImgProc/HistEven_FourChannel - pattern1('ImgProc', 'HistEven_FourChannel'), + # ImgProc_HistEven_FourChannel + pattern1('ImgProc', 'HistEvenFourChannel'), - # ImgProc/Rotate + # ImgProc_Rotate pattern1('ImgProc', 'Rotate'), - # ImgProc/SwapChannels + # ImgProc_SwapChannels pattern1('ImgProc', 'SwapChannels'), - # ImgProc/AlphaComp + # ImgProc_AlphaComp pattern1('ImgProc', 'AlphaComp'), - # ImgProc/ImagePyramid_build - pattern1('ImgProc', 'ImagePyramid_build'), + # ImgProc_ImagePyramidBuild + pattern1('ImgProc', 'ImagePyramidBuild'), + + # ImgProc_ImagePyramid_getLayer + pattern1('ImgProc', 'ImagePyramidGetLayer'), - # ImgProc/ImagePyramid_getLayer - pattern1('ImgProc', 'ImagePyramid_getLayer'), - ############################################################## # MatOp - - # MatOp/SetTo (8UC4 | 16UC1 | 16UC4 | 32FC1 | 32FC4) - pattern2('MatOp', 'SetTo', '8UC4'), - pattern2('MatOp', 'SetTo', '16UC1'), - pattern2('MatOp', 'SetTo', '16UC4'), - pattern2('MatOp', 'SetTo', '32FC1'), - pattern2('MatOp', 'SetTo', '32FC4'), - - # MatOp/SetToMasked (8UC4 | 16UC1 | 16UC4 | 32FC1 | 32FC4) - pattern2('MatOp', 'SetToMasked', '8UC4'), - pattern2('MatOp', 'SetToMasked', '16UC1'), - pattern2('MatOp', 'SetToMasked', '16UC4'), - pattern2('MatOp', 'SetToMasked', '32FC1'), - pattern2('MatOp', 'SetToMasked', '32FC4'), - - # MatOp/CopyToMasked (8UC1 | 8UC3 |8UC4 | 16UC1 | 16UC3 | 16UC4 | 32FC1 | 32FC3 | 32FC4) - pattern2('MatOp', 'CopyToMasked', '8UC1'), - pattern2('MatOp', 'CopyToMasked', '8UC3'), - pattern2('MatOp', 'CopyToMasked', '8UC4'), - pattern2('MatOp', 'CopyToMasked', '16UC1'), - pattern2('MatOp', 'CopyToMasked', '16UC3'), - pattern2('MatOp', 'CopyToMasked', '16UC4'), - pattern2('MatOp', 'CopyToMasked', '32FC1'), - pattern2('MatOp', 'CopyToMasked', '32FC3'), - pattern2('MatOp', 'CopyToMasked', '32FC4'), + + # MatOp_SetTo (8UC4 | 16UC1 | 16UC4 | 32FC1 | 32FC4) + pattern3('MatOp', 'SetTo', '8U' , '4'), + pattern3('MatOp', 'SetTo', '16U', '1'), + pattern3('MatOp', 'SetTo', '16U', '4'), + pattern3('MatOp', 'SetTo', '32F', '1'), + pattern3('MatOp', 'SetTo', '32F', '4'), + + # MatOp_SetToMasked (8UC4 | 16UC1 | 16UC4 | 32FC1 | 32FC4) + pattern3('MatOp', 'SetToMasked', '8U' , '4'), + pattern3('MatOp', 'SetToMasked', '16U', '1'), + pattern3('MatOp', 'SetToMasked', '16U', '4'), + pattern3('MatOp', 'SetToMasked', '32F', '1'), + pattern3('MatOp', 'SetToMasked', '32F', '4'), + + # MatOp_CopyToMasked (8UC1 | 8UC3 |8UC4 | 16UC1 | 16UC3 | 16UC4 | 32FC1 | 32FC3 | 32FC4) + pattern3('MatOp', 'CopyToMasked', '8U' , '1'), + pattern3('MatOp', 'CopyToMasked', '8U' , '3'), + pattern3('MatOp', 'CopyToMasked', '8U' , '4'), + pattern3('MatOp', 'CopyToMasked', '16U', '1'), + pattern3('MatOp', 'CopyToMasked', '16U', '3'), + pattern3('MatOp', 'CopyToMasked', '16U', '4'), + pattern3('MatOp', 'CopyToMasked', '32F', '1'), + pattern3('MatOp', 'CopyToMasked', '32F', '3'), + pattern3('MatOp', 'CopyToMasked', '32F', '4'), ] cublasPattern = pattern1('Core', 'GEMM') @@ -260,7 +239,7 @@ if __name__ == "__main__": inputFile = open(sys.argv[1], 'r') lines = inputFile.readlines() inputFile.close() - + for i in range(len(lines)): if cublasPattern.match(lines[i]): From 93172bab87c2c9bab596b964a16256a2f479b303 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 16:12:32 +0400 Subject: [PATCH 06/40] added --cpu flag (run tests on CPU) --- modules/gpu/perf/main.cpp | 124 +++++++++++++++++------------- modules/gpu/perf/perf_utility.cpp | 2 + modules/gpu/perf/perf_utility.hpp | 2 + 3 files changed, 75 insertions(+), 53 deletions(-) diff --git a/modules/gpu/perf/main.cpp b/modules/gpu/perf/main.cpp index 988c95ae0..865362f88 100644 --- a/modules/gpu/perf/main.cpp +++ b/modules/gpu/perf/main.cpp @@ -1,107 +1,125 @@ #include "perf_precomp.hpp" -#ifdef HAVE_CUDA - using namespace std; using namespace cv; using namespace cv::gpu; using namespace cvtest; using namespace testing; -void printInfo() +void printOsInfo() { #if defined _WIN32 # if defined _WIN64 - puts("OS: Windows x64"); + cout << "OS: Windows x64 \n" << endl; # else - puts("OS: Windows x32"); + cout << "OS: Windows x32 \n" << endl; # endif #elif defined linux # if defined _LP64 - puts("OS: Linux x64"); + cout << "OS: Linux x64 \n" << endl; # else - puts("OS: Linux x32"); + cout << "OS: Linux x32 \n" << endl; # endif #elif defined __APPLE__ # if defined _LP64 - puts("OS: Apple x64"); + cout << "OS: Apple x64 \n" << endl; # else - puts("OS: Apple x32"); + cout << "OS: Apple x32 \n" << endl; # endif #endif +} +void printCudaInfo() +{ +#ifndef HAVE_CUDA + cout << "OpenCV was built without CUDA support \n" << endl; +#else int driver; cudaDriverGetVersion(&driver); - printf("CUDA Driver version: %d\n", driver); - printf("CUDA Runtime version: %d\n", CUDART_VERSION); + cout << "CUDA Driver version: " << driver << '\n'; + cout << "CUDA Runtime version: " << CUDART_VERSION << '\n'; - puts("GPU module was compiled for the following GPU archs:"); - printf(" BIN: %s\n", CUDA_ARCH_BIN); - printf(" PTX: %s\n\n", CUDA_ARCH_PTX); + cout << endl; + + cout << "GPU module was compiled for the following GPU archs:" << endl; + cout << " BIN: " << CUDA_ARCH_BIN << '\n'; + cout << " PTX: " << CUDA_ARCH_PTX << '\n'; + + cout << endl; int deviceCount = getCudaEnabledDeviceCount(); - printf("CUDA device count: %d\n\n", deviceCount); + cout << "CUDA device count: " << deviceCount << '\n'; + + cout << endl; for (int i = 0; i < deviceCount; ++i) { DeviceInfo info(i); - printf("Device %d:\n", i); - printf(" Name: %s\n", info.name().c_str()); - printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion()); - printf(" Multi Processor Count: %d\n", info.multiProcessorCount()); - printf(" Total memory: %d Mb\n", static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0)); - printf(" Free memory: %d Mb\n", static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0)); + cout << "Device [" << i << "] \n"; + cout << "\t Name: " << info.name() << '\n'; + cout << "\t Compute capability: " << info.majorVersion() << '.' << info.minorVersion()<< '\n'; + cout << "\t Multi Processor Count: " << info.multiProcessorCount() << '\n'; + cout << "\t Total memory: " << static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0) << " Mb \n"; + cout << "\t Free memory: " << static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0) << " Mb \n"; if (!info.isCompatible()) - puts(" !!! This device is NOT compatible with current GPU module build\n"); - printf("\n"); + cout << "\t !!! This device is NOT compatible with current GPU module build \n"; + + cout << endl; } +#endif } int main(int argc, char **argv) { - CommandLineParser parser(argc, (const char**)argv, - "{ print_info_only | print_info_only | false | Print information about system and exit }" - "{ device | device | 0 | Device on which tests will be executed }"); + CommandLineParser cmd(argc, argv, + "{ print_info_only | print_info_only | false | Print information about system and exit }" + "{ device | device | 0 | Device on which tests will be executed }" + "{ cpu | cpu | false | Run tests on cpu }" + ); - printInfo(); + printOsInfo(); + printCudaInfo(); - if (parser.get("print_info_only")) + if (cmd.get("print_info_only")) return 0; - int device = parser.get("device"); + int device = cmd.get("device"); + bool cpu = cmd.get("cpu"); +#ifndef HAVE_CUDA + cpu = true; +#endif - if (device < 0 || device >= getCudaEnabledDeviceCount()) + if (cpu) { - cerr << "Incorrect device number - " << device << endl; - return -1; - } + runOnGpu = false; - DeviceInfo info(device); - if (!info.isCompatible()) + cout << "Run tests on CPU \n" << endl; + } + else { - cerr << "Device " << device << " [" << info.name() << "] is NOT compatible with current GPU module build" << endl; - return -1; + runOnGpu = true; + + if (device < 0 || device >= getCudaEnabledDeviceCount()) + { + cerr << "Incorrect device index - " << device << endl; + return -1; + } + + DeviceInfo info(device); + if (!info.isCompatible()) + { + cerr << "Device " << device << " [" << info.name() << "] is NOT compatible with current GPU module build" << endl; + return -1; + } + + setDevice(device); + + cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl; } - std::cout << "Run tests on device " << device << '\n' << std::endl; - - setDevice(device); - testing::InitGoogleTest(&argc, argv); perf::TestBase::Init(argc, argv); return RUN_ALL_TESTS(); - - return 0; } - -#else - -int main() -{ - printf("OpenCV was built without CUDA support\n"); - return 0; -} - -#endif diff --git a/modules/gpu/perf/perf_utility.cpp b/modules/gpu/perf/perf_utility.cpp index 42862f49d..3be162b93 100644 --- a/modules/gpu/perf/perf_utility.cpp +++ b/modules/gpu/perf/perf_utility.cpp @@ -4,6 +4,8 @@ using namespace std; using namespace cv; using namespace cv::gpu; +bool runOnGpu = true; + void fillRandom(Mat& m, double a, double b) { RNG rng(123456789); diff --git a/modules/gpu/perf/perf_utility.hpp b/modules/gpu/perf/perf_utility.hpp index b717030ff..2d21fffb5 100644 --- a/modules/gpu/perf/perf_utility.hpp +++ b/modules/gpu/perf/perf_utility.hpp @@ -6,6 +6,8 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/ts/ts_perf.hpp" +extern bool runOnGpu; + void fillRandom(cv::Mat& m, double a = 0.0, double b = 255.0); cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR); From a507d564a4aaa33cb1fa8bac144a3dacbddbf103 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 17 Aug 2012 17:34:58 +0400 Subject: [PATCH 07/40] merged gpu_perf_cpu into gpu_perf --- modules/gpu/perf/perf_calib3d.cpp | 258 +++- modules/gpu/perf/perf_core.cpp | 1652 +++++++++++++++------ modules/gpu/perf/perf_features2d.cpp | 209 ++- modules/gpu/perf/perf_filters.cpp | 266 +++- modules/gpu/perf/perf_imgproc.cpp | 994 +++++++++---- modules/gpu/perf/perf_labeling.cpp | 134 +- modules/gpu/perf/perf_matop.cpp | 102 +- modules/gpu/perf/perf_objdetect.cpp | 103 +- modules/gpu/perf/perf_video.cpp | 792 ++++++---- modules/gpu/perf_cpu/perf_calib3d.cpp | 136 -- modules/gpu/perf_cpu/perf_core.cpp | 1388 ----------------- modules/gpu/perf_cpu/perf_cpu_precomp.cpp | 1 - modules/gpu/perf_cpu/perf_cpu_precomp.hpp | 32 - modules/gpu/perf_cpu/perf_features2d.cpp | 187 --- modules/gpu/perf_cpu/perf_filters.cpp | 283 ---- modules/gpu/perf_cpu/perf_imgproc.cpp | 771 ---------- modules/gpu/perf_cpu/perf_labeling.cpp | 158 -- modules/gpu/perf_cpu/perf_main.cpp | 20 - modules/gpu/perf_cpu/perf_matop.cpp | 124 -- modules/gpu/perf_cpu/perf_objdetect.cpp | 74 - modules/gpu/perf_cpu/perf_utility.cpp | 220 --- modules/gpu/perf_cpu/perf_utility.hpp | 77 - modules/gpu/perf_cpu/perf_video.cpp | 466 ------ 23 files changed, 3270 insertions(+), 5177 deletions(-) delete mode 100644 modules/gpu/perf_cpu/perf_calib3d.cpp delete mode 100644 modules/gpu/perf_cpu/perf_core.cpp delete mode 100644 modules/gpu/perf_cpu/perf_cpu_precomp.cpp delete mode 100644 modules/gpu/perf_cpu/perf_cpu_precomp.hpp delete mode 100644 modules/gpu/perf_cpu/perf_features2d.cpp delete mode 100644 modules/gpu/perf_cpu/perf_filters.cpp delete mode 100644 modules/gpu/perf_cpu/perf_imgproc.cpp delete mode 100644 modules/gpu/perf_cpu/perf_labeling.cpp delete mode 100644 modules/gpu/perf_cpu/perf_main.cpp delete mode 100644 modules/gpu/perf_cpu/perf_matop.cpp delete mode 100644 modules/gpu/perf_cpu/perf_objdetect.cpp delete mode 100644 modules/gpu/perf_cpu/perf_utility.cpp delete mode 100644 modules/gpu/perf_cpu/perf_utility.hpp delete mode 100644 modules/gpu/perf_cpu/perf_video.cpp diff --git a/modules/gpu/perf/perf_calib3d.cpp b/modules/gpu/perf/perf_calib3d.cpp index 343a4e9fa..f62185e00 100644 --- a/modules/gpu/perf/perf_calib3d.cpp +++ b/modules/gpu/perf/perf_calib3d.cpp @@ -15,22 +15,42 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBM, Values(make_pair("gpu/p { declare.time(5.0); - cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + const cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(imgLeft.empty()); - cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + const cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(imgRight.empty()); - cv::gpu::StereoBM_GPU d_bm(0, 256); - cv::gpu::GpuMat d_imgLeft(imgLeft); - cv::gpu::GpuMat d_imgRight(imgRight); - cv::gpu::GpuMat d_dst; + const int preset = 0; + const int ndisp = 256; - d_bm(d_imgLeft, d_imgRight, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::StereoBM_GPU d_bm(preset, ndisp); + + cv::gpu::GpuMat d_imgLeft(imgLeft); + cv::gpu::GpuMat d_imgRight(imgRight); + cv::gpu::GpuMat d_dst; + d_bm(d_imgLeft, d_imgRight, d_dst); + + TEST_CYCLE() + { + d_bm(d_imgLeft, d_imgRight, d_dst); + } + } + else + { + cv::StereoBM bm(preset, ndisp); + + cv::Mat dst; + + bm(imgLeft, imgRight, dst); + + TEST_CYCLE() + { + bm(imgLeft, imgRight, dst); + } } } @@ -41,22 +61,32 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, Values(make_pair("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png"))) { - cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); + const cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::Mat disp = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); + const cv::Mat disp = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(disp.empty()); - cv::gpu::DisparityBilateralFilter d_filter(128); - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_disp(disp); - cv::gpu::GpuMat d_dst; + const int ndisp = 128; - d_filter(d_disp, d_img, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::DisparityBilateralFilter d_filter(ndisp); + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_disp(disp); + cv::gpu::GpuMat d_dst; + d_filter(d_disp, d_img, d_dst); + + TEST_CYCLE() + { + d_filter(d_disp, d_img, d_dst); + } + } + else + { + FAIL(); } } @@ -117,22 +167,29 @@ DEF_PARAM_TEST_1(Count, int); PERF_TEST_P(Count, Calib3D_TransformPoints, Values(5000, 10000, 20000)) { - int count = GetParam(); + const int count = GetParam(); cv::Mat src(1, count, CV_32FC3); fillRandom(src, -100, 100); - cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); + const cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); + const cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); + + TEST_CYCLE() + { + cv::gpu::transformPoints(d_src, rvec, tvec, d_dst); + } + } + else + { + FAIL(); } } @@ -141,23 +198,37 @@ PERF_TEST_P(Count, Calib3D_TransformPoints, Values(5000, 10000, 20000)) PERF_TEST_P(Count, Calib3D_ProjectPoints, Values(5000, 10000, 20000)) { - int count = GetParam(); + const int count = GetParam(); cv::Mat src(1, count, CV_32FC3); fillRandom(src, -100, 100); - cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1); + const cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); + const cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); + const cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); + + TEST_CYCLE() + { + cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst); + } + } + else + { + cv::Mat dst; + + cv::projectPoints(src, rvec, tvec, camera_mat, cv::noArray(), dst); + + TEST_CYCLE() + { + cv::projectPoints(src, rvec, tvec, camera_mat, cv::noArray(), dst); + } } } @@ -166,9 +237,9 @@ PERF_TEST_P(Count, Calib3D_ProjectPoints, Values(5000, 10000, 20000)) PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000)) { - declare.time(3.0); + declare.time(10.0); - int count = GetParam(); + const int count = GetParam(); cv::Mat object(1, count, CV_32FC3); fillRandom(object, -100, 100); @@ -180,7 +251,7 @@ PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000)) camera_mat.at(2, 0) = 0.f; camera_mat.at(2, 1) = 0.f; - cv::Mat dist_coef(1, 8, CV_32F, cv::Scalar::all(0)); + const cv::Mat dist_coef(1, 8, CV_32F, cv::Scalar::all(0)); std::vector image_vec; cv::Mat rvec_gold(1, 3, CV_32FC1); @@ -194,11 +265,23 @@ PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000)) cv::Mat rvec; cv::Mat tvec; - cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); - - TEST_CYCLE() + if (runOnGpu) { cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); + + TEST_CYCLE() + { + cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); + } + } + else + { + cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); + + TEST_CYCLE() + { + cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); + } } } @@ -207,8 +290,8 @@ PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000)) PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src, 5.0, 30.0); @@ -216,14 +299,28 @@ PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES, cv::Mat Q(4, 4, CV_32FC1); fillRandom(Q, 0.1, 1.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); + + TEST_CYCLE() + { + cv::gpu::reprojectImageTo3D(d_src, d_dst, Q); + } + } + else + { + cv::Mat dst; + + cv::reprojectImageTo3D(src, dst, Q); + + TEST_CYCLE() + { + cv::reprojectImageTo3D(src, dst, Q); + } } } @@ -232,20 +329,27 @@ PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES, PERF_TEST_P(Sz_Depth, Calib3D_DrawColorDisp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S))) { - cv::Size size = GET_PARAM(0); - int type = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int type = GET_PARAM(1); cv::Mat src(size, type); fillRandom(src, 0, 255); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::drawColorDisp(d_src, d_dst, 255); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::drawColorDisp(d_src, d_dst, 255); + + TEST_CYCLE() + { + cv::gpu::drawColorDisp(d_src, d_dst, 255); + } + } + else + { + FAIL(); } } diff --git a/modules/gpu/perf/perf_core.cpp b/modules/gpu/perf/perf_core.cpp index b56713a70..90d0d831c 100644 --- a/modules/gpu/perf/perf_core.cpp +++ b/modules/gpu/perf/perf_core.cpp @@ -12,21 +12,39 @@ namespace { PERF_TEST_P(Sz_Depth_Cn, Core_Merge, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, Values(2, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - std::vector d_src(channels); + std::vector src(channels); for (int i = 0; i < channels; ++i) - d_src[i] = cv::gpu::GpuMat(size, depth, cv::Scalar::all(i)); + src[i] = cv::Mat(size, depth, cv::Scalar::all(i)); - cv::gpu::GpuMat d_dst; - - cv::gpu::merge(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + std::vector d_src(channels); + for (int i = 0; i < channels; ++i) + d_src[i].upload(src[i]); + + cv::gpu::GpuMat d_dst; + cv::gpu::merge(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::merge(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::merge(src, dst); + + TEST_CYCLE() + { + cv::merge(src, dst); + } } } @@ -35,19 +53,35 @@ PERF_TEST_P(Sz_Depth_Cn, Core_Merge, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_D PERF_TEST_P(Sz_Depth_Cn, Core_Split, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, Values(2, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - cv::gpu::GpuMat d_src(size, CV_MAKE_TYPE(depth, channels), cv::Scalar(1, 2, 3, 4)); + cv::Mat src(size, CV_MAKE_TYPE(depth, channels), cv::Scalar(1, 2, 3, 4)); - std::vector d_dst; - - cv::gpu::split(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + + std::vector d_dst; + cv::gpu::split(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::split(d_src, d_dst); + } + } + else + { + std::vector dst; + + cv::split(src, dst); + + TEST_CYCLE() + { + cv::split(src, dst); + } } } @@ -56,8 +90,8 @@ PERF_TEST_P(Sz_Depth_Cn, Core_Split, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_D PERF_TEST_P(Sz_Depth, Core_AddMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -65,15 +99,29 @@ PERF_TEST_P(Sz_Depth, Core_AddMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEP cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::add(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::add(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::add(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::add(src1, src2, dst); + + TEST_CYCLE() + { + cv::add(src1, src2, dst); + } } } @@ -82,22 +130,36 @@ PERF_TEST_P(Sz_Depth, Core_AddMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEP PERF_TEST_P(Sz_Depth, Core_AddScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::add(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::add(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::add(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::add(src, s, dst); + + TEST_CYCLE() + { + cv::add(src, s, dst); + } } } @@ -106,8 +168,8 @@ PERF_TEST_P(Sz_Depth, Core_AddScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_ PERF_TEST_P(Sz_Depth, Core_SubtractMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -115,15 +177,29 @@ PERF_TEST_P(Sz_Depth, Core_SubtractMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MA cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::subtract(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::subtract(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::subtract(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::subtract(src1, src2, dst); + + TEST_CYCLE() + { + cv::subtract(src1, src2, dst); + } } } @@ -132,22 +208,36 @@ PERF_TEST_P(Sz_Depth, Core_SubtractMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MA PERF_TEST_P(Sz_Depth, Core_SubtractScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::subtract(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::subtract(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::subtract(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::subtract(src, s, dst); + + TEST_CYCLE() + { + cv::subtract(src, s, dst); + } } } @@ -156,8 +246,8 @@ PERF_TEST_P(Sz_Depth, Core_SubtractScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM PERF_TEST_P(Sz_Depth, Core_MultiplyMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -165,15 +255,29 @@ PERF_TEST_P(Sz_Depth, Core_MultiplyMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MA cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::multiply(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::multiply(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::multiply(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::multiply(src1, src2, dst); + + TEST_CYCLE() + { + cv::multiply(src1, src2, dst); + } } } @@ -182,22 +286,36 @@ PERF_TEST_P(Sz_Depth, Core_MultiplyMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MA PERF_TEST_P(Sz_Depth, Core_MultiplyScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::multiply(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::multiply(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::multiply(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::multiply(src, s, dst); + + TEST_CYCLE() + { + cv::multiply(src, s, dst); + } } } @@ -206,8 +324,8 @@ PERF_TEST_P(Sz_Depth, Core_MultiplyScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM PERF_TEST_P(Sz_Depth, Core_DivideMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -215,15 +333,29 @@ PERF_TEST_P(Sz_Depth, Core_DivideMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_ cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::divide(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::divide(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::divide(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::divide(src1, src2, dst); + + TEST_CYCLE() + { + cv::divide(src1, src2, dst); + } } } @@ -232,22 +364,36 @@ PERF_TEST_P(Sz_Depth, Core_DivideMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_ PERF_TEST_P(Sz_Depth, Core_DivideScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::divide(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::divide(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::divide(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::divide(src, s, dst); + + TEST_CYCLE() + { + cv::divide(src, s, dst); + } } } @@ -256,22 +402,36 @@ PERF_TEST_P(Sz_Depth, Core_DivideScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_M PERF_TEST_P(Sz_Depth, Core_DivideScalarInv, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); double s = 100.0; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::divide(s, d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::divide(s, d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::divide(s, d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::divide(s, src, dst); + + TEST_CYCLE() + { + cv::divide(s, src, dst); + } } } @@ -280,8 +440,8 @@ PERF_TEST_P(Sz_Depth, Core_DivideScalarInv, Combine(GPU_TYPICAL_MAT_SIZES, ARITH PERF_TEST_P(Sz_Depth, Core_AbsDiffMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -289,15 +449,29 @@ PERF_TEST_P(Sz_Depth, Core_AbsDiffMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::absdiff(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::absdiff(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::absdiff(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::absdiff(src1, src2, dst); + + TEST_CYCLE() + { + cv::absdiff(src1, src2, dst); + } } } @@ -306,22 +480,36 @@ PERF_TEST_P(Sz_Depth, Core_AbsDiffMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT PERF_TEST_P(Sz_Depth, Core_AbsDiffScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::absdiff(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::absdiff(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::absdiff(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::absdiff(src, s, dst); + + TEST_CYCLE() + { + cv::absdiff(src, s, dst); + } } } @@ -330,20 +518,27 @@ PERF_TEST_P(Sz_Depth, Core_AbsDiffScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_ PERF_TEST_P(Sz_Depth, Core_Abs, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_16S, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::abs(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::abs(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::abs(d_src, d_dst); + } + } + else + { + FAIL(); } } @@ -352,20 +547,27 @@ PERF_TEST_P(Sz_Depth, Core_Abs, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_16S, CV PERF_TEST_P(Sz_Depth, Core_Sqr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::sqr(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::sqr(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::sqr(d_src, d_dst); + } + } + else + { + FAIL(); } } @@ -374,20 +576,34 @@ PERF_TEST_P(Sz_Depth, Core_Sqr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_ PERF_TEST_P(Sz_Depth, Core_Sqrt, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::sqrt(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::sqrt(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::sqrt(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::sqrt(src, dst); + + TEST_CYCLE() + { + cv::sqrt(src, dst); + } } } @@ -396,20 +612,34 @@ PERF_TEST_P(Sz_Depth, Core_Sqrt, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV PERF_TEST_P(Sz_Depth, Core_Log, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src, 1.0, 255.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::log(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::log(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::log(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::log(src, dst); + + TEST_CYCLE() + { + cv::log(src, dst); + } } } @@ -418,20 +648,34 @@ PERF_TEST_P(Sz_Depth, Core_Log, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_ PERF_TEST_P(Sz_Depth, Core_Exp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src, 1.0, 10.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::exp(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::exp(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::exp(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::exp(src, dst); + + TEST_CYCLE() + { + cv::exp(src, dst); + } } } @@ -442,21 +686,35 @@ DEF_PARAM_TEST(Sz_Depth_Power, cv::Size, MatDepth, double); PERF_TEST_P(Sz_Depth_Power, Core_Pow, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S, CV_32F), Values(0.3, 2.0, 2.4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - double power = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const double power = GET_PARAM(2); cv::Mat src(size, depth); fillRandom(src, 1.0, 10.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::pow(d_src, power, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::pow(d_src, power, d_dst); + + TEST_CYCLE() + { + cv::gpu::pow(d_src, power, d_dst); + } + } + else + { + cv::Mat dst; + + cv::pow(src, power, dst); + + TEST_CYCLE() + { + cv::pow(src, power, dst); + } } } @@ -470,9 +728,9 @@ DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CmpCode); PERF_TEST_P(Sz_Depth_Code, Core_CompareMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, ALL_CMP_CODES)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int cmp_code = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int cmp_code = GET_PARAM(2); cv::Mat src1(size, depth); fillRandom(src1); @@ -480,15 +738,29 @@ PERF_TEST_P(Sz_Depth_Code, Core_CompareMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITH cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::compare(d_src1, d_src2, d_dst, cmp_code); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::compare(d_src1, d_src2, d_dst, cmp_code); + + TEST_CYCLE() + { + cv::gpu::compare(d_src1, d_src2, d_dst, cmp_code); + } + } + else + { + cv::Mat dst; + + cv::compare(src1, src2, dst, cmp_code); + + TEST_CYCLE() + { + cv::compare(src1, src2, dst, cmp_code); + } } } @@ -497,23 +769,37 @@ PERF_TEST_P(Sz_Depth_Code, Core_CompareMat, Combine(GPU_TYPICAL_MAT_SIZES, ARITH PERF_TEST_P(Sz_Depth_Code, Core_CompareScalar, Combine(GPU_TYPICAL_MAT_SIZES, ARITHM_MAT_DEPTH, ALL_CMP_CODES)) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int cmp_code = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int cmp_code = GET_PARAM(2); cv::Mat src(size, depth); fillRandom(src); cv::Scalar s = cv::Scalar::all(100); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::compare(d_src, s, d_dst, cmp_code); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::compare(d_src, s, d_dst, cmp_code); + + TEST_CYCLE() + { + cv::gpu::compare(d_src, s, d_dst, cmp_code); + } + } + else + { + cv::Mat dst; + + cv::compare(src, s, dst, cmp_code); + + TEST_CYCLE() + { + cv::compare(src, s, dst, cmp_code); + } } } @@ -522,20 +808,34 @@ PERF_TEST_P(Sz_Depth_Code, Core_CompareScalar, Combine(GPU_TYPICAL_MAT_SIZES, AR PERF_TEST_P(Sz_Depth, Core_BitwiseNot, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_not(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_not(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_not(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_not(src, dst); + + TEST_CYCLE() + { + cv::bitwise_not(src, dst); + } } } @@ -544,8 +844,8 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseNot, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_ PERF_TEST_P(Sz_Depth, Core_BitwiseAndMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -553,15 +853,29 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseAndMat, Combine(GPU_TYPICAL_MAT_SIZES, Values( cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_and(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_and(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_and(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_and(src1, src2, dst); + + TEST_CYCLE() + { + cv::bitwise_and(src1, src2, dst); + } } } @@ -570,25 +884,39 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseAndMat, Combine(GPU_TYPICAL_MAT_SIZES, Values( PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseAndScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - int type = CV_MAKE_TYPE(depth, channels); + const int type = CV_MAKE_TYPE(depth, channels); cv::Mat src(size, type); fillRandom(src); cv::Scalar s = cv::Scalar::all(100); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_and(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_and(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_and(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_and(src, s, dst); + + TEST_CYCLE() + { + cv::bitwise_and(src, s, dst); + } } } @@ -597,8 +925,8 @@ PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseAndScalar, Combine(GPU_TYPICAL_MAT_SIZES, V PERF_TEST_P(Sz_Depth, Core_BitwiseOrMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -606,15 +934,29 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseOrMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(C cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_or(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_or(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_or(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_or(src1, src2, dst); + + TEST_CYCLE() + { + cv::bitwise_or(src1, src2, dst); + } } } @@ -623,25 +965,39 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseOrMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(C PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseOrScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - int type = CV_MAKE_TYPE(depth, channels); + const int type = CV_MAKE_TYPE(depth, channels); cv::Mat src(size, type); fillRandom(src); cv::Scalar s = cv::Scalar::all(100); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_or(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_or(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_or(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_or(src, s, dst); + + TEST_CYCLE() + { + cv::bitwise_or(src, s, dst); + } } } @@ -650,8 +1006,8 @@ PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseOrScalar, Combine(GPU_TYPICAL_MAT_SIZES, Va PERF_TEST_P(Sz_Depth, Core_BitwiseXorMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -659,15 +1015,29 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseXorMat, Combine(GPU_TYPICAL_MAT_SIZES, Values( cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_xor(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_xor(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_xor(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_xor(src1, src2, dst); + + TEST_CYCLE() + { + cv::bitwise_xor(src1, src2, dst); + } } } @@ -676,25 +1046,39 @@ PERF_TEST_P(Sz_Depth, Core_BitwiseXorMat, Combine(GPU_TYPICAL_MAT_SIZES, Values( PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseXorScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - int type = CV_MAKE_TYPE(depth, channels); + const int type = CV_MAKE_TYPE(depth, channels); cv::Mat src(size, type); fillRandom(src); cv::Scalar s = cv::Scalar::all(100); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::bitwise_xor(d_src, s, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::bitwise_xor(d_src, s, d_dst); + + TEST_CYCLE() + { + cv::gpu::bitwise_xor(d_src, s, d_dst); + } + } + else + { + cv::Mat dst; + + cv::bitwise_xor(src, s, dst); + + TEST_CYCLE() + { + cv::bitwise_xor(src, s, dst); + } } } @@ -703,25 +1087,32 @@ PERF_TEST_P(Sz_Depth_Cn, Core_BitwiseXorScalar, Combine(GPU_TYPICAL_MAT_SIZES, V PERF_TEST_P(Sz_Depth_Cn, Core_RShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - int type = CV_MAKE_TYPE(depth, channels); + const int type = CV_MAKE_TYPE(depth, channels); cv::Mat src(size, type); fillRandom(src); - cv::Scalar_ val = cv::Scalar_::all(4); + const cv::Scalar_ val = cv::Scalar_::all(4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::rshift(d_src, val, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::rshift(d_src, val, d_dst); + + TEST_CYCLE() + { + cv::gpu::rshift(d_src, val, d_dst); + } + } + else + { + FAIL(); } } @@ -730,25 +1121,32 @@ PERF_TEST_P(Sz_Depth_Cn, Core_RShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8 PERF_TEST_P(Sz_Depth_Cn, Core_LShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32S), Values(1, 3, 4))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); - int channels = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); + const int channels = GET_PARAM(2); - int type = CV_MAKE_TYPE(depth, channels); + const int type = CV_MAKE_TYPE(depth, channels); cv::Mat src(size, type); fillRandom(src); - cv::Scalar_ val = cv::Scalar_::all(4); + const cv::Scalar_ val = cv::Scalar_::all(4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::lshift(d_src, val, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::lshift(d_src, val, d_dst); + + TEST_CYCLE() + { + cv::gpu::lshift(d_src, val, d_dst); + } + } + else + { + FAIL(); } } @@ -757,8 +1155,8 @@ PERF_TEST_P(Sz_Depth_Cn, Core_LShift, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8 PERF_TEST_P(Sz_Depth, Core_MinMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -766,15 +1164,29 @@ PERF_TEST_P(Sz_Depth, Core_MinMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::min(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::min(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::min(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::min(src1, src2, dst); + + TEST_CYCLE() + { + cv::min(src1, src2, dst); + } } } @@ -783,22 +1195,36 @@ PERF_TEST_P(Sz_Depth, Core_MinMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, PERF_TEST_P(Sz_Depth, Core_MinScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - double val = 50.0; + const double val = 50.0; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::min(d_src, val, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::min(d_src, val, d_dst); + + TEST_CYCLE() + { + cv::gpu::min(d_src, val, d_dst); + } + } + else + { + cv::Mat dst; + + cv::min(src, val, dst); + + TEST_CYCLE() + { + cv::min(src, val, dst); + } } } @@ -807,8 +1233,8 @@ PERF_TEST_P(Sz_Depth, Core_MinScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8 PERF_TEST_P(Sz_Depth, Core_MaxMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src1(size, depth); fillRandom(src1); @@ -816,15 +1242,29 @@ PERF_TEST_P(Sz_Depth, Core_MaxMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, cv::Mat src2(size, depth); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::max(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::max(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::max(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::max(src1, src2, dst); + + TEST_CYCLE() + { + cv::max(src1, src2, dst); + } } } @@ -833,22 +1273,36 @@ PERF_TEST_P(Sz_Depth, Core_MaxMat, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, PERF_TEST_P(Sz_Depth, Core_MaxScalar, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F))) { - cv::Size size = GET_PARAM(0); - int depth = GET_PARAM(1); + const cv::Size size = GET_PARAM(0); + const int depth = GET_PARAM(1); cv::Mat src(size, depth); fillRandom(src); - double val = 50.0; + const double val = 50.0; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::max(d_src, val, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::max(d_src, val, d_dst); + + TEST_CYCLE() + { + cv::gpu::max(d_src, val, d_dst); + } + } + else + { + cv::Mat dst; + + cv::max(src, val, dst); + + TEST_CYCLE() + { + cv::max(src, val, dst); + } } } @@ -863,10 +1317,10 @@ PERF_TEST_P(Sz_3Depth, Core_AddWeighted, Combine( Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(CV_8U, CV_16U, CV_32F, CV_64F))) { - cv::Size size = GET_PARAM(0); - int depth1 = GET_PARAM(1); - int depth2 = GET_PARAM(2); - int dst_depth = GET_PARAM(3); + const cv::Size size = GET_PARAM(0); + const int depth1 = GET_PARAM(1); + const int depth2 = GET_PARAM(2); + const int dst_depth = GET_PARAM(3); cv::Mat src1(size, depth1); fillRandom(src1); @@ -874,15 +1328,29 @@ PERF_TEST_P(Sz_3Depth, Core_AddWeighted, Combine( cv::Mat src2(size, depth2); fillRandom(src2); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, d_dst, dst_depth); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, d_dst, dst_depth); + + TEST_CYCLE() + { + cv::gpu::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, d_dst, dst_depth); + } + } + else + { + cv::Mat dst; + + cv::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); + + TEST_CYCLE() + { + cv::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); + } } } @@ -901,9 +1369,9 @@ PERF_TEST_P(Sz_Type_Flags, Core_GEMM, Combine( { declare.time(5.0); - cv::Size size = GET_PARAM(0); - int type = GET_PARAM(1); - int flags = GET_PARAM(2); + const cv::Size size = GET_PARAM(0); + const int type = GET_PARAM(1); + const int flags = GET_PARAM(2); cv::Mat src1(size, type); fillRandom(src1); @@ -914,16 +1382,32 @@ PERF_TEST_P(Sz_Type_Flags, Core_GEMM, Combine( cv::Mat src3(size, type); fillRandom(src3); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_src3(src3); - cv::gpu::GpuMat d_dst; - - cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst, flags); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_src3(src3); + cv::gpu::GpuMat d_dst; + cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst, flags); + + TEST_CYCLE() + { + cv::gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst, flags); + } + } + else + { + cv::Mat dst; + + cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); + + declare.time(50.0); + + TEST_CYCLE() + { + cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); + } } } @@ -940,14 +1424,28 @@ PERF_TEST_P(Sz_Type, Core_Transpose, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::transpose(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::transpose(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::transpose(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::transpose(src, dst); + + TEST_CYCLE() + { + cv::transpose(src, dst); + } } } @@ -976,14 +1474,28 @@ PERF_TEST_P(Sz_Depth_Cn_Code, Core_Flip, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::flip(d_src, d_dst, flipCode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::flip(d_src, d_dst, flipCode); + + TEST_CYCLE() + { + cv::gpu::flip(d_src, d_dst, flipCode); + } + } + else + { + cv::Mat dst; + + cv::flip(src, dst, flipCode); + + TEST_CYCLE() + { + cv::flip(src, dst, flipCode); + } } } @@ -1003,14 +1515,28 @@ PERF_TEST_P(Sz_Type, Core_LutOneChannel, Combine( cv::Mat lut(1, 256, CV_8UC1); fillRandom(lut); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::LUT(d_src, lut, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::LUT(d_src, lut, d_dst); + + TEST_CYCLE() + { + cv::gpu::LUT(d_src, lut, d_dst); + } + } + else + { + cv::Mat dst; + + cv::LUT(src, lut, dst); + + TEST_CYCLE() + { + cv::LUT(src, lut, dst); + } } } @@ -1030,14 +1556,28 @@ PERF_TEST_P(Sz_Type, Core_LutMultiChannel, Combine( cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels())); fillRandom(lut); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::LUT(d_src, lut, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::LUT(d_src, lut, d_dst); + + TEST_CYCLE() + { + cv::gpu::LUT(d_src, lut, d_dst); + } + } + else + { + cv::Mat dst; + + cv::LUT(src, lut, dst); + + TEST_CYCLE() + { + cv::LUT(src, lut, dst); + } } } @@ -1051,14 +1591,31 @@ PERF_TEST_P(Sz, Core_MagnitudeComplex, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_32FC2); fillRandom(src, -100.0, 100.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::magnitude(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::magnitude(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::magnitude(d_src, d_dst); + } + } + else + { + cv::Mat xy[2]; + cv::split(src, xy); + + cv::Mat dst; + + cv::magnitude(xy[0], xy[1], dst); + + TEST_CYCLE() + { + cv::magnitude(xy[0], xy[1], dst); + } } } @@ -1072,14 +1629,21 @@ PERF_TEST_P(Sz, Core_MagnitudeSqrComplex, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_32FC2); fillRandom(src, -100.0, 100.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::magnitudeSqr(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::magnitudeSqr(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::magnitudeSqr(d_src, d_dst); + } + } + else + { + FAIL(); } } @@ -1096,15 +1660,29 @@ PERF_TEST_P(Sz, Core_Magnitude, GPU_TYPICAL_MAT_SIZES) cv::Mat src2(size, CV_32FC1); fillRandom(src2, -100.0, 100.0); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::magnitude(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::magnitude(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::magnitude(d_src1, d_src2, d_dst); + } + } + else + { + cv::Mat dst; + + cv::magnitude(src1, src2, dst); + + TEST_CYCLE() + { + cv::magnitude(src1, src2, dst); + } } } @@ -1121,15 +1699,22 @@ PERF_TEST_P(Sz, Core_MagnitudeSqr, GPU_TYPICAL_MAT_SIZES) cv::Mat src2(size, CV_32FC1); fillRandom(src2, -100.0, 100.0); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::magnitudeSqr(d_src1, d_src2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::magnitudeSqr(d_src1, d_src2, d_dst); + + TEST_CYCLE() + { + cv::gpu::magnitudeSqr(d_src1, d_src2, d_dst); + } + } + else + { + FAIL(); } } @@ -1149,15 +1734,29 @@ PERF_TEST_P(Sz_AngleInDegrees, Core_Phase, Combine(GPU_TYPICAL_MAT_SIZES, Bool() cv::Mat src2(size, CV_32FC1); fillRandom(src2, -100.0, 100.0); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::phase(d_src1, d_src2, d_dst, angleInDegrees); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::phase(d_src1, d_src2, d_dst, angleInDegrees); + + TEST_CYCLE() + { + cv::gpu::phase(d_src1, d_src2, d_dst, angleInDegrees); + } + } + else + { + cv::Mat dst; + + cv::phase(src1, src2, dst, angleInDegrees); + + TEST_CYCLE() + { + cv::phase(src1, src2, dst, angleInDegrees); + } } } @@ -1175,16 +1774,31 @@ PERF_TEST_P(Sz_AngleInDegrees, Core_CartToPolar, Combine(GPU_TYPICAL_MAT_SIZES, cv::Mat src2(size, CV_32FC1); fillRandom(src2, -100.0, 100.0); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_magnitude; - cv::gpu::GpuMat d_angle; - - cv::gpu::cartToPolar(d_src1, d_src2, d_magnitude, d_angle, angleInDegrees); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_magnitude; + cv::gpu::GpuMat d_angle; + cv::gpu::cartToPolar(d_src1, d_src2, d_magnitude, d_angle, angleInDegrees); + + TEST_CYCLE() + { + cv::gpu::cartToPolar(d_src1, d_src2, d_magnitude, d_angle, angleInDegrees); + } + } + else + { + cv::Mat magnitude; + cv::Mat angle; + + cv::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); + + TEST_CYCLE() + { + cv::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); + } } } @@ -1202,16 +1816,31 @@ PERF_TEST_P(Sz_AngleInDegrees, Core_PolarToCart, Combine(GPU_TYPICAL_MAT_SIZES, cv::Mat angle(size, CV_32FC1); fillRandom(angle, 0.0, angleInDegrees ? 360.0 : 2 * CV_PI); - cv::gpu::GpuMat d_magnitude(magnitude); - cv::gpu::GpuMat d_angle(angle); - cv::gpu::GpuMat d_x; - cv::gpu::GpuMat d_y; - - cv::gpu::polarToCart(d_magnitude, d_angle, d_x, d_y, angleInDegrees); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_magnitude(magnitude); + cv::gpu::GpuMat d_angle(angle); + cv::gpu::GpuMat d_x; + cv::gpu::GpuMat d_y; + cv::gpu::polarToCart(d_magnitude, d_angle, d_x, d_y, angleInDegrees); + + TEST_CYCLE() + { + cv::gpu::polarToCart(d_magnitude, d_angle, d_x, d_y, angleInDegrees); + } + } + else + { + cv::Mat x; + cv::Mat y; + + cv::polarToCart(magnitude, angle, x, y, angleInDegrees); + + TEST_CYCLE() + { + cv::polarToCart(magnitude, angle, x, y, angleInDegrees); + } } } @@ -1228,14 +1857,26 @@ PERF_TEST_P(Sz, Core_MeanStdDev, GPU_TYPICAL_MAT_SIZES) cv::Scalar mean; cv::Scalar stddev; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - cv::gpu::meanStdDev(d_src, mean, stddev, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + cv::gpu::meanStdDev(d_src, mean, stddev, d_buf); + + TEST_CYCLE() + { + cv::gpu::meanStdDev(d_src, mean, stddev, d_buf); + } + } + else + { + cv::meanStdDev(src, mean, stddev); + + TEST_CYCLE() + { + cv::meanStdDev(src, mean, stddev); + } } } @@ -1258,14 +1899,26 @@ PERF_TEST_P(Sz_Depth_Norm, Core_Norm, Combine( double dst; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - dst = cv::gpu::norm(d_src, normType, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + dst = cv::gpu::norm(d_src, normType, d_buf); + + TEST_CYCLE() + { + dst = cv::gpu::norm(d_src, normType, d_buf); + } + } + else + { + dst = cv::norm(src, normType); + + TEST_CYCLE() + { + dst = cv::norm(src, normType); + } } } @@ -1289,14 +1942,26 @@ PERF_TEST_P(Sz_Norm, Core_NormDiff, Combine( double dst; - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - - dst = cv::gpu::norm(d_src1, d_src2, normType); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + dst = cv::gpu::norm(d_src1, d_src2, normType); + + TEST_CYCLE() + { + dst = cv::gpu::norm(d_src1, d_src2, normType); + } + } + else + { + dst = cv::norm(src1, src2, normType); + + TEST_CYCLE() + { + dst = cv::norm(src1, src2, normType); + } } } @@ -1319,14 +1984,26 @@ PERF_TEST_P(Sz_Depth_Cn, Core_Sum, Combine( cv::Scalar dst; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - dst = cv::gpu::sum(d_src, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + dst = cv::gpu::sum(d_src, d_buf); + + TEST_CYCLE() + { + dst = cv::gpu::sum(d_src, d_buf); + } + } + else + { + dst = cv::sum(src); + + TEST_CYCLE() + { + dst = cv::sum(src); + } } } @@ -1349,14 +2026,21 @@ PERF_TEST_P(Sz_Depth_Cn, Core_SumAbs, Combine( cv::Scalar dst; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - dst = cv::gpu::absSum(d_src, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + dst = cv::gpu::absSum(d_src, d_buf); + + TEST_CYCLE() + { + dst = cv::gpu::absSum(d_src, d_buf); + } + } + else + { + FAIL(); } } @@ -1379,14 +2063,21 @@ PERF_TEST_P(Sz_Depth_Cn, Core_SumSqr, Combine( cv::Scalar dst; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - dst = cv::gpu::sqrSum(d_src, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + dst = cv::gpu::sqrSum(d_src, d_buf); + + TEST_CYCLE() + { + dst = cv::gpu::sqrSum(d_src, d_buf); + } + } + else + { + FAIL(); } } @@ -1405,14 +2096,21 @@ PERF_TEST_P(Sz_Depth, Core_MinMax, Combine( double minVal, maxVal; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - cv::gpu::minMax(d_src, &minVal, &maxVal, cv::gpu::GpuMat(), d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + cv::gpu::minMax(d_src, &minVal, &maxVal, cv::gpu::GpuMat(), d_buf); + + TEST_CYCLE() + { + cv::gpu::minMax(d_src, &minVal, &maxVal, cv::gpu::GpuMat(), d_buf); + } + } + else + { + FAIL(); } } @@ -1432,14 +2130,26 @@ PERF_TEST_P(Sz_Depth, Core_MinMaxLoc, Combine( double minVal, maxVal; cv::Point minLoc, maxLoc; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_valbuf, d_locbuf; - - cv::gpu::minMaxLoc(d_src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_valbuf, d_locbuf; + cv::gpu::minMaxLoc(d_src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); + + TEST_CYCLE() + { + cv::gpu::minMaxLoc(d_src, &minVal, &maxVal, &minLoc, &maxLoc, cv::gpu::GpuMat(), d_valbuf, d_locbuf); + } + } + else + { + cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc); + + TEST_CYCLE() + { + cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc); + } } } @@ -1458,14 +2168,26 @@ PERF_TEST_P(Sz_Depth, Core_CountNonZero, Combine( int dst; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_buf; - - dst = cv::gpu::countNonZero(d_src, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_buf; + dst = cv::gpu::countNonZero(d_src, d_buf); + + TEST_CYCLE() + { + dst = cv::gpu::countNonZero(d_src, d_buf); + } + } + else + { + dst = cv::countNonZero(src); + + TEST_CYCLE() + { + dst = cv::countNonZero(src); + } } } @@ -1499,14 +2221,28 @@ PERF_TEST_P(Sz_Depth_Cn_Code_Dim, Core_Reduce, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::reduce(d_src, d_dst, dim, reduceOp); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::reduce(d_src, d_dst, dim, reduceOp); + + TEST_CYCLE() + { + cv::gpu::reduce(d_src, d_dst, dim, reduceOp); + } + } + else + { + cv::Mat dst; + + cv::reduce(src, dst, dim, reduceOp); + + TEST_CYCLE() + { + cv::reduce(src, dst, dim, reduceOp); + } } } diff --git a/modules/gpu/perf/perf_features2d.cpp b/modules/gpu/perf/perf_features2d.cpp index ef9612b54..53b98d462 100644 --- a/modules/gpu/perf/perf_features2d.cpp +++ b/modules/gpu/perf/perf_features2d.cpp @@ -12,21 +12,39 @@ DEF_PARAM_TEST_1(Image, string); PERF_TEST_P(Image, Features2D_SURF, Values("gpu/perf/aloe.jpg")) { - declare.time(2.0); + declare.time(50.0); cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::gpu::SURF_GPU d_surf; - - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_keypoints, d_descriptors; - - d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::SURF_GPU d_surf; + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints, d_descriptors; + d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); + + TEST_CYCLE() + { + d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); + } + } + else + { + cv::SURF surf; + + std::vector keypoints; + cv::Mat descriptors; + + surf(img, cv::noArray(), keypoints, descriptors); + + TEST_CYCLE() + { + keypoints.clear(); + surf(img, cv::noArray(), keypoints, descriptors); + } } } @@ -38,16 +56,31 @@ PERF_TEST_P(Image, Features2D_FAST, Values("gpu/perf/aloe.jpg")) cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::gpu::FAST_GPU d_fast(20); - - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_keypoints; - - d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::FAST_GPU d_fast(20); + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints; + d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); + + TEST_CYCLE() + { + d_fast(d_img, cv::gpu::GpuMat(), d_keypoints); + } + } + else + { + std::vector keypoints; + + cv::FAST(img, keypoints, 20); + + TEST_CYCLE() + { + keypoints.clear(); + cv::FAST(img, keypoints, 20); + } } } @@ -59,16 +92,34 @@ PERF_TEST_P(Image, Features2D_ORB, Values("gpu/perf/aloe.jpg")) cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::gpu::ORB_GPU d_orb(4000); - - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_keypoints, d_descriptors; - - d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::ORB_GPU d_orb(4000); + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_keypoints, d_descriptors; + d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); + + TEST_CYCLE() + { + d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors); + } + } + else + { + cv::ORB orb(4000); + + std::vector keypoints; + cv::Mat descriptors; + + orb(img, cv::noArray(), keypoints, descriptors); + + TEST_CYCLE() + { + keypoints.clear(); + orb(img, cv::noArray(), keypoints, descriptors); + } } } @@ -79,7 +130,7 @@ DEF_PARAM_TEST(DescSize_Norm, int, NormType); PERF_TEST_P(DescSize_Norm, Features2D_BFMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) { - declare.time(3.0); + declare.time(20.0); int desc_size = GET_PARAM(0); int normType = GET_PARAM(1); @@ -92,17 +143,33 @@ PERF_TEST_P(DescSize_Norm, Features2D_BFMatch, Combine(Values(64, 128, 256), Val cv::Mat train(3000, desc_size, type); fillRandom(train); - cv::gpu::BFMatcher_GPU d_matcher(normType); - - cv::gpu::GpuMat d_query(query); - cv::gpu::GpuMat d_train(train); - cv::gpu::GpuMat d_trainIdx, d_distance; - - d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::BFMatcher_GPU d_matcher(normType); + + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_distance; + d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); + + TEST_CYCLE() + { + d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance); + } + } + else + { + cv::BFMatcher matcher(normType); + + std::vector matches; + + matcher.match(query, train, matches); + + TEST_CYCLE() + { + matcher.match(query, train, matches); + } } } @@ -116,7 +183,7 @@ PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine( Values(2, 3), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) { - declare.time(3.0); + declare.time(30.0); int desc_size = GET_PARAM(0); int k = GET_PARAM(1); @@ -130,17 +197,33 @@ PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine( cv::Mat train(3000, desc_size, type); fillRandom(train); - cv::gpu::BFMatcher_GPU d_matcher(normType); - - cv::gpu::GpuMat d_query(query); - cv::gpu::GpuMat d_train(train); - cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist; - - d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::BFMatcher_GPU d_matcher(normType); + + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist; + d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); + + TEST_CYCLE() + { + d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k); + } + } + else + { + cv::BFMatcher matcher(normType); + + std::vector< std::vector > matches; + + matcher.knnMatch(query, train, matches, k); + + TEST_CYCLE() + { + matcher.knnMatch(query, train, matches, k); + } } } @@ -149,7 +232,7 @@ PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine( PERF_TEST_P(DescSize_Norm, Features2D_BFRadiusMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))) { - declare.time(3.0); + declare.time(30.0); int desc_size = GET_PARAM(0); int normType = GET_PARAM(1); @@ -162,17 +245,33 @@ PERF_TEST_P(DescSize_Norm, Features2D_BFRadiusMatch, Combine(Values(64, 128, 256 cv::Mat train(3000, desc_size, type); fillRandom(train, 0.0, 1.0); - cv::gpu::BFMatcher_GPU d_matcher(normType); - - cv::gpu::GpuMat d_query(query); - cv::gpu::GpuMat d_train(train); - cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance; - - d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::BFMatcher_GPU d_matcher(normType); + + cv::gpu::GpuMat d_query(query); + cv::gpu::GpuMat d_train(train); + cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance; + d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); + + TEST_CYCLE() + { + d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0); + } + } + else + { + cv::BFMatcher matcher(normType); + + std::vector< std::vector > matches; + + matcher.radiusMatch(query, train, matches, 2.0); + + TEST_CYCLE() + { + matcher.radiusMatch(query, train, matches, 2.0); + } } } diff --git a/modules/gpu/perf/perf_filters.cpp b/modules/gpu/perf/perf_filters.cpp index 71dcd49e2..64ab829f8 100644 --- a/modules/gpu/perf/perf_filters.cpp +++ b/modules/gpu/perf/perf_filters.cpp @@ -12,6 +12,8 @@ DEF_PARAM_TEST(Sz_Type_KernelSz, cv::Size, MatType, int); PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), Values(3, 5, 7))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int ksize = GET_PARAM(2); @@ -19,14 +21,28 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Value cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); + + TEST_CYCLE() + { + cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize)); + } + } + else + { + cv::Mat dst; + + cv::blur(src, dst, cv::Size(ksize, ksize)); + + TEST_CYCLE() + { + cv::blur(src, dst, cv::Size(ksize, ksize)); + } } } @@ -35,6 +51,8 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Value PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int ksize = GET_PARAM(2); @@ -42,15 +60,29 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Valu cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); + + TEST_CYCLE() + { + cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize); + } + } + else + { + cv::Mat dst; + + cv::Sobel(src, dst, -1, 1, 1, ksize); + + TEST_CYCLE() + { + cv::Sobel(src, dst, -1, 1, 1, ksize); + } } } @@ -59,21 +91,37 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Valu PERF_TEST_P(Sz_Type, Filters_Scharr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); + + TEST_CYCLE() + { + cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf); + } + } + else + { + cv::Mat dst; + + cv::Scharr(src, dst, -1, 1, 0); + + TEST_CYCLE() + { + cv::Scharr(src, dst, -1, 1, 0); + } } } @@ -82,6 +130,8 @@ PERF_TEST_P(Sz_Type, Filters_Scharr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int ksize = GET_PARAM(2); @@ -89,15 +139,29 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZE cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); + + TEST_CYCLE() + { + cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5); + } + } + else + { + cv::Mat dst; + + cv::GaussianBlur(src, dst, cv::Size(ksize, ksize), 0.5); + + TEST_CYCLE() + { + cv::GaussianBlur(src, dst, cv::Size(ksize, ksize), 0.5); + } } } @@ -106,6 +170,8 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZE PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int ksize = GET_PARAM(2); @@ -113,14 +179,28 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::Laplacian(d_src, d_dst, -1, ksize); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::Laplacian(d_src, d_dst, -1, ksize); + + TEST_CYCLE() + { + cv::gpu::Laplacian(d_src, d_dst, -1, ksize); + } + } + else + { + cv::Mat dst; + + cv::Laplacian(src, dst, -1, ksize); + + TEST_CYCLE() + { + cv::Laplacian(src, dst, -1, ksize); + } } } @@ -129,6 +209,8 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); @@ -137,15 +219,29 @@ PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::erode(d_src, d_dst, ker, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::erode(d_src, d_dst, ker, d_buf); + + TEST_CYCLE() + { + cv::gpu::erode(d_src, d_dst, ker, d_buf); + } + } + else + { + cv::Mat dst; + + cv::erode(src, dst, ker); + + TEST_CYCLE() + { + cv::erode(src, dst, ker); + } } } @@ -154,6 +250,8 @@ PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC PERF_TEST_P(Sz_Type, Filters_Dilate, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); @@ -162,15 +260,29 @@ PERF_TEST_P(Sz_Type, Filters_Dilate, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::dilate(d_src, d_dst, ker, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::dilate(d_src, d_dst, ker, d_buf); + + TEST_CYCLE() + { + cv::gpu::dilate(d_src, d_dst, ker, d_buf); + } + } + else + { + cv::Mat dst; + + cv::dilate(src, dst, ker); + + TEST_CYCLE() + { + cv::dilate(src, dst, ker); + } } } @@ -184,6 +296,8 @@ DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, MorphOp); PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), ALL_MORPH_OPS)) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int morphOp = GET_PARAM(2); @@ -193,16 +307,30 @@ PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Val cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf1; - cv::gpu::GpuMat d_buf2; - - cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf1; + cv::gpu::GpuMat d_buf2; + cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); + + TEST_CYCLE() + { + cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2); + } + } + else + { + cv::Mat dst; + + cv::morphologyEx(src, dst, morphOp, ker); + + TEST_CYCLE() + { + cv::morphologyEx(src, dst, morphOp, ker); + } } } @@ -211,6 +339,8 @@ PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Val PERF_TEST_P(Sz_Type_KernelSz, Filters_Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(3, 5, 7, 9, 11, 13, 15))) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int type = GET_PARAM(1); int ksize = GET_PARAM(2); @@ -221,14 +351,28 @@ PERF_TEST_P(Sz_Type_KernelSz, Filters_Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, V cv::Mat kernel(ksize, ksize, CV_32FC1); fillRandom(kernel, 0.0, 1.0); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::filter2D(d_src, d_dst, -1, kernel); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::filter2D(d_src, d_dst, -1, kernel); + + TEST_CYCLE() + { + cv::gpu::filter2D(d_src, d_dst, -1, kernel); + } + } + else + { + cv::Mat dst; + + cv::filter2D(src, dst, -1, kernel); + + TEST_CYCLE() + { + cv::filter2D(src, dst, -1, kernel); + } } } diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index a1614a79f..9104892db 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -59,7 +59,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, ImgProc_Remap, Combine( ALL_BORDER_MODES, ALL_REMAP_MODES)) { - declare.time(3.0); + declare.time(20.0); cv::Size size = GET_PARAM(0); int depth = GET_PARAM(1); @@ -78,16 +78,30 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, ImgProc_Remap, Combine( generateMap(xmap, ymap, remapMode); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_xmap(xmap); - cv::gpu::GpuMat d_ymap(ymap); - cv::gpu::GpuMat d_dst; - - cv::gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_xmap(xmap); + cv::gpu::GpuMat d_ymap(ymap); + cv::gpu::GpuMat d_dst; + cv::gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode); + + TEST_CYCLE() + { + cv::gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode); + } + } + else + { + cv::Mat dst; + + cv::remap(src, dst, xmap, ymap, interpolation, borderMode); + + TEST_CYCLE() + { + cv::remap(src, dst, xmap, ymap, interpolation, borderMode); + } } } @@ -103,7 +117,7 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, Combine( ALL_INTERPOLATIONS, Values(0.5, 0.3, 2.0))) { - declare.time(1.0); + declare.time(20.0); cv::Size size = GET_PARAM(0); int depth = GET_PARAM(1); @@ -116,14 +130,28 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); + + TEST_CYCLE() + { + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); + } + } + else + { + cv::Mat dst; + + cv::resize(src, dst, cv::Size(), f, f, interpolation); + + TEST_CYCLE() + { + cv::resize(src, dst, cv::Size(), f, f, interpolation); + } } } @@ -151,14 +179,28 @@ PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); + + TEST_CYCLE() + { + cv::gpu::resize(d_src, d_dst, cv::Size(), f, f, interpolation); + } + } + else + { + cv::Mat dst; + + cv::resize(src, dst, cv::Size(), f, f, interpolation); + + TEST_CYCLE() + { + cv::resize(src, dst, cv::Size(), f, f, interpolation); + } } } @@ -174,6 +216,8 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, Combine( Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), ALL_BORDER_MODES)) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int depth = GET_PARAM(1); int channels = GET_PARAM(2); @@ -190,14 +234,28 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine, Combine( {std::sin(aplha), std::cos(aplha), 0}}; cv::Mat M(2, 3, CV_64F, (void*) mat); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::warpAffine(d_src, d_dst, M, size, interpolation, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::warpAffine(d_src, d_dst, M, size, interpolation, borderMode); + + TEST_CYCLE() + { + cv::gpu::warpAffine(d_src, d_dst, M, size, interpolation, borderMode); + } + } + else + { + cv::Mat dst; + + cv::warpAffine(src, dst, M, size, interpolation, borderMode); + + TEST_CYCLE() + { + cv::warpAffine(src, dst, M, size, interpolation, borderMode); + } } } @@ -211,6 +269,8 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, Combine( Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), ALL_BORDER_MODES)) { + declare.time(20.0); + cv::Size size = GET_PARAM(0); int depth = GET_PARAM(1); int channels = GET_PARAM(2); @@ -228,14 +288,28 @@ PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective, Combine( {0.0, 0.0, 1.0}}; cv::Mat M(3, 3, CV_64F, (void*) mat); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::warpPerspective(d_src, d_dst, M, size, interpolation, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::warpPerspective(d_src, d_dst, M, size, interpolation, borderMode); + + TEST_CYCLE() + { + cv::gpu::warpPerspective(d_src, d_dst, M, size, interpolation, borderMode); + } + } + else + { + cv::Mat dst; + + cv::warpPerspective(src, dst, M, size, interpolation, borderMode); + + TEST_CYCLE() + { + cv::warpPerspective(src, dst, M, size, interpolation, borderMode); + } } } @@ -260,14 +334,28 @@ PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::copyMakeBorder(d_src, d_dst, 5, 5, 5, 5, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::copyMakeBorder(d_src, d_dst, 5, 5, 5, 5, borderMode); + + TEST_CYCLE() + { + cv::gpu::copyMakeBorder(d_src, d_dst, 5, 5, 5, 5, borderMode); + } + } + else + { + cv::Mat dst; + + cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode); + + TEST_CYCLE() + { + cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode); + } } } @@ -291,14 +379,28 @@ PERF_TEST_P(Sz_Depth_Op, ImgProc_Threshold, Combine( cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::threshold(d_src, d_dst, 100.0, 255.0, threshOp); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::threshold(d_src, d_dst, 100.0, 255.0, threshOp); + + TEST_CYCLE() + { + cv::gpu::threshold(d_src, d_dst, 100.0, 255.0, threshOp); + } + } + else + { + cv::Mat dst; + + cv::threshold(src, dst, 100.0, 255.0, threshOp); + + TEST_CYCLE() + { + cv::threshold(src, dst, 100.0, 255.0, threshOp); + } } } @@ -312,15 +414,29 @@ PERF_TEST_P(Sz, ImgProc_Integral, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_8UC1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_buf; - - cv::gpu::integralBuffered(d_src, d_dst, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_buf; + cv::gpu::integralBuffered(d_src, d_dst, d_buf); + + TEST_CYCLE() + { + cv::gpu::integralBuffered(d_src, d_dst, d_buf); + } + } + else + { + cv::Mat dst; + + cv::integral(src, dst); + + TEST_CYCLE() + { + cv::integral(src, dst); + } } } @@ -334,14 +450,21 @@ PERF_TEST_P(Sz, ImgProc_IntegralSqr, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_8UC1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::sqrIntegral(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::sqrIntegral(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::sqrIntegral(d_src, d_dst); + } + } + else + { + FAIL(); } } @@ -356,15 +479,35 @@ PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC1, Combine(GPU_TYPICAL_MAT_SIZES, Values( cv::Mat src(size, depth); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_hist; - cv::gpu::GpuMat d_buf; - - cv::gpu::histEven(d_src, d_hist, d_buf, 30, 0, 180); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; + cv::gpu::histEven(d_src, d_hist, d_buf, 30, 0, 180); + + TEST_CYCLE() + { + cv::gpu::histEven(d_src, d_hist, d_buf, 30, 0, 180); + } + } + else + { + int hbins = 30; + float hranges[] = {0.0f, 180.0f}; + int histSize[] = {hbins}; + const float* ranges[] = {hranges}; + int channels[] = {0}; + + cv::Mat hist; + + cv::calcHist(&src, 1, channels, cv::Mat(), hist, 1, histSize, ranges); + + TEST_CYCLE() + { + cv::calcHist(&src, 1, channels, cv::Mat(), hist, 1, histSize, ranges); + } } } @@ -383,15 +526,22 @@ PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC4, Combine(GPU_TYPICAL_MAT_SIZES, Values( int lowerLevel[] = {0, 0, 0, 0}; int upperLevel[] = {180, 180, 180, 180}; - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_hist[4]; - cv::gpu::GpuMat d_buf; - - cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist[4]; + cv::gpu::GpuMat d_buf; + cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); + + TEST_CYCLE() + { + cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel); + } + } + else + { + FAIL(); } } @@ -405,15 +555,22 @@ PERF_TEST_P(Sz, ImgProc_CalcHist, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_8UC1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_hist; - cv::gpu::GpuMat d_buf; - - cv::gpu::calcHist(d_src, d_hist, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; + cv::gpu::calcHist(d_src, d_hist, d_buf); + + TEST_CYCLE() + { + cv::gpu::calcHist(d_src, d_hist, d_buf); + } + } + else + { + FAIL(); } } @@ -427,16 +584,30 @@ PERF_TEST_P(Sz, ImgProc_EqualizeHist, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_8UC1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_hist; - cv::gpu::GpuMat d_buf; - - cv::gpu::equalizeHist(d_src, d_dst, d_hist, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_hist; + cv::gpu::GpuMat d_buf; + cv::gpu::equalizeHist(d_src, d_dst, d_hist, d_buf); + + TEST_CYCLE() + { + cv::gpu::equalizeHist(d_src, d_dst, d_hist, d_buf); + } + } + else + { + cv::Mat dst; + + cv::equalizeHist(src, dst); + + TEST_CYCLE() + { + cv::equalizeHist(src, dst); + } } } @@ -450,14 +621,21 @@ PERF_TEST_P(Sz, ImgProc_ColumnSum, GPU_TYPICAL_MAT_SIZES) cv::Mat src(size, CV_32FC1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::columnSum(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::columnSum(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::columnSum(d_src, d_dst); + } + } + else + { + FAIL(); } } @@ -478,15 +656,29 @@ PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny, Combine( cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); - cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat d_dst; - cv::gpu::CannyBuf d_buf; - - cv::gpu::Canny(d_image, d_buf, d_dst, 50.0, 100.0, apperture_size, useL2gradient); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_dst; + cv::gpu::CannyBuf d_buf; + cv::gpu::Canny(d_image, d_buf, d_dst, 50.0, 100.0, apperture_size, useL2gradient); + + TEST_CYCLE() + { + cv::gpu::Canny(d_image, d_buf, d_dst, 50.0, 100.0, apperture_size, useL2gradient); + } + } + else + { + cv::Mat dst; + + cv::Canny(image, dst, 50.0, 100.0, apperture_size, useL2gradient); + + TEST_CYCLE() + { + cv::Canny(image, dst, 50.0, 100.0, apperture_size, useL2gradient); + } } } @@ -497,7 +689,7 @@ DEF_PARAM_TEST_1(Image, string); PERF_TEST_P(Image, ImgProc_MeanShiftFiltering, Values("gpu/meanshift/cones.png")) { - declare.time(5.0); + declare.time(15.0); cv::Mat img = readImage(GetParam()); ASSERT_FALSE(img.empty()); @@ -505,14 +697,28 @@ PERF_TEST_P(Image, ImgProc_MeanShiftFiltering, Values("gpu/meanshift/con cv::Mat rgba; cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - cv::gpu::GpuMat d_src(rgba); - cv::gpu::GpuMat d_dst; - - cv::gpu::meanShiftFiltering(d_src, d_dst, 50, 50); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(rgba); + cv::gpu::GpuMat d_dst; + cv::gpu::meanShiftFiltering(d_src, d_dst, 50, 50); + + TEST_CYCLE() + { + cv::gpu::meanShiftFiltering(d_src, d_dst, 50, 50); + } + } + else + { + cv::Mat dst; + + cv::pyrMeanShiftFiltering(img, dst, 50, 50); + + TEST_CYCLE() + { + cv::pyrMeanShiftFiltering(img, dst, 50, 50); + } } } @@ -529,15 +735,22 @@ PERF_TEST_P(Image, ImgProc_MeanShiftProc, Values("gpu/meanshift/cones.pn cv::Mat rgba; cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA); - cv::gpu::GpuMat d_src(rgba); - cv::gpu::GpuMat d_dstr; - cv::gpu::GpuMat d_dstsp; - - cv::gpu::meanShiftProc(d_src, d_dstr, d_dstsp, 50, 50); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(rgba); + cv::gpu::GpuMat d_dstr; + cv::gpu::GpuMat d_dstsp; + cv::gpu::meanShiftProc(d_src, d_dstr, d_dstsp, 50, 50); + + TEST_CYCLE() + { + cv::gpu::meanShiftProc(d_src, d_dstr, d_dstsp, 50, 50); + } + } + else + { + FAIL(); } } @@ -556,13 +769,20 @@ PERF_TEST_P(Image, ImgProc_MeanShiftSegmentation, Values("gpu/meanshift/ cv::Mat dst; - cv::gpu::GpuMat d_src(rgba); - - cv::gpu::meanShiftSegmentation(d_src, dst, 10, 10, 20); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(rgba); + cv::gpu::meanShiftSegmentation(d_src, dst, 10, 10, 20); + + TEST_CYCLE() + { + cv::gpu::meanShiftSegmentation(d_src, dst, 10, 10, 20); + } + } + else + { + FAIL(); } } @@ -583,17 +803,24 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, Combine(GPU_TYPICAL_MAT_SIZES, Val cv::Mat img2(size, type); fillRandom(img2); - cv::gpu::GpuMat d_img1(img1); - cv::gpu::GpuMat d_img2(img2); - cv::gpu::GpuMat d_weights1(size, CV_32FC1, cv::Scalar::all(0.5)); - cv::gpu::GpuMat d_weights2(size, CV_32FC1, cv::Scalar::all(0.5)); - cv::gpu::GpuMat d_dst; - - cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_img1(img1); + cv::gpu::GpuMat d_img2(img2); + cv::gpu::GpuMat d_weights1(size, CV_32FC1, cv::Scalar::all(0.5)); + cv::gpu::GpuMat d_weights2(size, CV_32FC1, cv::Scalar::all(0.5)); + cv::gpu::GpuMat d_dst; + cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, d_dst); + + TEST_CYCLE() + { + cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, d_dst); + } + } + else + { + FAIL(); } } @@ -604,26 +831,48 @@ 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(2.0); + declare.time(10.0); cv::Size size = GET_PARAM(0); int templ_size = GET_PARAM(1); bool ccorr = GET_PARAM(2); - cv::gpu::GpuMat d_image = cv::gpu::createContinuous(size, CV_32FC1); - d_image.setTo(cv::Scalar(1.0)); + cv::Mat image(size, CV_32FC1); + image.setTo(1.0); - cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1); - d_templ.setTo(cv::Scalar(1.0)); + cv::Mat templ(templ_size, templ_size, CV_32FC1); + templ.setTo(1.0); - cv::gpu::GpuMat d_dst; - cv::gpu::ConvolveBuf d_buf; - - cv::gpu::convolve(d_image, d_templ, d_dst, ccorr, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + 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 d_dst; + cv::gpu::ConvolveBuf d_buf; + cv::gpu::convolve(d_image, d_templ, d_dst, ccorr, d_buf); + + TEST_CYCLE() + { + cv::gpu::convolve(d_image, d_templ, d_dst, ccorr, d_buf); + } + } + else + { + ASSERT_FALSE(ccorr); + + cv::Mat dst; + + cv::filter2D(image, dst, image.depth(), templ); + + TEST_CYCLE() + { + cv::filter2D(image, dst, image.depth(), templ); + } } } @@ -652,15 +901,29 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate8U, Combine( cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_8U, cn)); fillRandom(templ); - cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat d_templ(templ); - cv::gpu::GpuMat d_dst; - - cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_templ(templ); + cv::gpu::GpuMat d_dst; + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); + + TEST_CYCLE() + { + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); + } + } + else + { + cv::Mat dst; + + cv::matchTemplate(image, templ, dst, method); + + TEST_CYCLE() + { + cv::matchTemplate(image, templ, dst, method); + } } }; @@ -684,15 +947,29 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate32F, Combine( cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_32F, cn)); fillRandom(templ); - cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat d_templ(templ); - cv::gpu::GpuMat d_dst; - - cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_templ(templ); + cv::gpu::GpuMat d_dst; + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); + + TEST_CYCLE() + { + cv::gpu::matchTemplate(d_image, d_templ, d_dst, method); + } + } + else + { + cv::Mat dst; + + cv::matchTemplate(image, templ, dst, method); + + TEST_CYCLE() + { + cv::matchTemplate(image, templ, dst, method); + } } }; @@ -716,15 +993,29 @@ PERF_TEST_P(Sz_Flags, ImgProc_MulSpectrums, Combine( cv::Mat b(size, CV_32FC2); fillRandom(b, 0, 100); - cv::gpu::GpuMat d_a(a); - cv::gpu::GpuMat d_b(b); - cv::gpu::GpuMat d_dst; - - cv::gpu::mulSpectrums(d_a, d_b, d_dst, flag); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_a(a); + cv::gpu::GpuMat d_b(b); + cv::gpu::GpuMat d_dst; + cv::gpu::mulSpectrums(d_a, d_b, d_dst, flag); + + TEST_CYCLE() + { + cv::gpu::mulSpectrums(d_a, d_b, d_dst, flag); + } + } + else + { + cv::Mat dst; + + cv::mulSpectrums(a, b, dst, flag); + + TEST_CYCLE() + { + cv::mulSpectrums(a, b, dst, flag); + } } } @@ -743,15 +1034,22 @@ PERF_TEST_P(Sz, ImgProc_MulAndScaleSpectrums, GPU_TYPICAL_MAT_SIZES) cv::Mat src2(size, CV_32FC2); fillRandom(src2, 0, 100); - cv::gpu::GpuMat d_src1(src1); - cv::gpu::GpuMat d_src2(src2); - cv::gpu::GpuMat d_dst; - - cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, d_dst, cv::DFT_ROWS, scale, false); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src1(src1); + cv::gpu::GpuMat d_src2(src2); + cv::gpu::GpuMat d_dst; + cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, d_dst, cv::DFT_ROWS, scale, false); + + TEST_CYCLE() + { + cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, d_dst, cv::DFT_ROWS, scale, false); + } + } + else + { + FAIL(); } } @@ -762,7 +1060,7 @@ PERF_TEST_P(Sz_Flags, ImgProc_Dft, Combine( GPU_TYPICAL_MAT_SIZES, Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))) { - declare.time(2.0); + declare.time(10.0); cv::Size size = GET_PARAM(0); int flag = GET_PARAM(1); @@ -770,14 +1068,28 @@ PERF_TEST_P(Sz_Flags, ImgProc_Dft, Combine( cv::Mat src(size, CV_32FC2); fillRandom(src, 0, 100); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::dft(d_src, d_dst, size, flag); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::dft(d_src, d_dst, size, flag); + + TEST_CYCLE() + { + cv::gpu::dft(d_src, d_dst, size, flag); + } + } + else + { + cv::Mat dst; + + cv::dft(src, dst, flag); + + TEST_CYCLE() + { + cv::dft(src, dst, flag); + } } } @@ -793,8 +1105,6 @@ PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerHarris, Combine( Values(3, 5, 7), Values(0, 3, 5, 7))) { - double k = 0.5; - string fileName = GET_PARAM(0); int type = GET_PARAM(1); int borderMode = GET_PARAM(2); @@ -803,20 +1113,35 @@ PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerHarris, Combine( 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); - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_Dx; - cv::gpu::GpuMat d_Dy; - cv::gpu::GpuMat d_buf; + double k = 0.5; - cv::gpu::cornerHarris(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_Dx; + cv::gpu::GpuMat d_Dy; + cv::gpu::GpuMat d_buf; + cv::gpu::cornerHarris(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); + + TEST_CYCLE() + { + cv::gpu::cornerHarris(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode); + } + } + else + { + cv::Mat dst; + + cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderMode); + + TEST_CYCLE() + { + cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderMode); + } } } @@ -841,17 +1166,31 @@ PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerMinEigenVal, Com img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_dst; - cv::gpu::GpuMat d_Dx; - cv::gpu::GpuMat d_Dy; - cv::gpu::GpuMat d_buf; - - cv::gpu::cornerMinEigenVal(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_dst; + cv::gpu::GpuMat d_Dx; + cv::gpu::GpuMat d_Dy; + cv::gpu::GpuMat d_buf; + cv::gpu::cornerMinEigenVal(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); + + TEST_CYCLE() + { + cv::gpu::cornerMinEigenVal(d_img, d_dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode); + } + } + else + { + cv::Mat dst; + + cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderMode); + + TEST_CYCLE() + { + cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderMode); + } } } @@ -866,14 +1205,21 @@ PERF_TEST_P(Sz, ImgProc_BuildWarpPlaneMaps, GPU_TYPICAL_MAT_SIZES) cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); cv::Mat T = cv::Mat::zeros(1, 3, CV_32F); - cv::gpu::GpuMat d_map_x; - cv::gpu::GpuMat d_map_y; - - cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, d_map_x, d_map_y); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, d_map_x, d_map_y); + + TEST_CYCLE() + { + cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, d_map_x, d_map_y); + } + } + else + { + FAIL(); } } @@ -887,14 +1233,21 @@ PERF_TEST_P(Sz, ImgProc_BuildWarpCylindricalMaps, GPU_TYPICAL_MAT_SIZES) cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat d_map_x; - cv::gpu::GpuMat d_map_y; - - cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); + + TEST_CYCLE() + { + cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); + } + } + else + { + FAIL(); } } @@ -908,14 +1261,21 @@ PERF_TEST_P(Sz, ImgProc_BuildWarpSphericalMaps, GPU_TYPICAL_MAT_SIZES) cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1); cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1); - cv::gpu::GpuMat d_map_x; - cv::gpu::GpuMat d_map_y; - - cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_map_x; + cv::gpu::GpuMat d_map_y; + cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); + + TEST_CYCLE() + { + cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, d_map_x, d_map_y); + } + } + else + { + FAIL(); } } @@ -940,14 +1300,21 @@ PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::rotate(d_src, d_dst, size, 30.0, 0, 0, interpolation); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::rotate(d_src, d_dst, size, 30.0, 0, 0, interpolation); + + TEST_CYCLE() + { + cv::gpu::rotate(d_src, d_dst, size, 30.0, 0, 0, interpolation); + } + } + else + { + FAIL(); } } @@ -968,14 +1335,28 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrDown, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::pyrDown(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::pyrDown(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::pyrDown(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::pyrDown(src, dst); + + TEST_CYCLE() + { + cv::pyrDown(src, dst); + } } } @@ -996,14 +1377,28 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrUp, Combine( cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::pyrUp(d_src, d_dst); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::pyrUp(d_src, d_dst); + + TEST_CYCLE() + { + cv::gpu::pyrUp(d_src, d_dst); + } + } + else + { + cv::Mat dst; + + cv::pyrUp(src, dst); + + TEST_CYCLE() + { + cv::pyrUp(src, dst); + } } } @@ -1049,14 +1444,28 @@ PERF_TEST_P(Sz_Depth_Code, ImgProc_CvtColor, Combine( cv::Mat src(size, CV_MAKETYPE(depth, info.scn)); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::cvtColor(d_src, d_dst, info.code, info.dcn); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + cv::gpu::cvtColor(d_src, d_dst, info.code, info.dcn); + + TEST_CYCLE() + { + cv::gpu::cvtColor(d_src, d_dst, info.code, info.dcn); + } + } + else + { + cv::Mat dst; + + cv::cvtColor(src, dst, info.code, info.dcn); + + TEST_CYCLE() + { + cv::cvtColor(src, dst, info.code, info.dcn); + } } } @@ -1072,13 +1481,20 @@ PERF_TEST_P(Sz, ImgProc_SwapChannels, GPU_TYPICAL_MAT_SIZES) const int dstOrder[] = {2, 1, 0, 3}; - cv::gpu::GpuMat d_src(src); - - cv::gpu::swapChannels(d_src, dstOrder); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::swapChannels(d_src, dstOrder); + + TEST_CYCLE() + { + cv::gpu::swapChannels(d_src, dstOrder); + } + } + else + { + FAIL(); } } @@ -1102,15 +1518,22 @@ PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, Combine(GPU_TYPICAL_MAT_SIZES, Values cv::Mat img2(size, type); fillRandom(img2); - cv::gpu::GpuMat d_img1(img1); - cv::gpu::GpuMat d_img2(img2); - cv::gpu::GpuMat d_dst; - - cv::gpu::alphaComp(d_img1, d_img2, d_dst, alpha_op); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_img1(img1); + cv::gpu::GpuMat d_img2(img2); + cv::gpu::GpuMat d_dst; + cv::gpu::alphaComp(d_img1, d_img2, d_dst, alpha_op); + + TEST_CYCLE() + { + cv::gpu::alphaComp(d_img1, d_img2, d_dst, alpha_op); + } + } + else + { + FAIL(); } } @@ -1128,15 +1551,22 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidBuild, Combine(GPU_TYPICAL_MAT_SIZE cv::Mat src(size, type); fillRandom(src); - cv::gpu::GpuMat d_src(src); - - cv::gpu::ImagePyramid d_pyr; - - d_pyr.build(d_src, 5); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + + cv::gpu::ImagePyramid d_pyr; + d_pyr.build(d_src, 5); + + TEST_CYCLE() + { + d_pyr.build(d_src, 5); + } + } + else + { + FAIL(); } } @@ -1156,16 +1586,23 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidGetLayer, Combine(GPU_TYPICAL_MAT_S cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - cv::gpu::ImagePyramid d_pyr(d_src, 3); - - d_pyr.getLayer(d_dst, dstSize); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + + cv::gpu::ImagePyramid d_pyr(d_src, 3); + d_pyr.getLayer(d_dst, dstSize); + + TEST_CYCLE() + { + d_pyr.getLayer(d_dst, dstSize); + } + } + else + { + FAIL(); } } @@ -1197,16 +1634,29 @@ PERF_TEST_P(Sz_DoSort, ImgProc_HoughLines, Combine(GPU_TYPICAL_MAT_SIZES, Bool() cv::line(src, p1, p2, cv::Scalar::all(255), 2); } - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_lines; - cv::gpu::GpuMat d_accum; - cv::gpu::GpuMat d_buf; - - cv::gpu::HoughLines(d_src, d_lines, d_accum, d_buf, rho, theta, threshold, doSort); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_lines; + cv::gpu::GpuMat d_accum; + cv::gpu::GpuMat d_buf; + cv::gpu::HoughLines(d_src, d_lines, d_accum, d_buf, rho, theta, threshold, doSort); + + TEST_CYCLE() + { + cv::gpu::HoughLines(d_src, d_lines, d_accum, d_buf, rho, theta, threshold, doSort); + } + } + else + { + std::vector lines; + cv::HoughLines(src, lines, rho, theta, threshold); + + TEST_CYCLE() + { + cv::HoughLines(src, lines, rho, theta, threshold); + } } } diff --git a/modules/gpu/perf/perf_labeling.cpp b/modules/gpu/perf/perf_labeling.cpp index bd1bcf144..f17dd7d0a 100644 --- a/modules/gpu/perf/perf_labeling.cpp +++ b/modules/gpu/perf/perf_labeling.cpp @@ -7,27 +7,129 @@ namespace { DEF_PARAM_TEST_1(Image, string); +struct GreedyLabeling +{ + struct dot + { + int x; + int y; + + static dot make(int i, int j) + { + dot d; d.x = i; d.y = j; + return d; + } + }; + + struct InInterval + { + InInterval(const int& _lo, const int& _hi) : lo(-_lo), hi(_hi) {}; + const int lo, hi; + + bool operator() (const unsigned char a, const unsigned char b) const + { + int d = a - b; + return lo <= d && d <= hi; + } + }; + + GreedyLabeling(cv::Mat img) + : image(img), _labels(image.size(), CV_32SC1, cv::Scalar::all(-1)) {stack = new dot[image.cols * image.rows];} + + ~GreedyLabeling(){delete[] stack;} + + void operator() (cv::Mat labels) const + { + labels.setTo(cv::Scalar::all(-1)); + InInterval inInt(0, 2); + int cc = -1; + + int* dist_labels = (int*)labels.data; + int pitch = labels.step1(); + + unsigned char* source = (unsigned char*)image.data; + int width = image.cols; + int height = image.rows; + + for (int j = 0; j < image.rows; ++j) + for (int i = 0; i < image.cols; ++i) + { + if (dist_labels[j * pitch + i] != -1) continue; + + dot* top = stack; + dot p = dot::make(i, j); + cc++; + + dist_labels[j * pitch + i] = cc; + + while (top >= stack) + { + int* dl = &dist_labels[p.y * pitch + p.x]; + unsigned char* sp = &source[p.y * image.step1() + p.x]; + + dl[0] = cc; + + //right + if( p.x < (width - 1) && dl[ +1] == -1 && inInt(sp[0], sp[+1])) + *top++ = dot::make(p.x + 1, p.y); + + //left + if( p.x > 0 && dl[-1] == -1 && inInt(sp[0], sp[-1])) + *top++ = dot::make(p.x - 1, p.y); + + //bottom + if( p.y < (height - 1) && dl[+pitch] == -1 && inInt(sp[0], sp[+image.step1()])) + *top++ = dot::make(p.x, p.y + 1); + + //top + if( p.y > 0 && dl[-pitch] == -1 && inInt(sp[0], sp[-image.step1()])) + *top++ = dot::make(p.x, p.y - 1); + + p = *--top; + } + } + } + + cv::Mat image; + cv::Mat _labels; + dot* stack; +}; + PERF_TEST_P(Image, Labeling_ConnectedComponents, Values("gpu/labeling/aloe-disp.png")) { - cv::Mat image = readImage(GetParam(), cv::IMREAD_GRAYSCALE); - - // cv::threshold(image, image, 150, 255, CV_THRESH_BINARY); - - cv::gpu::GpuMat mask; - mask.create(image.rows, image.cols, CV_8UC1); - - cv::gpu::GpuMat components; - components.create(image.rows, image.cols, CV_32SC1); - - cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2)); - - ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components)); - declare.time(1.0); - TEST_CYCLE() + cv::Mat image = readImage(GetParam(), cv::IMREAD_GRAYSCALE); + + if (runOnGpu) { - cv::gpu::labelComponents(mask, components); + cv::gpu::GpuMat mask; + mask.create(image.rows, image.cols, CV_8UC1); + + cv::gpu::GpuMat components; + components.create(image.rows, image.cols, CV_32SC1); + + cv::gpu::connectivityMask(cv::gpu::GpuMat(image), mask, cv::Scalar::all(0), cv::Scalar::all(2)); + + ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components)); + + TEST_CYCLE() + { + cv::gpu::labelComponents(mask, components); + } + } + else + { + GreedyLabeling host(image); + + host(host._labels); + + declare.time(1.0); + + TEST_CYCLE() + { + host(host._labels); + } } } diff --git a/modules/gpu/perf/perf_matop.cpp b/modules/gpu/perf/perf_matop.cpp index c014b19da..cdae962f2 100644 --- a/modules/gpu/perf/perf_matop.cpp +++ b/modules/gpu/perf/perf_matop.cpp @@ -18,13 +18,27 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8 cv::Scalar val(1, 2, 3, 4); - cv::gpu::GpuMat d_src(size, type); - - d_src.setTo(val); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(size, type); + d_src.setTo(val); + + TEST_CYCLE() + { + d_src.setTo(val); + } + } + else + { + cv::Mat src(size, type); + + src.setTo(val); + + TEST_CYCLE() + { + src.setTo(val); + } } } @@ -47,14 +61,26 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Value cv::Scalar val(1, 2, 3, 4); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_mask(mask); - - d_src.setTo(val, d_mask); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_mask(mask); + d_src.setTo(val, d_mask); + + TEST_CYCLE() + { + d_src.setTo(val, d_mask); + } + } + else + { + src.setTo(val, mask); + + TEST_CYCLE() + { + src.setTo(val, mask); + } } } @@ -75,15 +101,29 @@ PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Valu cv::Mat mask(size, CV_8UC1); fillRandom(mask, 0, 2); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_mask(mask); - cv::gpu::GpuMat d_dst; - - d_src.copyTo(d_dst, d_mask); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_mask(mask); + cv::gpu::GpuMat d_dst; + d_src.copyTo(d_dst, d_mask); + + TEST_CYCLE() + { + d_src.copyTo(d_dst, d_mask); + } + } + else + { + cv::Mat dst; + + src.copyTo(dst, mask); + + TEST_CYCLE() + { + src.copyTo(dst, mask); + } } } @@ -101,14 +141,28 @@ PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV cv::Mat src(size, depth1); fillRandom(src); - cv::gpu::GpuMat d_src(src); - cv::gpu::GpuMat d_dst; - - d_src.convertTo(d_dst, depth2, 0.5, 1.0); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_src(src); + cv::gpu::GpuMat d_dst; + d_src.convertTo(d_dst, depth2, 0.5, 1.0); + + TEST_CYCLE() + { + d_src.convertTo(d_dst, depth2, 0.5, 1.0); + } + } + else + { + cv::Mat dst; + + src.convertTo(dst, depth2, 0.5, 1.0); + + TEST_CYCLE() + { + src.convertTo(dst, depth2, 0.5, 1.0); + } } } diff --git a/modules/gpu/perf/perf_objdetect.cpp b/modules/gpu/perf/perf_objdetect.cpp index 9c1f7919f..0c4cd5e4c 100644 --- a/modules/gpu/perf/perf_objdetect.cpp +++ b/modules/gpu/perf/perf_objdetect.cpp @@ -17,16 +17,31 @@ PERF_TEST_P(Image, ObjDetect_HOG, Values("gpu/hog/road.png")) std::vector found_locations; - cv::gpu::GpuMat d_img(img); - - cv::gpu::HOGDescriptor d_hog; - d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); - - d_hog.detectMultiScale(d_img, found_locations); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_img(img); + + cv::gpu::HOGDescriptor d_hog; + d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); + d_hog.detectMultiScale(d_img, found_locations); + + TEST_CYCLE() + { + d_hog.detectMultiScale(d_img, found_locations); + } + } + else + { + cv::HOGDescriptor hog; + hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); + + hog.detectMultiScale(img, found_locations); + + TEST_CYCLE() + { + hog.detectMultiScale(img, found_locations); + } } } @@ -42,18 +57,34 @@ PERF_TEST_P(ImageAndCascade, ObjDetect_HaarClassifier, cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::gpu::CascadeClassifier_GPU d_cascade; - - ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); - - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_objects_buffer; - - d_cascade.detectMultiScale(d_img, d_objects_buffer); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::CascadeClassifier_GPU d_cascade; + ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_objects_buffer; + d_cascade.detectMultiScale(d_img, d_objects_buffer); + + TEST_CYCLE() + { + d_cascade.detectMultiScale(d_img, d_objects_buffer); + } + } + else + { + cv::CascadeClassifier cascade; + ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml"))); + + std::vector rects; + + cascade.detectMultiScale(img, rects); + + TEST_CYCLE() + { + cascade.detectMultiScale(img, rects); + } } } @@ -66,18 +97,34 @@ PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier, cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(img.empty()); - cv::gpu::CascadeClassifier_GPU d_cascade; - - ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); - - cv::gpu::GpuMat d_img(img); - cv::gpu::GpuMat d_gpu_rects; - - d_cascade.detectMultiScale(d_img, d_gpu_rects); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::CascadeClassifier_GPU d_cascade; + ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second))); + + cv::gpu::GpuMat d_img(img); + cv::gpu::GpuMat d_gpu_rects; + d_cascade.detectMultiScale(d_img, d_gpu_rects); + + TEST_CYCLE() + { + d_cascade.detectMultiScale(d_img, d_gpu_rects); + } + } + else + { + cv::CascadeClassifier cascade; + ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml"))); + + std::vector rects; + + cascade.detectMultiScale(img, rects); + + TEST_CYCLE() + { + cascade.detectMultiScale(img, rects); + } } } diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index a5a1e4da5..7faea0b88 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -3,6 +3,14 @@ using namespace std; using namespace testing; +namespace cv +{ + template<> void Ptr::delete_obj() + { + cvReleaseBGStatModel(&obj); + } +} + namespace { ////////////////////////////////////////////////////// @@ -25,19 +33,26 @@ PERF_TEST_P(ImagePair, Video_BroxOpticalFlow, Values(make_pair("gpu frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - cv::gpu::GpuMat d_frame0(frame0); - cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_u; - cv::gpu::GpuMat d_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, d_u, d_v); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_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, d_u, d_v); + + TEST_CYCLE() + { + d_flow(d_frame0, d_frame1, d_u, d_v); + } + } + else + { + FAIL(); } } @@ -55,25 +70,32 @@ PERF_TEST_P(ImagePair, Video_InterpolateFrames, Values(make_pair("g frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - cv::gpu::GpuMat d_frame0(frame0); - 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 d_newFrame; - cv::gpu::GpuMat d_buf; - - cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_frame0(frame0); + 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 d_newFrame; + cv::gpu::GpuMat d_buf; + cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); + + TEST_CYCLE() + { + cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf); + } + } + else + { + FAIL(); } } @@ -91,23 +113,30 @@ PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap, Values(mak frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0); - cv::gpu::GpuMat d_frame0(frame0); - cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_u; - cv::gpu::GpuMat d_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, d_u, d_v); - - cv::gpu::GpuMat d_vertex, d_colors; - - cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_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, d_u, d_v); + + cv::gpu::GpuMat d_vertex, d_colors; + cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); + + TEST_CYCLE() + { + cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors); + } + } + else + { + FAIL(); } } @@ -124,16 +153,30 @@ PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack, Combine(Values cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(image.empty()); - cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance); - - cv::gpu::GpuMat d_image(image); - cv::gpu::GpuMat d_pts; - - d_detector(d_image, d_pts); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance); + + cv::gpu::GpuMat d_image(image); + cv::gpu::GpuMat d_pts; + d_detector(d_image, d_pts); + + TEST_CYCLE() + { + d_detector(d_image, d_pts); + } + } + else + { + cv::Mat pts; + + cv::goodFeaturesToTrack(image, pts, 8000, 0.01, minDistance); + + TEST_CYCLE() + { + cv::goodFeaturesToTrack(image, pts, 8000, 0.01, minDistance); + } } } @@ -150,6 +193,8 @@ PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, Video_PyrLKOpticalFlowSparse Values(1, 2, 3), Values(1, 10, 30))) { + declare.time(20.0); + pair_string imagePair = GET_PARAM(0); bool useGray = GET_PARAM(1); int points = GET_PARAM(2); @@ -169,26 +214,45 @@ PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, Video_PyrLKOpticalFlowSparse else cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY); - cv::gpu::GpuMat d_pts; + cv::Mat pts; + cv::goodFeaturesToTrack(gray_frame, pts, points, 0.01, 0.0); - cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(points, 0.01, 0.0); - d_detector(cv::gpu::GpuMat(gray_frame), d_pts); - - cv::gpu::PyrLKOpticalFlow d_pyrLK; - d_pyrLK.winSize = cv::Size(winSize, winSize); - d_pyrLK.maxLevel = levels - 1; - d_pyrLK.iters = iters; - - cv::gpu::GpuMat d_frame0(frame0); - cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_nextPts; - cv::gpu::GpuMat d_status; - - d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_pts(pts); + + cv::gpu::PyrLKOpticalFlow d_pyrLK; + d_pyrLK.winSize = cv::Size(winSize, winSize); + d_pyrLK.maxLevel = levels - 1; + d_pyrLK.iters = iters; + + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_nextPts; + cv::gpu::GpuMat d_status; + d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); + + TEST_CYCLE() + { + d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status); + } + } + else + { + cv::Mat nextPts; + cv::Mat status; + + 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)); + + 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)); + } } } @@ -216,21 +280,28 @@ PERF_TEST_P(ImagePair_WinSz_Levels_Iters, Video_PyrLKOpticalFlowDense, Combine( cv::Mat frame1 = readImage(imagePair.second, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame1.empty()); - cv::gpu::GpuMat d_frame0(frame0); - cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_u; - cv::gpu::GpuMat d_v; - - cv::gpu::PyrLKOpticalFlow d_pyrLK; - d_pyrLK.winSize = cv::Size(winSize, winSize); - d_pyrLK.maxLevel = levels - 1; - d_pyrLK.iters = iters; - - d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_v; + + cv::gpu::PyrLKOpticalFlow d_pyrLK; + d_pyrLK.winSize = cv::Size(winSize, winSize); + d_pyrLK.maxLevel = levels - 1; + d_pyrLK.iters = iters; + d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); + + TEST_CYCLE() + { + d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v); + } + } + else + { + FAIL(); } } @@ -247,18 +318,47 @@ PERF_TEST_P(ImagePair, Video_FarnebackOpticalFlow, Values(make_pair cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame1.empty()); - cv::gpu::GpuMat d_frame0(frame0); - cv::gpu::GpuMat d_frame1(frame1); - cv::gpu::GpuMat d_u; - cv::gpu::GpuMat d_v; + int numLevels = 5; + double pyrScale = 0.5; + int winSize = 13; + int numIters = 10; + int polyN = 5; + double polySigma = 1.1; + int flags = 0; - cv::gpu::FarnebackOpticalFlow d_farneback; - - d_farneback(d_frame0, d_frame1, d_u, d_v); - - TEST_CYCLE() + if (runOnGpu) { + cv::gpu::GpuMat d_frame0(frame0); + cv::gpu::GpuMat d_frame1(frame1); + cv::gpu::GpuMat d_u; + cv::gpu::GpuMat d_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; + d_farneback(d_frame0, d_frame1, d_u, d_v); + + TEST_CYCLE() + { + d_farneback(d_frame0, d_frame1, d_u, d_v); + } + } + else + { + cv::Mat flow; + + cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); + + TEST_CYCLE() + { + cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); + } } } @@ -269,7 +369,7 @@ DEF_PARAM_TEST_1(Video, string); PERF_TEST_P(Video, Video_FGDStatModel, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) { - declare.time(10); + declare.time(60); string inputFile = perf::TestBase::getDataPath(GetParam()); @@ -280,20 +380,41 @@ PERF_TEST_P(Video, Video_FGDStatModel, Values("gpu/video/768x576.avi", "gpu/vide cap >> frame; ASSERT_FALSE(frame.empty()); - cv::gpu::GpuMat d_frame(frame); - cv::gpu::FGDStatModel d_model(4); - d_model.create(d_frame); - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - cap >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::GpuMat d_frame(frame); - d_frame.upload(frame); + cv::gpu::FGDStatModel d_model(4); + d_model.create(d_frame); - startTimer(); next(); - d_model.update(d_frame); - stopTimer(); + 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(); + } + } + 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(); + } } } @@ -313,10 +434,6 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576. cv::Mat frame; - cv::gpu::GpuMat d_frame; - cv::gpu::MOG_GPU d_mog; - cv::gpu::GpuMat d_foreground; - cap >> frame; ASSERT_FALSE(frame.empty()); @@ -330,30 +447,62 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576. cv::swap(temp, frame); } - d_frame.upload(frame); - - d_mog(d_frame, d_foreground, learningRate); - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - cap >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::GpuMat d_frame(frame); + cv::gpu::MOG_GPU d_mog; + cv::gpu::GpuMat d_foreground; - 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, d_foreground, learningRate); - stopTimer(); + + 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, d_foreground, learningRate); + stopTimer(); + } + } + else + { + cv::BackgroundSubtractorMOG mog; + cv::Mat foreground; + + mog(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(frame, foreground, learningRate); + stopTimer(); + } } } @@ -372,10 +521,6 @@ PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/v cv::Mat frame; - cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU d_mog2; - cv::gpu::GpuMat d_foreground; - cap >> frame; ASSERT_FALSE(frame.empty()); @@ -389,30 +534,62 @@ PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/v cv::swap(temp, frame); } - d_frame.upload(frame); - - d_mog2(d_frame, d_foreground); - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - cap >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::GpuMat d_frame(frame); + cv::gpu::MOG2_GPU d_mog2; + cv::gpu::GpuMat d_foreground; - 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, d_foreground); - stopTimer(); + + 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, d_foreground); + stopTimer(); + } + } + else + { + cv::BackgroundSubtractorMOG2 mog2; + cv::Mat foreground; + + mog2(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(frame, foreground); + stopTimer(); + } } } @@ -429,36 +606,70 @@ PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, Combine(Values("gpu/video/76 cv::Mat frame; - cv::gpu::GpuMat d_frame; - cv::gpu::MOG2_GPU d_mog2; - cv::gpu::GpuMat d_foreground; - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - cap >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::GpuMat d_frame; + cv::gpu::MOG2_GPU d_mog2; + cv::gpu::GpuMat d_foreground; - if (cn != 3) + for (int i = 0; i < 10; ++i) { - 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); + 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); } - d_frame.upload(frame); - - d_mog2(d_frame, d_foreground); - } - - cv::gpu::GpuMat d_background; - d_mog2.getBackgroundImage(d_background); - - TEST_CYCLE() - { + cv::gpu::GpuMat d_background; d_mog2.getBackgroundImage(d_background); + + TEST_CYCLE() + { + d_mog2.getBackgroundImage(d_background); + } + } + else + { + cv::BackgroundSubtractorMOG2 mog2; + 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(frame, foreground); + } + + cv::Mat background; + mog2.getBackgroundImage(background); + + TEST_CYCLE() + { + mog2.getBackgroundImage(background); + } } } @@ -487,32 +698,39 @@ PERF_TEST_P(Video_Cn, Video_VIBE, Combine(Values("gpu/video/768x576.avi", "gpu/v cv::swap(temp, frame); } - cv::gpu::GpuMat d_frame(frame); - cv::gpu::VIBE_GPU d_vibe; - cv::gpu::GpuMat d_foreground; - - d_vibe(d_frame, d_foreground); - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - cap >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::GpuMat d_frame(frame); + cv::gpu::VIBE_GPU d_vibe; + cv::gpu::GpuMat d_foreground; - 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_vibe(d_frame, d_foreground); - stopTimer(); + + 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_vibe(d_frame, d_foreground); + stopTimer(); + } + } + else + { + FAIL(); } } @@ -544,38 +762,76 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.a cv::swap(temp, frame); } - cv::gpu::GpuMat d_frame(frame); - cv::gpu::GpuMat d_fgmask; - - cv::gpu::GMG_GPU d_gmg; - d_gmg.maxFeatures = maxFeatures; - - d_gmg(d_frame, d_fgmask); - - for (int i = 0; i < 150; ++i) + if (runOnGpu) { - cap >> frame; - if (frame.empty()) - { - cap.open(inputFile); - cap >> frame; - } + cv::gpu::GpuMat d_frame(frame); + cv::gpu::GpuMat d_fgmask; - 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); - } + cv::gpu::GMG_GPU d_gmg; + d_gmg.maxFeatures = maxFeatures; - d_frame.upload(frame); - - startTimer(); next(); d_gmg(d_frame, d_fgmask); - stopTimer(); + + for (int i = 0; i < 150; ++i) + { + cap >> frame; + if (frame.empty()) + { + 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, d_fgmask); + stopTimer(); + } + } + else + { + cv::Mat fgmask; + cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); + + cv::BackgroundSubtractorGMG gmg; + gmg.set("maxFeatures", maxFeatures); + gmg.initialize(frame.size(), 0.0, 255.0); + + gmg(frame, fgmask); + + for (int i = 0; i < 150; ++i) + { + cap >> frame; + if (frame.empty()) + { + 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(frame, fgmask); + stopTimer(); + } } } @@ -584,6 +840,8 @@ PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.a PERF_TEST_P(Video, Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi")) { + declare.time(30); + string inputFile = perf::TestBase::getDataPath(GetParam()); string outputFile = cv::tempfile(".avi"); @@ -592,26 +850,45 @@ PERF_TEST_P(Video, Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video cv::VideoCapture reader(inputFile); ASSERT_TRUE( reader.isOpened() ); - cv::gpu::VideoWriter_GPU d_writer; - cv::Mat frame; - cv::gpu::GpuMat d_frame; - declare.time(10); - - for (int i = 0; i < 10; ++i) + if (runOnGpu) { - reader >> frame; - ASSERT_FALSE(frame.empty()); + cv::gpu::VideoWriter_GPU d_writer; - d_frame.upload(frame); + cv::gpu::GpuMat d_frame; - if (!d_writer.isOpened()) - d_writer.open(outputFile, frame.size(), FPS); + for (int i = 0; i < 10; ++i) + { + reader >> frame; + ASSERT_FALSE(frame.empty()); - startTimer(); next(); - d_writer.write(d_frame); - stopTimer(); + 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(); + } } } @@ -624,16 +901,33 @@ PERF_TEST_P(Video, Video_VideoReader, Values("gpu/video/768x576.avi", "gpu/video string inputFile = perf::TestBase::getDataPath(GetParam()); - cv::gpu::VideoReader_GPU d_reader(inputFile); - ASSERT_TRUE( d_reader.isOpened() ); - - cv::gpu::GpuMat d_frame; - - d_reader.read(d_frame); - - TEST_CYCLE_N(10) + if (runOnGpu) { + cv::gpu::VideoReader_GPU d_reader(inputFile); + ASSERT_TRUE( d_reader.isOpened() ); + + cv::gpu::GpuMat d_frame; + d_reader.read(d_frame); + + TEST_CYCLE_N(10) + { + d_reader.read(d_frame); + } + } + else + { + cv::VideoCapture reader(inputFile); + ASSERT_TRUE( reader.isOpened() ); + + cv::Mat frame; + + reader >> frame; + + TEST_CYCLE_N(10) + { + reader >> frame; + } } } diff --git a/modules/gpu/perf_cpu/perf_calib3d.cpp b/modules/gpu/perf_cpu/perf_calib3d.cpp deleted file mode 100644 index 8124b808a..000000000 --- a/modules/gpu/perf_cpu/perf_calib3d.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////////////////////// -// StereoBM - -GPU_PERF_TEST_1(StereoBM, cv::gpu::DeviceInfo) -{ - cv::Mat img_l = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_l.empty()); - - cv::Mat img_r = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img_r.empty()); - - cv::StereoBM bm(0, 256); - - cv::Mat dst; - - bm(img_l, img_r, dst); - - declare.time(5.0); - - TEST_CYCLE() - { - bm(img_l, img_r, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Calib3D, StereoBM, ALL_DEVICES); - -////////////////////////////////////////////////////////////////////// -// ProjectPoints - -IMPLEMENT_PARAM_CLASS(Count, int) - -GPU_PERF_TEST(ProjectPoints, cv::gpu::DeviceInfo, Count) -{ - int count = GET_PARAM(1); - - cv::Mat src(1, count, CV_32FC3); - fill(src, -100, 100); - - cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); - cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1); - cv::Mat dst; - - cv::projectPoints(src, rvec, tvec, camera_mat, cv::noArray(), dst); - - TEST_CYCLE() - { - cv::projectPoints(src, rvec, tvec, camera_mat, cv::noArray(), dst); - } -} - -INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, testing::Combine( - ALL_DEVICES, - testing::Values(5000, 10000, 20000))); - -////////////////////////////////////////////////////////////////////// -// SolvePnPRansac - -GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count) -{ - int count = GET_PARAM(1); - - cv::Mat object(1, count, CV_32FC3); - fill(object, -100, 100); - - cv::Mat camera_mat(3, 3, CV_32FC1); - fill(camera_mat, 0.5, 1); - camera_mat.at(0, 1) = 0.f; - camera_mat.at(1, 0) = 0.f; - camera_mat.at(2, 0) = 0.f; - camera_mat.at(2, 1) = 0.f; - - cv::Mat dist_coef(1, 8, CV_32F, cv::Scalar::all(0)); - - std::vector image_vec; - cv::Mat rvec_gold(1, 3, CV_32FC1); - fill(rvec_gold, 0, 1); - cv::Mat tvec_gold(1, 3, CV_32FC1); - fill(tvec_gold, 0, 1); - cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec); - - cv::Mat image(1, count, CV_32FC2, &image_vec[0]); - - cv::Mat rvec; - cv::Mat tvec; - - cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); - - declare.time(10.0); - - TEST_CYCLE() - { - cv::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); - } -} - -INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, testing::Combine( - ALL_DEVICES, - testing::Values(5000, 10000, 20000))); - -////////////////////////////////////////////////////////////////////// -// ReprojectImageTo3D - -GPU_PERF_TEST(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 5.0, 30.0); - - cv::Mat Q(4, 4, CV_32FC1); - fill(Q, 0.1, 1.0); - - cv::Mat dst; - - cv::reprojectImageTo3D(src, dst, Q); - - TEST_CYCLE() - { - cv::reprojectImageTo3D(src, dst, Q); - } -} - -INSTANTIATE_TEST_CASE_P(Calib3D, ReprojectImageTo3D, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S))); - -#endif - diff --git a/modules/gpu/perf_cpu/perf_core.cpp b/modules/gpu/perf_cpu/perf_core.cpp deleted file mode 100644 index fb8700958..000000000 --- a/modules/gpu/perf_cpu/perf_core.cpp +++ /dev/null @@ -1,1388 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////////////////////// -// Merge - -GPU_PERF_TEST(Merge, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - std::vector src(channels); - for (int i = 0; i < channels; ++i) - src[i] = cv::Mat(size, depth, cv::Scalar::all(i)); - - cv::Mat dst; - - cv::merge(src, dst); - - TEST_CYCLE() - { - cv::merge(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Merge, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(2, 3, 4))); - -////////////////////////////////////////////////////////////////////// -// Split - -GPU_PERF_TEST(Split, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - cv::Mat src(size, CV_MAKE_TYPE(depth, channels), cv::Scalar(1, 2, 3, 4)); - - std::vector dst; - - cv::split(src, dst); - - TEST_CYCLE() - { - cv::split(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Split, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(2, 3, 4))); - -////////////////////////////////////////////////////////////////////// -// Add_Mat - -GPU_PERF_TEST(Add_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0.0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0.0, 100.0); - - cv::Mat dst; - - cv::add(src1, src2, dst); - - TEST_CYCLE() - { - cv::add(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Add_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Add_Scalar - -GPU_PERF_TEST(Add_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Scalar s(1, 2, 3, 4); - cv::Mat dst; - - cv::add(src, s, dst); - - TEST_CYCLE() - { - cv::add(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Add_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Subtract_Mat - -GPU_PERF_TEST(Subtract_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0.0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0.0, 100.0); - - cv::Mat dst; - - cv::subtract(src1, src2, dst); - - TEST_CYCLE() - { - cv::subtract(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Subtract_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Subtract_Scalar - -GPU_PERF_TEST(Subtract_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Scalar s(1, 2, 3, 4); - cv::Mat dst; - - cv::subtract(src, s, dst); - - TEST_CYCLE() - { - cv::subtract(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Subtract_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Multiply_Mat - -GPU_PERF_TEST(Multiply_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0.0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0.0, 100.0); - - cv::Mat dst; - - cv::multiply(src1, src2, dst); - - TEST_CYCLE() - { - cv::multiply(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Multiply_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Multiply_Scalar - -GPU_PERF_TEST(Multiply_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Scalar s(1, 2, 3, 4); - cv::Mat dst; - - cv::multiply(src, s, dst); - - TEST_CYCLE() - { - cv::multiply(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Multiply_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Divide_Mat - -GPU_PERF_TEST(Divide_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0.0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0.0, 100.0); - - cv::Mat dst; - - cv::divide(src1, src2, dst); - - TEST_CYCLE() - { - cv::divide(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Divide_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Divide_Scalar - -GPU_PERF_TEST(Divide_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Scalar s(1, 2, 3, 4); - cv::Mat dst; - - cv::divide(src, s, dst); - - TEST_CYCLE() - { - cv::divide(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Divide_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Divide_Scalar_Inv - -GPU_PERF_TEST(Divide_Scalar_Inv, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - double scale = 100.0; - cv::Mat dst; - - cv::divide(scale, src, dst); - - TEST_CYCLE() - { - cv::divide(scale, src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Divide_Scalar_Inv, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// AbsDiff_Mat - -GPU_PERF_TEST(AbsDiff_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0.0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0.0, 100.0); - - cv::Mat dst; - - cv::absdiff(src1, src2, dst); - - TEST_CYCLE() - { - cv::absdiff(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, AbsDiff_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// AbsDiff_Scalar - -GPU_PERF_TEST(AbsDiff_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Scalar s(1, 2, 3, 4); - cv::Mat dst; - - cv::absdiff(src, s, dst); - - TEST_CYCLE() - { - cv::absdiff(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, AbsDiff_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Sqrt - -GPU_PERF_TEST(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 100.0); - - cv::Mat dst; - - cv::sqrt(src, dst); - - TEST_CYCLE() - { - cv::sqrt(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Sqrt, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Log - -GPU_PERF_TEST(Log, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 1.0, 100.0); - - cv::Mat dst; - - cv::log(src, dst); - - TEST_CYCLE() - { - cv::log(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Log, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Exp - -GPU_PERF_TEST(Exp, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 1.0, 10.0); - - cv::Mat dst; - - cv::exp(src, dst); - - TEST_CYCLE() - { - cv::exp(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Exp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Pow - -GPU_PERF_TEST(Pow, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 1.0, 10.0); - - cv::Mat dst; - - cv::pow(src, 2.3, dst); - - TEST_CYCLE() - { - cv::pow(src, 2.3, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Pow, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16S, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Compare_Mat - -CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE) -#define ALL_CMP_CODES testing::Values(CmpCode(cv::CMP_EQ), CmpCode(cv::CMP_NE), CmpCode(cv::CMP_GT), CmpCode(cv::CMP_GE), CmpCode(cv::CMP_LT), CmpCode(cv::CMP_LE)) - -GPU_PERF_TEST(Compare_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int cmp_code = GET_PARAM(3); - - cv::Mat src1(size, depth); - fill(src1, 0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 100.0); - - cv::Mat dst; - - cv::compare(src1, src2, dst, cmp_code); - - TEST_CYCLE() - { - cv::compare(src1, src2, dst, cmp_code); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Compare_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - ALL_CMP_CODES)); - -////////////////////////////////////////////////////////////////////// -// Compare_Scalar - -GPU_PERF_TEST(Compare_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, CmpCode) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int cmp_code = GET_PARAM(3); - - cv::Mat src(size, depth); - fill(src, 0, 100.0); - - cv::Scalar s = cv::Scalar::all(50); - cv::Mat dst; - - cv::compare(src, s, dst, cmp_code); - - TEST_CYCLE() - { - cv::compare(src, s, dst, cmp_code); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Compare_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - ALL_CMP_CODES)); - -////////////////////////////////////////////////////////////////////// -// Bitwise_Not - -GPU_PERF_TEST(Bitwise_Not, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0, 100.0); - - cv::Mat dst; - - cv::bitwise_not(src, dst); - - TEST_CYCLE() - { - cv::bitwise_not(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Not, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_And_Mat - -GPU_PERF_TEST(Bitwise_And_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 100.0); - - cv::Mat dst; - - cv::bitwise_and(src1, src2, dst); - - TEST_CYCLE() - { - cv::bitwise_and(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_And_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_And_Scalar - -GPU_PERF_TEST(Bitwise_And_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - fill(src, 0, 100.0); - - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::Mat dst; - - cv::bitwise_and(src, s, dst); - - TEST_CYCLE() - { - cv::bitwise_and(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_And_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_Or_Mat - -GPU_PERF_TEST(Bitwise_Or_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 100.0); - - cv::Mat dst; - - cv::bitwise_or(src1, src2, dst); - - TEST_CYCLE() - { - cv::bitwise_or(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Or_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_Or_Scalar - -GPU_PERF_TEST(Bitwise_Or_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - fill(src, 0, 100.0); - - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::Mat dst; - - cv::bitwise_or(src, s, dst); - - TEST_CYCLE() - { - cv::bitwise_or(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Or_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_Xor_Mat - -GPU_PERF_TEST(Bitwise_Xor_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0, 100.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 100.0); - - cv::Mat dst; - - cv::bitwise_xor(src1, src2, dst); - - TEST_CYCLE() - { - cv::bitwise_xor(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Xor_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S))); - -////////////////////////////////////////////////////////////////////// -// Bitwise_Xor_Scalar - -GPU_PERF_TEST(Bitwise_Xor_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - - int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - fill(src, 0, 100.0); - - cv::Scalar s = cv::Scalar(50, 50, 50, 50); - cv::Mat dst; - - cv::bitwise_xor(src, s, dst); - - TEST_CYCLE() - { - cv::bitwise_xor(src, s, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Bitwise_Xor_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S), - testing::Values(1, 3, 4))); - -////////////////////////////////////////////////////////////////////// -// Min_Mat - -GPU_PERF_TEST(Min_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0, 255.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 255.0); - - cv::Mat dst; - - cv::min(src1, src2, dst); - - TEST_CYCLE() - { - cv::min(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Min_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Min_Scalar - -GPU_PERF_TEST(Min_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0, 255.0); - - double val = 50.0; - cv::Mat dst; - - cv::min(src, val, dst); - - TEST_CYCLE() - { - cv::min(src, val, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Min_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Max_Mat - -GPU_PERF_TEST(Max_Mat, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src1(size, depth); - fill(src1, 0, 255.0); - - cv::Mat src2(size, depth); - fill(src2, 0, 255.0); - - cv::Mat dst; - - cv::max(src1, src2, dst); - - TEST_CYCLE() - { - cv::max(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Max_Mat, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// Max_Scalar - -GPU_PERF_TEST(Max_Scalar, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0, 255.0); - - double val = 50.0; - cv::Mat dst; - - cv::max(src, val, dst); - - TEST_CYCLE() - { - cv::max(src, val, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Max_Scalar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F))); - -////////////////////////////////////////////////////////////////////// -// AddWeighted - -GPU_PERF_TEST(AddWeighted, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth1 = GET_PARAM(2); - int depth2 = GET_PARAM(3); - int dst_depth = GET_PARAM(4); - - cv::Mat src1(size, depth1); - fill(src1, 0, 100.0); - - cv::Mat src2(size, depth2); - fill(src2, 0, 100.0); - - cv::Mat dst; - - cv::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); - - TEST_CYCLE() - { - cv::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth); - } -} - -INSTANTIATE_TEST_CASE_P(Core, AddWeighted, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F), - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// GEMM - -CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T) -#define ALL_GEMM_FLAGS testing::Values(GemmFlags(0), GemmFlags(cv::GEMM_1_T), GemmFlags(cv::GEMM_2_T), GemmFlags(cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_3_T), GemmFlags(cv::GEMM_1_T | cv::GEMM_2_T | cv::GEMM_3_T)) - -GPU_PERF_TEST(GEMM, cv::gpu::DeviceInfo, cv::Size, MatType, GemmFlags) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int flags = GET_PARAM(3); - - cv::Mat src1(size, type); - fill(src1, 0.0, 10.0); - - cv::Mat src2(size, type); - fill(src2, 0.0, 10.0); - - cv::Mat src3(size, type); - fill(src3, 0.0, 10.0); - - cv::Mat dst; - - cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); - - declare.time(50.0); - - TEST_CYCLE() - { - cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); - } -} - -INSTANTIATE_TEST_CASE_P(Core, GEMM, testing::Combine( - ALL_DEVICES, - testing::Values(cv::Size(512, 512), cv::Size(1024, 1024)), - testing::Values(CV_32FC1, CV_32FC2, CV_64FC1, CV_64FC2), - ALL_GEMM_FLAGS)); - -////////////////////////////////////////////////////////////////////// -// Transpose - -GPU_PERF_TEST(Transpose, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 100.0); - - cv::Mat dst; - - cv::transpose(src, dst); - - TEST_CYCLE() - { - cv::transpose(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Transpose, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_16SC2, CV_32SC1, CV_32SC2, CV_64FC1))); - -////////////////////////////////////////////////////////////////////// -// Flip - -enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1}; -CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y) -#define ALL_FLIP_CODES testing::Values(FlipCode(FLIP_BOTH), FlipCode(FLIP_X), FlipCode(FLIP_Y)) - -GPU_PERF_TEST(Flip, cv::gpu::DeviceInfo, cv::Size, MatType, FlipCode) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int flipCode = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 100.0); - - cv::Mat dst; - - cv::flip(src, dst, flipCode); - - TEST_CYCLE() - { - cv::flip(src, dst, flipCode); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Flip, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4), - ALL_FLIP_CODES)); - -////////////////////////////////////////////////////////////////////// -// LUT_OneChannel - -GPU_PERF_TEST(LUT_OneChannel, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 100.0); - - cv::Mat lut(1, 256, CV_8UC1); - fill(lut, 0.0, 100.0); - - cv::Mat dst; - - cv::LUT(src, lut, dst); - - TEST_CYCLE() - { - cv::LUT(src, lut, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, LUT_OneChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3))); - -////////////////////////////////////////////////////////////////////// -// LUT_MultiChannel - -GPU_PERF_TEST(LUT_MultiChannel, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 100.0); - - cv::Mat lut(1, 256, CV_MAKE_TYPE(CV_8U, src.channels())); - fill(lut, 0.0, 100.0); - - cv::Mat dst; - - cv::LUT(src, lut, dst); - - TEST_CYCLE() - { - cv::LUT(src, lut, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, LUT_MultiChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC3))); - -////////////////////////////////////////////////////////////////////// -// Magnitude_Complex - -GPU_PERF_TEST(Magnitude_Complex, cv::gpu::DeviceInfo, cv::Size) -{ - cv::Size size = GET_PARAM(1); - - cv::Mat src(size, CV_32FC2); - fill(src, -100.0, 100.0); - - cv::Mat srcs[2]; - cv::split(src, srcs); - - cv::Mat dst; - - cv::magnitude(srcs[0], srcs[1], dst); - - TEST_CYCLE() - { - cv::magnitude(srcs[0], srcs[1], dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Magnitude_Complex, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - -////////////////////////////////////////////////////////////////////// -// Magnitude - -GPU_PERF_TEST(Magnitude, cv::gpu::DeviceInfo, cv::Size) -{ - cv::Size size = GET_PARAM(1); - - cv::Mat src1(size, CV_32FC1); - fill(src1, -100.0, 100.0); - - cv::Mat src2(size, CV_32FC1); - fill(src2, -100.0, 100.0); - - cv::Mat dst; - - cv::magnitude(src1, src2, dst); - - TEST_CYCLE() - { - cv::magnitude(src1, src2, dst); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Magnitude, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - -////////////////////////////////////////////////////////////////////// -// Phase - -IMPLEMENT_PARAM_CLASS(AngleInDegrees, bool) - -GPU_PERF_TEST(Phase, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) -{ - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); - - cv::Mat src1(size, CV_32FC1); - fill(src1, -100.0, 100.0); - - cv::Mat src2(size, CV_32FC1); - fill(src2, -100.0, 100.0); - - cv::Mat dst; - - cv::phase(src1, src2, dst, angleInDegrees); - - TEST_CYCLE() - { - cv::phase(src1, src2, dst, angleInDegrees); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Phase, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - -////////////////////////////////////////////////////////////////////// -// CartToPolar - -GPU_PERF_TEST(CartToPolar, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) -{ - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); - - cv::Mat src1(size, CV_32FC1); - fill(src1, -100.0, 100.0); - - cv::Mat src2(size, CV_32FC1); - fill(src2, -100.0, 100.0); - - cv::Mat magnitude; - cv::Mat angle; - - cv::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); - - TEST_CYCLE() - { - cv::cartToPolar(src1, src2, magnitude, angle, angleInDegrees); - } -} - -INSTANTIATE_TEST_CASE_P(Core, CartToPolar, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - -////////////////////////////////////////////////////////////////////// -// PolarToCart - -GPU_PERF_TEST(PolarToCart, cv::gpu::DeviceInfo, cv::Size, AngleInDegrees) -{ - cv::Size size = GET_PARAM(1); - bool angleInDegrees = GET_PARAM(2); - - cv::Mat magnitude(size, CV_32FC1); - fill(magnitude, 0.0, 100.0); - - cv::Mat angle(size, CV_32FC1); - fill(angle, 0.0, angleInDegrees ? 360.0 : 2 * CV_PI); - - cv::Mat x; - cv::Mat y; - - cv::polarToCart(magnitude, angle, x, y, angleInDegrees); - - TEST_CYCLE() - { - cv::polarToCart(magnitude, angle, x, y, angleInDegrees); - } -} - -INSTANTIATE_TEST_CASE_P(Core, PolarToCart, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(false, true))); - -////////////////////////////////////////////////////////////////////// -// MeanStdDev - -GPU_PERF_TEST(MeanStdDev, cv::gpu::DeviceInfo, cv::Size) -{ - cv::Size size = GET_PARAM(1); - - cv::Mat src(size, CV_8UC1); - fill(src, 0.0, 255.0); - - cv::Scalar mean; - cv::Scalar stddev; - - cv::meanStdDev(src, mean, stddev); - - TEST_CYCLE() - { - cv::meanStdDev(src, mean, stddev); - } -} - -INSTANTIATE_TEST_CASE_P(Core, MeanStdDev, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - -////////////////////////////////////////////////////////////////////// -// Norm - -GPU_PERF_TEST(Norm, cv::gpu::DeviceInfo, cv::Size, MatDepth, NormType) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int normType = GET_PARAM(3); - - cv::Mat src(size, depth); - fill(src, 0.0, 255.0); - - double dst; - cv::Mat buf; - - dst = cv::norm(src, normType); - - TEST_CYCLE() - { - dst = cv::norm(src, normType); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Norm, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32S, CV_32F), - testing::Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))); - -////////////////////////////////////////////////////////////////////// -// NormDiff - -GPU_PERF_TEST(NormDiff, cv::gpu::DeviceInfo, cv::Size, NormType) -{ - cv::Size size = GET_PARAM(1); - int normType = GET_PARAM(2); - - cv::Mat src1(size, CV_8UC1); - fill(src1, 0.0, 255.0); - - cv::Mat src2(size, CV_8UC1); - fill(src2, 0.0, 255.0); - - double dst; - - dst = cv::norm(src1, src2, normType); - - TEST_CYCLE() - { - dst = cv::norm(src1, src2, normType); - } -} - -INSTANTIATE_TEST_CASE_P(Core, NormDiff, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(NormType(cv::NORM_INF), NormType(cv::NORM_L1), NormType(cv::NORM_L2)))); - -////////////////////////////////////////////////////////////////////// -// Sum - -GPU_PERF_TEST(Sum, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Scalar dst; - - dst = cv::sum(src); - - TEST_CYCLE() - { - dst = cv::sum(src); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Sum, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4))); - -////////////////////////////////////////////////////////////////////// -// MinMaxLoc - -GPU_PERF_TEST(MinMaxLoc, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 255.0); - - double minVal, maxVal; - cv::Point minLoc, maxLoc; - - cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc); - - TEST_CYCLE() - { - cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc); - } -} - -INSTANTIATE_TEST_CASE_P(Core, MinMaxLoc, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// CountNonZero - -GPU_PERF_TEST(CountNonZero, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0.0, 1.5); - - int dst; - - dst = cv::countNonZero(src); - - TEST_CYCLE() - { - dst = cv::countNonZero(src); - } -} - -INSTANTIATE_TEST_CASE_P(Core, CountNonZero, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_32F, CV_64F))); - -////////////////////////////////////////////////////////////////////// -// Reduce - -CV_ENUM(ReduceCode, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) -#define ALL_REDUCE_CODES testing::Values(CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN) - -enum {Rows = 0, Cols = 1}; -CV_ENUM(ReduceDim, Rows, Cols) - -GPU_PERF_TEST(Reduce, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, ReduceCode, ReduceDim) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int channels = GET_PARAM(3); - int reduceOp = GET_PARAM(4); - int dim = GET_PARAM(5); - - int type = CV_MAKE_TYPE(depth, channels); - - cv::Mat src(size, type); - fill(src, 0.0, 10.0); - - cv::Mat dst; - - cv::reduce(src, dst, dim, reduceOp); - - TEST_CYCLE() - { - cv::reduce(src, dst, dim, reduceOp); - } -} - -INSTANTIATE_TEST_CASE_P(Core, Reduce, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(CV_8U, CV_16U, CV_16S, CV_32F), - testing::Values(1, 2, 3, 4), - ALL_REDUCE_CODES, - testing::Values(ReduceDim(Rows), ReduceDim(Cols)))); - -#endif diff --git a/modules/gpu/perf_cpu/perf_cpu_precomp.cpp b/modules/gpu/perf_cpu/perf_cpu_precomp.cpp deleted file mode 100644 index d947dd025..000000000 --- a/modules/gpu/perf_cpu/perf_cpu_precomp.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "perf_cpu_precomp.hpp" diff --git a/modules/gpu/perf_cpu/perf_cpu_precomp.hpp b/modules/gpu/perf_cpu/perf_cpu_precomp.hpp deleted file mode 100644 index 12680c7a0..000000000 --- a/modules/gpu/perf_cpu/perf_cpu_precomp.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef __GNUC__ -# pragma GCC diagnostic ignored "-Wmissing-declarations" -# pragma GCC diagnostic ignored "-Wmissing-prototypes" //OSX -#endif - -#ifndef __OPENCV_PERF_CPU_PRECOMP_HPP__ -#define __OPENCV_PERF_CPU_PRECOMP_HPP__ - -#include -#include - -#include "cvconfig.h" - -#include "opencv2/ts/ts.hpp" -#include "opencv2/ts/ts_perf.hpp" - -#include "opencv2/core/core.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/gpu/gpu.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/video/video.hpp" -#include "opencv2/calib3d/calib3d.hpp" -#include "opencv2/nonfree/nonfree.hpp" -#include "opencv2/legacy/legacy.hpp" - -#include "perf_utility.hpp" - -#ifdef GTEST_CREATE_SHARED_LIBRARY -#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined -#endif - -#endif diff --git a/modules/gpu/perf_cpu/perf_features2d.cpp b/modules/gpu/perf_cpu/perf_features2d.cpp deleted file mode 100644 index 74579a64a..000000000 --- a/modules/gpu/perf_cpu/perf_features2d.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////////////////////// -// SURF - -GPU_PERF_TEST_1(SURF, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - cv::SURF surf; - - std::vector keypoints; - cv::Mat descriptors; - - surf(img, cv::noArray(), keypoints, descriptors); - - declare.time(50.0); - - TEST_CYCLE() - { - keypoints.clear(); - surf(img, cv::noArray(), keypoints, descriptors); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, SURF, ALL_DEVICES); - -////////////////////////////////////////////////////////////////////// -// FAST - -GPU_PERF_TEST_1(FAST, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - std::vector keypoints; - - cv::FAST(img, keypoints, 20); - - TEST_CYCLE() - { - keypoints.clear(); - cv::FAST(img, keypoints, 20); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, FAST, ALL_DEVICES); - -////////////////////////////////////////////////////////////////////// -// ORB - -GPU_PERF_TEST_1(ORB, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - cv::ORB orb(4000); - - std::vector keypoints; - cv::Mat descriptors; - - orb(img, cv::noArray(), keypoints, descriptors); - - TEST_CYCLE() - { - keypoints.clear(); - orb(img, cv::noArray(), keypoints, descriptors); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, ORB, ALL_DEVICES); - -////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_match - -IMPLEMENT_PARAM_CLASS(DescriptorSize, int) - -GPU_PERF_TEST(BruteForceMatcher_match, cv::gpu::DeviceInfo, DescriptorSize, NormType) -{ - int desc_size = GET_PARAM(1); - int normType = GET_PARAM(2); - - int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - - cv::Mat query(3000, desc_size, type); - fill(query, 0.0, 10.0); - - cv::Mat train(3000, desc_size, type); - fill(train, 0.0, 10.0); - - cv::BFMatcher matcher(normType); - - std::vector matches; - - matcher.match(query, train, matches); - - declare.time(20.0); - - TEST_CYCLE() - { - matcher.match(query, train, matches); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_match, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - -////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_knnMatch - -IMPLEMENT_PARAM_CLASS(K, int) - -GPU_PERF_TEST(BruteForceMatcher_knnMatch, cv::gpu::DeviceInfo, DescriptorSize, K, NormType) -{ - int desc_size = GET_PARAM(1); - int k = GET_PARAM(2); - int normType = GET_PARAM(3); - - int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - - cv::Mat query(3000, desc_size, type); - fill(query, 0.0, 10.0); - - cv::Mat train(3000, desc_size, type); - fill(train, 0.0, 10.0); - - cv::BFMatcher matcher(normType); - - std::vector< std::vector > matches; - - matcher.knnMatch(query, train, matches, k); - - declare.time(30.0); - - TEST_CYCLE() - { - matcher.knnMatch(query, train, matches, k); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_knnMatch, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(K(2), K(3)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - -////////////////////////////////////////////////////////////////////// -// BruteForceMatcher_radiusMatch - -GPU_PERF_TEST(BruteForceMatcher_radiusMatch, cv::gpu::DeviceInfo, DescriptorSize, NormType) -{ - int desc_size = GET_PARAM(1); - int normType = GET_PARAM(2); - - int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; - - cv::Mat query(3000, desc_size, type); - fill(query, 0.0, 1.0); - - cv::Mat train(3000, desc_size, type); - fill(train, 0.0, 1.0); - - cv::BFMatcher matcher(normType); - - std::vector< std::vector > matches; - - matcher.radiusMatch(query, train, matches, 2.0); - - declare.time(30.0); - - TEST_CYCLE() - { - matcher.radiusMatch(query, train, matches, 2.0); - } -} - -INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_radiusMatch, testing::Combine( - ALL_DEVICES, - testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)), - testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING)))); - -#endif diff --git a/modules/gpu/perf_cpu/perf_filters.cpp b/modules/gpu/perf_cpu/perf_filters.cpp deleted file mode 100644 index ab0be3bad..000000000 --- a/modules/gpu/perf_cpu/perf_filters.cpp +++ /dev/null @@ -1,283 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -IMPLEMENT_PARAM_CLASS(KernelSize, int) - -////////////////////////////////////////////////////////////////////// -// Blur - -GPU_PERF_TEST(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::blur(src, dst, cv::Size(ksize, ksize)); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::blur(src, dst, cv::Size(ksize, ksize)); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Blur, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7)))); - -////////////////////////////////////////////////////////////////////// -// Sobel - -GPU_PERF_TEST(Sobel, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::Sobel(src, dst, -1, 1, 1, ksize); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::Sobel(src, dst, -1, 1, 1, ksize); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Sobel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - -////////////////////////////////////////////////////////////////////// -// Scharr - -GPU_PERF_TEST(Scharr, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::Scharr(src, dst, -1, 1, 0); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::Scharr(src, dst, -1, 1, 0); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Scharr, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)))); - -////////////////////////////////////////////////////////////////////// -// GaussianBlur - -GPU_PERF_TEST(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::GaussianBlur(src, dst, cv::Size(ksize, ksize), 0.5); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::GaussianBlur(src, dst, cv::Size(ksize, ksize), 0.5); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, GaussianBlur, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - -////////////////////////////////////////////////////////////////////// -// Laplacian - -GPU_PERF_TEST(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::Laplacian(src, dst, -1, ksize); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::Laplacian(src, dst, -1, ksize); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Laplacian, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)), - testing::Values(KernelSize(1), KernelSize(3)))); - -////////////////////////////////////////////////////////////////////// -// Erode - -GPU_PERF_TEST(Erode, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - - cv::Mat dst; - - cv::erode(src, dst, ker); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::erode(src, dst, ker); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Erode, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); - -////////////////////////////////////////////////////////////////////// -// Dilate - -GPU_PERF_TEST(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - - cv::Mat dst; - - cv::dilate(src, dst, ker); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::dilate(src, dst, ker); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Dilate, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); - -////////////////////////////////////////////////////////////////////// -// MorphologyEx - -CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT) -#define ALL_MORPH_OPS testing::Values(MorphOp(cv::MORPH_OPEN), MorphOp(cv::MORPH_CLOSE), MorphOp(cv::MORPH_GRADIENT), MorphOp(cv::MORPH_TOPHAT), MorphOp(cv::MORPH_BLACKHAT)) - -GPU_PERF_TEST(MorphologyEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int morphOp = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat dst; - - cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); - - cv::morphologyEx(src, dst, morphOp, ker); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::morphologyEx(src, dst, morphOp, ker); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, MorphologyEx, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), - ALL_MORPH_OPS)); - -////////////////////////////////////////////////////////////////////// -// Filter2D - -GPU_PERF_TEST(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int ksize = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0.0, 255.0); - - cv::Mat kernel(ksize, ksize, CV_32FC1); - fill(kernel, 0.0, 1.0); - - cv::Mat dst; - - cv::filter2D(src, dst, -1, kernel); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::filter2D(src, dst, -1, kernel); - } -} - -INSTANTIATE_TEST_CASE_P(Filters, Filter2D, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)), - testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15)))); - -#endif diff --git a/modules/gpu/perf_cpu/perf_imgproc.cpp b/modules/gpu/perf_cpu/perf_imgproc.cpp deleted file mode 100644 index 1b3c0951c..000000000 --- a/modules/gpu/perf_cpu/perf_imgproc.cpp +++ /dev/null @@ -1,771 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////////////////////// -// Remap - -GPU_PERF_TEST(Remap, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = GET_PARAM(3); - int borderMode = GET_PARAM(4); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat xmap(size, CV_32FC1); - fill(xmap, 0, size.width); - - cv::Mat ymap(size, CV_32FC1); - fill(ymap, 0, size.height); - - cv::Mat dst; - - cv::remap(src, dst, xmap, ymap, interpolation, borderMode); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::remap(src, dst, xmap, ymap, interpolation, borderMode); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Remap, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - - -////////////////////////////////////////////////////////////////////// -// Resize - -IMPLEMENT_PARAM_CLASS(Scale, double) - -GPU_PERF_TEST(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, Scale) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = GET_PARAM(3); - double f = GET_PARAM(4); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - cv::resize(src, dst, cv::Size(), f, f, interpolation); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::resize(src, dst, cv::Size(), f, f, interpolation); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Resize, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), - Interpolation(cv::INTER_CUBIC), Interpolation(cv::INTER_AREA)), - testing::Values(Scale(0.5), Scale(0.3), Scale(2.0)))); - -GPU_PERF_TEST(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, Scale) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = cv::INTER_AREA; - double f = GET_PARAM(3); - - cv::Mat src_host(size, type); - fill(src_host, 0, 255); - - cv::Mat src(src_host); - cv::Mat dst; - - cv::resize(src, dst, cv::Size(), f, f, interpolation); - - declare.time(1.0); - - TEST_CYCLE() - { - cv::resize(src, dst, cv::Size(), f, f, interpolation); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, ResizeArea, testing::Combine( - ALL_DEVICES, - testing::Values(perf::sz1080p, cv::Size(4096, 2048)), - testing::Values(MatType(CV_8UC1)/*, MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)*/), - testing::Values(Scale(0.2),Scale(0.1),Scale(0.05)))); - -////////////////////////////////////////////////////////////////////// -// WarpAffine - -GPU_PERF_TEST(WarpAffine, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = GET_PARAM(3); - int borderMode = GET_PARAM(4); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - const double aplha = CV_PI / 4; - double mat[2][3] = { {std::cos(aplha), -std::sin(aplha), src.cols / 2}, - {std::sin(aplha), std::cos(aplha), 0}}; - cv::Mat M(2, 3, CV_64F, (void*) mat); - - cv::warpAffine(src, dst, M, size, interpolation, borderMode); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::warpAffine(src, dst, M, size, interpolation, borderMode); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, WarpAffine, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - -////////////////////////////////////////////////////////////////////// -// WarpPerspective - -GPU_PERF_TEST(WarpPerspective, cv::gpu::DeviceInfo, cv::Size, MatType, Interpolation, BorderMode) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int interpolation = GET_PARAM(3); - int borderMode = GET_PARAM(4); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - 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}}; - cv::Mat M(3, 3, CV_64F, (void*) mat); - - cv::warpPerspective(src, dst, M, size, interpolation, borderMode); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::warpPerspective(src, dst, M, size, interpolation, borderMode); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, WarpPerspective, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - -////////////////////////////////////////////////////////////////////// -// CopyMakeBorder - -GPU_PERF_TEST(CopyMakeBorder, cv::gpu::DeviceInfo, cv::Size, MatType, BorderMode) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - int borderType = GET_PARAM(3); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderType); - - TEST_CYCLE() - { - cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderType); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, CopyMakeBorder, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_CONSTANT), BorderMode(cv::BORDER_REFLECT), BorderMode(cv::BORDER_WRAP)))); - -////////////////////////////////////////////////////////////////////// -// Threshold - -CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV) -#define ALL_THRESH_OPS testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV)) - -GPU_PERF_TEST(Threshold, cv::gpu::DeviceInfo, cv::Size, MatDepth, ThreshOp) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - int threshOp = GET_PARAM(3); - - cv::Mat src(size, depth); - fill(src, 0, 255); - - cv::Mat dst; - - cv::threshold(src, dst, 100.0, 255.0, threshOp); - - TEST_CYCLE() - { - cv::threshold(src, dst, 100.0, 255.0, threshOp); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Threshold, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)), - ALL_THRESH_OPS)); - -////////////////////////////////////////////////////////////////////// -// Integral - -GPU_PERF_TEST(Integral, cv::gpu::DeviceInfo, cv::Size) -{ - cv::Size size = GET_PARAM(1); - - cv::Mat src(size, CV_8UC1); - fill(src, 0, 255); - - cv::Mat dst; - - cv::integral(src, dst); - - TEST_CYCLE() - { - cv::integral(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Integral, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - -////////////////////////////////////////////////////////////////////// -// HistEven_OneChannel - -GPU_PERF_TEST(HistEven_OneChannel, cv::gpu::DeviceInfo, cv::Size, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - - cv::Mat src(size, depth); - fill(src, 0, 255); - - int hbins = 30; - float hranges[] = {0.0f, 180.0f}; - cv::Mat hist; - int histSize[] = {hbins}; - const float* ranges[] = {hranges}; - int channels[] = {0}; - - cv::calcHist(&src, 1, channels, cv::Mat(), hist, 1, histSize, ranges); - - TEST_CYCLE() - { - cv::calcHist(&src, 1, channels, cv::Mat(), hist, 1, histSize, ranges); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, HistEven_OneChannel, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_16S)))); - -////////////////////////////////////////////////////////////////////// -// EqualizeHist - -GPU_PERF_TEST(EqualizeHist, cv::gpu::DeviceInfo, cv::Size) -{ - cv::Size size = GET_PARAM(1); - - cv::Mat src(size, CV_8UC1); - fill(src, 0, 255); - - cv::Mat dst; - - cv::equalizeHist(src, dst); - - TEST_CYCLE() - { - cv::equalizeHist(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, EqualizeHist, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES)); - -////////////////////////////////////////////////////////////////////// -// Canny - -IMPLEMENT_PARAM_CLASS(AppertureSize, int) -IMPLEMENT_PARAM_CLASS(L2gradient, bool) - -GPU_PERF_TEST(Canny, cv::gpu::DeviceInfo, AppertureSize, L2gradient) -{ - int apperture_size = GET_PARAM(1); - bool useL2gradient = GET_PARAM(2); - - cv::Mat image = readImage("perf/1280x1024.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - cv::Mat dst; - - cv::Canny(image, dst, 50.0, 100.0, apperture_size, useL2gradient); - - TEST_CYCLE() - { - cv::Canny(image, dst, 50.0, 100.0, apperture_size, useL2gradient); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine( - ALL_DEVICES, - testing::Values(AppertureSize(3), AppertureSize(5)), - testing::Values(L2gradient(false), L2gradient(true)))); - -////////////////////////////////////////////////////////////////////// -// MeanShiftFiltering - -GPU_PERF_TEST_1(MeanShiftFiltering, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/meanshift/cones.png"); - ASSERT_FALSE(img.empty()); - - cv::Mat dst; - - cv::pyrMeanShiftFiltering(img, dst, 50, 50); - - declare.time(15.0); - - TEST_CYCLE() - { - cv::pyrMeanShiftFiltering(img, dst, 50, 50); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, MeanShiftFiltering, ALL_DEVICES); - -////////////////////////////////////////////////////////////////////// -// Convolve - -IMPLEMENT_PARAM_CLASS(KSize, int) -IMPLEMENT_PARAM_CLASS(Ccorr, bool) - -GPU_PERF_TEST(Convolve, cv::gpu::DeviceInfo, cv::Size, KSize, Ccorr) -{ - cv::Size size = GET_PARAM(1); - int templ_size = GET_PARAM(2); - bool ccorr = GET_PARAM(3); - - ASSERT_FALSE(ccorr); - - cv::Mat image(size, CV_32FC1); - image.setTo(1.0); - - cv::Mat templ(templ_size, templ_size, CV_32FC1); - templ.setTo(1.0); - - cv::Mat dst; - - cv::filter2D(image, dst, image.depth(), templ); - - declare.time(10.0); - - TEST_CYCLE() - { - cv::filter2D(image, dst, image.depth(), templ); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Convolve, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(KSize(3), KSize(9), KSize(17), KSize(27), KSize(32), KSize(64)), - testing::Values(Ccorr(false), Ccorr(true)))); - -//////////////////////////////////////////////////////////////////////////////// -// MatchTemplate_8U - -CV_ENUM(TemplateMethod, cv::TM_SQDIFF, cv::TM_SQDIFF_NORMED, cv::TM_CCORR, cv::TM_CCORR_NORMED, cv::TM_CCOEFF, cv::TM_CCOEFF_NORMED) -#define ALL_TEMPLATE_METHODS testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_SQDIFF_NORMED), TemplateMethod(cv::TM_CCORR), TemplateMethod(cv::TM_CCORR_NORMED), TemplateMethod(cv::TM_CCOEFF), TemplateMethod(cv::TM_CCOEFF_NORMED)) - -IMPLEMENT_PARAM_CLASS(TemplateSize, cv::Size) - -GPU_PERF_TEST(MatchTemplate_8U, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Channels, TemplateMethod) -{ - cv::Size size = GET_PARAM(1); - cv::Size templ_size = GET_PARAM(2); - int cn = GET_PARAM(3); - int method = GET_PARAM(4); - - cv::Mat image(size, CV_MAKE_TYPE(CV_8U, cn)); - fill(image, 0, 255); - - cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_8U, cn)); - fill(templ, 0, 255); - - cv::Mat dst; - - cv::matchTemplate(image, templ, dst, method); - - TEST_CYCLE() - { - cv::matchTemplate(image, templ, dst, method); - } -}; - -INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate_8U, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))), - testing::Values(Channels(1), Channels(3), Channels(4)), - ALL_TEMPLATE_METHODS)); - -//////////////////////////////////////////////////////////////////////////////// -// MatchTemplate_32F - -GPU_PERF_TEST(MatchTemplate_32F, cv::gpu::DeviceInfo, cv::Size, TemplateSize, Channels, TemplateMethod) -{ - cv::Size size = GET_PARAM(1); - cv::Size templ_size = GET_PARAM(2); - int cn = GET_PARAM(3); - int method = GET_PARAM(4); - - cv::Mat image(size, CV_MAKE_TYPE(CV_32F, cn)); - fill(image, 0, 255); - - cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_32F, cn)); - fill(templ, 0, 255); - - cv::Mat dst; - - cv::matchTemplate(image, templ, dst, method); - - TEST_CYCLE() - { - cv::matchTemplate(image, templ, dst, method); - } -}; - -INSTANTIATE_TEST_CASE_P(ImgProc, MatchTemplate_32F, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(TemplateSize(cv::Size(5, 5)), TemplateSize(cv::Size(16, 16)), TemplateSize(cv::Size(30, 30))), - testing::Values(Channels(1), Channels(3), Channels(4)), - testing::Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR)))); - -////////////////////////////////////////////////////////////////////// -// MulSpectrums - -CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT) - -GPU_PERF_TEST(MulSpectrums, cv::gpu::DeviceInfo, cv::Size, DftFlags) -{ - cv::Size size = GET_PARAM(1); - int flag = GET_PARAM(2); - - cv::Mat a(size, CV_32FC2); - fill(a, 0, 100); - - cv::Mat b(size, CV_32FC2); - fill(b, 0, 100); - - cv::Mat dst; - - cv::mulSpectrums(a, b, dst, flag); - - TEST_CYCLE() - { - cv::mulSpectrums(a, b, dst, flag); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, MulSpectrums, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS)))); - -////////////////////////////////////////////////////////////////////// -// Dft - -GPU_PERF_TEST(Dft, cv::gpu::DeviceInfo, cv::Size, DftFlags) -{ - cv::Size size = GET_PARAM(1); - int flag = GET_PARAM(2); - - cv::Mat src(size, CV_32FC2); - fill(src, 0, 100); - - cv::Mat dst; - - cv::dft(src, dst, flag); - - declare.time(10.0); - - TEST_CYCLE() - { - cv::dft(src, dst, flag); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, Dft, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DftFlags(0), DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))); - -////////////////////////////////////////////////////////////////////// -// CornerHarris - -IMPLEMENT_PARAM_CLASS(BlockSize, int) -IMPLEMENT_PARAM_CLASS(ApertureSize, int) - -GPU_PERF_TEST(CornerHarris, cv::gpu::DeviceInfo, MatType, BorderMode, BlockSize, ApertureSize) -{ - int type = GET_PARAM(1); - int borderType = GET_PARAM(2); - int blockSize = GET_PARAM(3); - int apertureSize = GET_PARAM(4); - - cv::Mat img = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); - - cv::Mat dst; - - double k = 0.5; - - cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderType); - - TEST_CYCLE() - { - cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderType); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, CornerHarris, testing::Combine( - ALL_DEVICES, - testing::Values(MatType(CV_8UC1), MatType(CV_32FC1)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - testing::Values(BlockSize(3), BlockSize(5), BlockSize(7)), - testing::Values(ApertureSize(0), ApertureSize(3), ApertureSize(5), ApertureSize(7)))); - -////////////////////////////////////////////////////////////////////// -// CornerMinEigenVal - -GPU_PERF_TEST(CornerMinEigenVal, cv::gpu::DeviceInfo, MatType, BorderMode, BlockSize, ApertureSize) -{ - int type = GET_PARAM(1); - int borderType = GET_PARAM(2); - int blockSize = GET_PARAM(3); - int apertureSize = GET_PARAM(4); - - cv::Mat img = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0); - - cv::Mat dst; - - cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderType); - - TEST_CYCLE() - { - cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderType); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, CornerMinEigenVal, testing::Combine( - ALL_DEVICES, - testing::Values(MatType(CV_8UC1), MatType(CV_32FC1)), - testing::Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)), - testing::Values(BlockSize(3), BlockSize(5), BlockSize(7)), - testing::Values(ApertureSize(0), ApertureSize(3), ApertureSize(5), ApertureSize(7)))); - -////////////////////////////////////////////////////////////////////// -// PyrDown - -GPU_PERF_TEST(PyrDown, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - cv::pyrDown(src, dst); - - TEST_CYCLE() - { - cv::pyrDown(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, PyrDown, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - -////////////////////////////////////////////////////////////////////// -// PyrUp - -GPU_PERF_TEST(PyrUp, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat dst; - - cv::pyrUp(src, dst); - - TEST_CYCLE() - { - cv::pyrUp(src, dst); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, PyrUp, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)))); - -////////////////////////////////////////////////////////////////////// -// CvtColor - -GPU_PERF_TEST(CvtColor, cv::gpu::DeviceInfo, cv::Size, MatDepth, CvtColorInfo) -{ - cv::Size size = GET_PARAM(1); - int depth = GET_PARAM(2); - CvtColorInfo info = GET_PARAM(3); - - cv::Mat src(size, CV_MAKETYPE(depth, info.scn)); - fill(src, 0, 255); - - cv::Mat dst; - - cv::cvtColor(src, dst, info.code, info.dcn); - - TEST_CYCLE() - { - cv::cvtColor(src, dst, info.code, info.dcn); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F)), - testing::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_RGB2Lab), - CvtColorInfo(3, 3, cv::COLOR_BGR2Luv), - CvtColorInfo(3, 3, cv::COLOR_RGB2Luv), - CvtColorInfo(3, 3, cv::COLOR_Lab2BGR), - CvtColorInfo(3, 3, cv::COLOR_Lab2RGB), - CvtColorInfo(3, 3, cv::COLOR_Luv2BGR), - CvtColorInfo(3, 3, cv::COLOR_Luv2RGB), - 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(4, 4, cv::COLOR_RGBA2mRGBA)))); - -////////////////////////////////////////////////////////////////////// -// HoughLines - -IMPLEMENT_PARAM_CLASS(DoSort, bool) - -GPU_PERF_TEST(HoughLines, cv::gpu::DeviceInfo, cv::Size, DoSort) -{ - declare.time(30.0); - - const cv::Size size = GET_PARAM(1); - - const float rho = 1.0f; - const float theta = CV_PI / 180.0f; - const int threshold = 300; - - cv::RNG rng(123456789); - - cv::Mat src(size, CV_8UC1, cv::Scalar::all(0)); - - const int numLines = rng.uniform(500, 2000); - for (int i = 0; i < numLines; ++i) - { - cv::Point p1(rng.uniform(0, src.cols), rng.uniform(0, src.rows)); - cv::Point p2(rng.uniform(0, src.cols), rng.uniform(0, src.rows)); - cv::line(src, p1, p2, cv::Scalar::all(255), 2); - } - - std::vector lines; - cv::HoughLines(src, lines, rho, theta, threshold); - - TEST_CYCLE() - { - cv::HoughLines(src, lines, rho, theta, threshold); - } -} - -INSTANTIATE_TEST_CASE_P(ImgProc, HoughLines, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(DoSort(false), DoSort(true)))); - -#endif diff --git a/modules/gpu/perf_cpu/perf_labeling.cpp b/modules/gpu/perf_cpu/perf_labeling.cpp deleted file mode 100644 index ddf9c3d9b..000000000 --- a/modules/gpu/perf_cpu/perf_labeling.cpp +++ /dev/null @@ -1,158 +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) 2008-2011, 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: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions 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" - -#ifdef HAVE_CUDA - -namespace { - - struct GreedyLabeling - { - struct dot - { - int x; - int y; - - static dot make(int i, int j) - { - dot d; d.x = i; d.y = j; - return d; - } - }; - - struct InInterval - { - InInterval(const int& _lo, const int& _hi) : lo(-_lo), hi(_hi) {}; - const int lo, hi; - - bool operator() (const unsigned char a, const unsigned char b) const - { - int d = a - b; - return lo <= d && d <= hi; - } - }; - - GreedyLabeling(cv::Mat img) - : image(img), _labels(image.size(), CV_32SC1, cv::Scalar::all(-1)) {stack = new dot[image.cols * image.rows];} - - ~GreedyLabeling(){delete[] stack;} - - void operator() (cv::Mat labels) const - { - labels.setTo(cv::Scalar::all(-1)); - InInterval inInt(0, 2); - int cc = -1; - - int* dist_labels = (int*)labels.data; - int pitch = labels.step1(); - - unsigned char* source = (unsigned char*)image.data; - int width = image.cols; - int height = image.rows; - - for (int j = 0; j < image.rows; ++j) - for (int i = 0; i < image.cols; ++i) - { - if (dist_labels[j * pitch + i] != -1) continue; - - dot* top = stack; - dot p = dot::make(i, j); - cc++; - - dist_labels[j * pitch + i] = cc; - - while (top >= stack) - { - int* dl = &dist_labels[p.y * pitch + p.x]; - unsigned char* sp = &source[p.y * image.step1() + p.x]; - - dl[0] = cc; - - //right - if( p.x < (width - 1) && dl[ +1] == -1 && inInt(sp[0], sp[+1])) - *top++ = dot::make(p.x + 1, p.y); - - //left - if( p.x > 0 && dl[-1] == -1 && inInt(sp[0], sp[-1])) - *top++ = dot::make(p.x - 1, p.y); - - //bottom - if( p.y < (height - 1) && dl[+pitch] == -1 && inInt(sp[0], sp[+image.step1()])) - *top++ = dot::make(p.x, p.y + 1); - - //top - if( p.y > 0 && dl[-pitch] == -1 && inInt(sp[0], sp[-image.step1()])) - *top++ = dot::make(p.x, p.y - 1); - - p = *--top; - } - } - } - - cv::Mat image; - cv::Mat _labels; - dot* stack; - }; -} - -GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size) -{ - cv::gpu::DeviceInfo devInfo = GET_PARAM(0); - cv::gpu::setDevice(devInfo.deviceID()); - - cv::Mat image = readImage("gpu/labeling/aloe-disp.png", cv::IMREAD_GRAYSCALE); - - GreedyLabeling host(image); - - host(host._labels); - - declare.time(1.0); - - TEST_CYCLE() - { - host(host._labels); - } -} - -INSTANTIATE_TEST_CASE_P(Labeling, ConnectedComponents, testing::Combine(ALL_DEVICES, testing::Values(cv::Size(261, 262)))); - -#endif \ No newline at end of file diff --git a/modules/gpu/perf_cpu/perf_main.cpp b/modules/gpu/perf_cpu/perf_main.cpp deleted file mode 100644 index 6fcf56d0b..000000000 --- a/modules/gpu/perf_cpu/perf_main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - perf::TestBase::Init(argc, argv); - return RUN_ALL_TESTS(); -} - -#else - -int main() -{ - printf("OpenCV was built without CUDA support\n"); - return 0; -} - -#endif diff --git a/modules/gpu/perf_cpu/perf_matop.cpp b/modules/gpu/perf_cpu/perf_matop.cpp deleted file mode 100644 index 7c46eee80..000000000 --- a/modules/gpu/perf_cpu/perf_matop.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////////////////////// -// SetTo - -GPU_PERF_TEST(SetTo, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - cv::Scalar val(1, 2, 3, 4); - - src.setTo(val); - - TEST_CYCLE() - { - src.setTo(val); - } -} - -INSTANTIATE_TEST_CASE_P(MatOp, SetTo, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - -////////////////////////////////////////////////////////////////////// -// SetToMasked - -GPU_PERF_TEST(SetToMasked, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat mask(size, CV_8UC1); - fill(mask, 0, 2); - - cv::Scalar val(1, 2, 3, 4); - - src.setTo(val, mask); - - TEST_CYCLE() - { - src.setTo(val, mask); - } -} - -INSTANTIATE_TEST_CASE_P(MatOp, SetToMasked, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - -////////////////////////////////////////////////////////////////////// -// CopyToMasked - -GPU_PERF_TEST(CopyToMasked, cv::gpu::DeviceInfo, cv::Size, MatType) -{ - cv::Size size = GET_PARAM(1); - int type = GET_PARAM(2); - - cv::Mat src(size, type); - fill(src, 0, 255); - - cv::Mat mask(size, CV_8UC1); - fill(mask, 0, 2); - - cv::Mat dst; - - src.copyTo(dst, mask); - - TEST_CYCLE() - { - src.copyTo(dst, mask); - } -} - -INSTANTIATE_TEST_CASE_P(MatOp, CopyToMasked, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), - MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), - MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4), - MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4)))); - -////////////////////////////////////////////////////////////////////// -// ConvertTo - -GPU_PERF_TEST(ConvertTo, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth) -{ - cv::Size size = GET_PARAM(1); - int depth1 = GET_PARAM(2); - int depth2 = GET_PARAM(3); - - cv::Mat src(size, depth1); - fill(src, 0, 255); - - cv::Mat dst; - - src.convertTo(dst, depth2, 0.5, 1.0); - - TEST_CYCLE() - { - src.convertTo(dst, depth2, 0.5, 1.0); - } -} - -INSTANTIATE_TEST_CASE_P(MatOp, ConvertTo, testing::Combine( - ALL_DEVICES, - GPU_TYPICAL_MAT_SIZES, - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)), - testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)))); - -#endif diff --git a/modules/gpu/perf_cpu/perf_objdetect.cpp b/modules/gpu/perf_cpu/perf_objdetect.cpp deleted file mode 100644 index d9ae2b7c8..000000000 --- a/modules/gpu/perf_cpu/perf_objdetect.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -/////////////////////////////////////////////////////////////// -// HOG - -GPU_PERF_TEST_1(HOG, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/hog/road.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - std::vector found_locations; - - cv::HOGDescriptor hog; - hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector()); - - hog.detectMultiScale(img, found_locations); - - TEST_CYCLE() - { - hog.detectMultiScale(img, found_locations); - } -} - -INSTANTIATE_TEST_CASE_P(ObjDetect, HOG, ALL_DEVICES); - -/////////////////////////////////////////////////////////////// -// HaarClassifier - -GPU_PERF_TEST_1(HaarClassifier, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - cv::CascadeClassifier cascade; - - ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml"))); - - std::vector rects; - - cascade.detectMultiScale(img, rects); - - TEST_CYCLE() - { - cascade.detectMultiScale(img, rects); - } -} - -INSTANTIATE_TEST_CASE_P(ObjDetect, HaarClassifier, ALL_DEVICES); - -//===================== LBP cascade ==========================// -GPU_PERF_TEST_1(LBPClassifier, cv::gpu::DeviceInfo) -{ - cv::Mat img = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - cv::CascadeClassifier cascade; - - ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml"))); - - std::vector rects; - - cascade.detectMultiScale(img, rects); - - TEST_CYCLE() - { - cascade.detectMultiScale(img, rects); - } -} - -INSTANTIATE_TEST_CASE_P(ObjDetect, LBPClassifier, ALL_DEVICES); - -#endif diff --git a/modules/gpu/perf_cpu/perf_utility.cpp b/modules/gpu/perf_cpu/perf_utility.cpp deleted file mode 100644 index 541e6fdc7..000000000 --- a/modules/gpu/perf_cpu/perf_utility.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -using namespace std; -using namespace cv; -using namespace cv::gpu; - -void fill(Mat& m, double a, double b) -{ - RNG rng(123456789); - rng.fill(m, RNG::UNIFORM, a, b); -} - -void PrintTo(const CvtColorInfo& info, ostream* os) -{ - static const char* str[] = - { - "BGR2BGRA", - "BGRA2BGR", - "BGR2RGBA", - "RGBA2BGR", - "BGR2RGB", - "BGRA2RGBA", - - "BGR2GRAY", - "RGB2GRAY", - "GRAY2BGR", - "GRAY2BGRA", - "BGRA2GRAY", - "RGBA2GRAY", - - "BGR2BGR565", - "RGB2BGR565", - "BGR5652BGR", - "BGR5652RGB", - "BGRA2BGR565", - "RGBA2BGR565", - "BGR5652BGRA", - "BGR5652RGBA", - - "GRAY2BGR565", - "BGR5652GRAY", - - "BGR2BGR555", - "RGB2BGR555", - "BGR5552BGR", - "BGR5552RGB", - "BGRA2BGR555", - "RGBA2BGR555", - "BGR5552BGRA", - "BGR5552RGBA", - - "GRAY2BGR555", - "BGR5552GRAY", - - "BGR2XYZ", - "RGB2XYZ", - "XYZ2BGR", - "XYZ2RGB", - - "BGR2YCrCb", - "RGB2YCrCb", - "YCrCb2BGR", - "YCrCb2RGB", - - "BGR2HSV", - "RGB2HSV", - - "", - "", - - "BGR2Lab", - "RGB2Lab", - - "BayerBG2BGR", - "BayerGB2BGR", - "BayerRG2BGR", - "BayerGR2BGR", - - "BGR2Luv", - "RGB2Luv", - - "BGR2HLS", - "RGB2HLS", - - "HSV2BGR", - "HSV2RGB", - - "Lab2BGR", - "Lab2RGB", - "Luv2BGR", - "Luv2RGB", - - "HLS2BGR", - "HLS2RGB", - - "BayerBG2BGR_VNG", - "BayerGB2BGR_VNG", - "BayerRG2BGR_VNG", - "BayerGR2BGR_VNG", - - "BGR2HSV_FULL", - "RGB2HSV_FULL", - "BGR2HLS_FULL", - "RGB2HLS_FULL", - - "HSV2BGR_FULL", - "HSV2RGB_FULL", - "HLS2BGR_FULL", - "HLS2RGB_FULL", - - "LBGR2Lab", - "LRGB2Lab", - "LBGR2Luv", - "LRGB2Luv", - - "Lab2LBGR", - "Lab2LRGB", - "Luv2LBGR", - "Luv2LRGB", - - "BGR2YUV", - "RGB2YUV", - "YUV2BGR", - "YUV2RGB", - - "BayerBG2GRAY", - "BayerGB2GRAY", - "BayerRG2GRAY", - "BayerGR2GRAY", - - //YUV 4:2:0 formats family - "YUV2RGB_NV12", - "YUV2BGR_NV12", - "YUV2RGB_NV21", - "YUV2BGR_NV21", - - "YUV2RGBA_NV12", - "YUV2BGRA_NV12", - "YUV2RGBA_NV21", - "YUV2BGRA_NV21", - - "YUV2RGB_YV12", - "YUV2BGR_YV12", - "YUV2RGB_IYUV", - "YUV2BGR_IYUV", - - "YUV2RGBA_YV12", - "YUV2BGRA_YV12", - "YUV2RGBA_IYUV", - "YUV2BGRA_IYUV", - - "YUV2GRAY_420", - - //YUV 4:2:2 formats family - "YUV2RGB_UYVY", - "YUV2BGR_UYVY", - "YUV2RGB_VYUY", - "YUV2BGR_VYUY", - - "YUV2RGBA_UYVY", - "YUV2BGRA_UYVY", - "YUV2RGBA_VYUY", - "YUV2BGRA_VYUY", - - "YUV2RGB_YUY2", - "YUV2BGR_YUY2", - "YUV2RGB_YVYU", - "YUV2BGR_YVYU", - - "YUV2RGBA_YUY2", - "YUV2BGRA_YUY2", - "YUV2RGBA_YVYU", - "YUV2BGRA_YVYU", - - "YUV2GRAY_UYVY", - "YUV2GRAY_YUY2", - - // alpha premultiplication - "RGBA2mRGBA", - "mRGBA2RGBA", - - "COLORCVT_MAX" - }; - - *os << str[info.code]; -} - -void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os) -{ - *os << info.name(); -} - -Mat readImage(const string& fileName, int flags) -{ - return imread(perf::TestBase::getDataPath(fileName), flags); -} - -const vector& devices() -{ - static vector devs; - static bool first = true; - - if (first) - { - int deviceCount = getCudaEnabledDeviceCount(); - - devs.reserve(deviceCount); - - for (int i = 0; i < deviceCount; ++i) - { - DeviceInfo info(i); - if (info.isCompatible()) - devs.push_back(info); - } - - first = false; - } - - return devs; -} diff --git a/modules/gpu/perf_cpu/perf_utility.hpp b/modules/gpu/perf_cpu/perf_utility.hpp deleted file mode 100644 index 8693cfc3c..000000000 --- a/modules/gpu/perf_cpu/perf_utility.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef __OPENCV_PERF_GPU_UTILITY_HPP__ -#define __OPENCV_PERF_GPU_UTILITY_HPP__ - -void fill(cv::Mat& m, double a, double b); - -using perf::MatType; -using perf::MatDepth; - -CV_ENUM(BorderMode, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP) - CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA) -CV_ENUM(NormType, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_HAMMING) - -struct CvtColorInfo -{ - int scn; - int dcn; - int code; - - explicit CvtColorInfo(int scn_=0, int dcn_=0, int code_=0) : scn(scn_), dcn(dcn_), code(code_) {} -}; - -void PrintTo(const CvtColorInfo& info, std::ostream* os); - -#define IMPLEMENT_PARAM_CLASS(name, type) \ - class name \ - { \ - public: \ - name ( type arg = type ()) : val_(arg) {} \ - operator type () const {return val_;} \ - private: \ - type val_; \ - }; \ - inline void PrintTo( name param, std::ostream* os) \ - { \ - *os << #name << " = " << testing::PrintToString(static_cast< type >(param)); \ - } - -IMPLEMENT_PARAM_CLASS(Channels, int) - -namespace cv { namespace gpu -{ - void PrintTo(const cv::gpu::DeviceInfo& info, std::ostream* os); -}} - -#define GPU_PERF_TEST(name, ...) \ - struct name : perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > \ - { \ - public: \ - name() {} \ - protected: \ - void PerfTestBody(); \ - }; \ - TEST_P(name, perf){ RunPerfTestBody(); } \ - void name :: PerfTestBody() - -#define GPU_PERF_TEST_1(name, param_type) \ - struct name : perf::TestBaseWithParam< param_type > \ - { \ - public: \ - name() {} \ - protected: \ - void PerfTestBody(); \ - }; \ - TEST_P(name, perf){ RunPerfTestBody(); } \ - void name :: PerfTestBody() - -#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz1080p, cv::Size(1800, 1500)) - -cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR); - -const std::vector& devices(); - -#define ALL_DEVICES testing::ValuesIn(devices()) - -#define GET_PARAM(k) std::tr1::get< k >(GetParam()) - -#endif // __OPENCV_PERF_GPU_UTILITY_HPP__ diff --git a/modules/gpu/perf_cpu/perf_video.cpp b/modules/gpu/perf_cpu/perf_video.cpp deleted file mode 100644 index 2c3aeb31c..000000000 --- a/modules/gpu/perf_cpu/perf_video.cpp +++ /dev/null @@ -1,466 +0,0 @@ -#include "perf_cpu_precomp.hpp" - -#ifdef HAVE_CUDA - -////////////////////////////////////////////////////// -// GoodFeaturesToTrack - -IMPLEMENT_PARAM_CLASS(MinDistance, double) - -GPU_PERF_TEST(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) -{ - double minDistance = GET_PARAM(1); - - cv::Mat image = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(image.empty()); - - cv::Mat corners; - - cv::goodFeaturesToTrack(image, corners, 8000, 0.01, minDistance); - - TEST_CYCLE() - { - cv::goodFeaturesToTrack(image, corners, 8000, 0.01, minDistance); - } -} - -INSTANTIATE_TEST_CASE_P(Video, GoodFeaturesToTrack, testing::Combine( - ALL_DEVICES, - testing::Values(MinDistance(0.0), MinDistance(3.0)))); - -////////////////////////////////////////////////////// -// PyrLKOpticalFlowSparse - -IMPLEMENT_PARAM_CLASS(GraySource, bool) -IMPLEMENT_PARAM_CLASS(Points, int) -IMPLEMENT_PARAM_CLASS(WinSize, int) -IMPLEMENT_PARAM_CLASS(Levels, int) -IMPLEMENT_PARAM_CLASS(Iters, int) - -GPU_PERF_TEST(PyrLKOpticalFlowSparse, cv::gpu::DeviceInfo, GraySource, Points, WinSize, Levels, Iters) -{ - bool useGray = GET_PARAM(1); - int points = GET_PARAM(2); - int win_size = GET_PARAM(3); - int levels = GET_PARAM(4); - int iters = GET_PARAM(5); - - cv::Mat frame0 = readImage("gpu/opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); - ASSERT_FALSE(frame0.empty()); - - cv::Mat frame1 = readImage("gpu/opticalflow/frame1.png", 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); - - cv::Mat nextPts; - cv::Mat status; - - cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, cv::noArray(), - cv::Size(win_size, win_size), levels - 1, - cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, iters, 0.01)); - - declare.time(20.0); - - TEST_CYCLE() - { - cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, cv::noArray(), - cv::Size(win_size, win_size), levels - 1, - cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, iters, 0.01)); - } -} - -INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowSparse, testing::Combine( - ALL_DEVICES, - testing::Values(GraySource(true), GraySource(false)), - testing::Values(Points(1000), Points(2000), Points(4000), Points(8000)), - testing::Values(WinSize(9), WinSize(13), WinSize(17), WinSize(21)), - testing::Values(Levels(1), Levels(2), Levels(3)), - testing::Values(Iters(1), Iters(10), Iters(30)))); - -////////////////////////////////////////////////////// -// FarnebackOpticalFlowTest - -GPU_PERF_TEST_1(FarnebackOpticalFlowTest, cv::gpu::DeviceInfo) -{ - cv::Mat frame0 = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame0.empty()); - - cv::Mat frame1 = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(frame1.empty()); - - cv::Mat flow; - - int numLevels = 5; - double pyrScale = 0.5; - int winSize = 13; - int numIters = 10; - int polyN = 5; - double polySigma = 1.1; - int flags = 0; - - cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); - - declare.time(10); - - TEST_CYCLE() - { - cv::calcOpticalFlowFarneback(frame0, frame1, flow, pyrScale, numLevels, winSize, numIters, polyN, polySigma, flags); - } -} - -INSTANTIATE_TEST_CASE_P(Video, FarnebackOpticalFlowTest, ALL_DEVICES); - -////////////////////////////////////////////////////// -// FGDStatModel - -namespace cv -{ - template<> void Ptr::delete_obj() - { - cvReleaseBGStatModel(&obj); - } -} - -GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - cap >> frame; - ASSERT_FALSE(frame.empty()); - - IplImage ipl_frame = frame; - cv::Ptr model(cvCreateFGDStatModel(&ipl_frame)); - - declare.time(60); - - for (int i = 0; i < 10; ++i) - { - cap >> frame; - ASSERT_FALSE(frame.empty()); - - ipl_frame = frame; - - startTimer(); - next(); - - cvUpdateBGStatModel(&ipl_frame, model); - - stopTimer(); - } -} - -INSTANTIATE_TEST_CASE_P(Video, FGDStatModel, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - -////////////////////////////////////////////////////// -// MOG - -IMPLEMENT_PARAM_CLASS(LearningRate, double) - -GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - double learningRate = GET_PARAM(3); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - cv::BackgroundSubtractorMOG mog; - cv::Mat foreground; - - 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); - } - - mog(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(frame, foreground, learningRate); - stopTimer(); - } -} - -INSTANTIATE_TEST_CASE_P(Video, MOG, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3)/*, Channels(4)*/), - testing::Values(LearningRate(0.0), LearningRate(0.01)))); - -////////////////////////////////////////////////////// -// MOG2 - -GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - cv::BackgroundSubtractorMOG2 mog2; - cv::Mat foreground; - - 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(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(frame, foreground); - stopTimer(); - } -} - -INSTANTIATE_TEST_CASE_P(Video, MOG2_update, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3)/*, Channels(4)*/))); - -GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channels) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - - cv::VideoCapture cap(inputFile); - ASSERT_TRUE(cap.isOpened()); - - cv::Mat frame; - - cv::BackgroundSubtractorMOG2 mog2; - 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(frame, foreground); - } - - cv::Mat background; - mog2.getBackgroundImage(background); - - TEST_CYCLE() - { - mog2.getBackgroundImage(background); - } -} - -INSTANTIATE_TEST_CASE_P(Video, MOG2_getBackgroundImage, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(/*Channels(1),*/ Channels(3)/*, Channels(4)*/))); - -////////////////////////////////////////////////////// -// GMG - -IMPLEMENT_PARAM_CLASS(MaxFeatures, int) - -GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - int cn = GET_PARAM(2); - int maxFeatures = GET_PARAM(3); - - 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); - } - - cv::Mat fgmask; - cv::Mat zeros(frame.size(), CV_8UC1, cv::Scalar::all(0)); - - cv::BackgroundSubtractorGMG gmg; - gmg.set("maxFeatures", maxFeatures); - gmg.initialize(frame.size(), 0.0, 255.0); - - gmg(frame, fgmask); - - for (int i = 0; i < 150; ++i) - { - cap >> frame; - if (frame.empty()) - { - 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(frame, fgmask); - stopTimer(); - } -} - -INSTANTIATE_TEST_CASE_P(Video, GMG, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")), - testing::Values(Channels(1), Channels(3), Channels(4)), - testing::Values(MaxFeatures(20), MaxFeatures(40), MaxFeatures(60)))); - -////////////////////////////////////////////////////// -// VideoWriter - -#ifdef WIN32 - -GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string) -{ - const double FPS = 25.0; - - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - std::string outputFile = cv::tempfile(".avi"); - - cv::VideoCapture reader(inputFile); - ASSERT_TRUE( reader.isOpened() ); - - cv::VideoWriter writer; - - cv::Mat frame; - - declare.time(30); - - 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(); - } -} - -INSTANTIATE_TEST_CASE_P(Video, VideoWriter, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - -#endif // WIN32 - -////////////////////////////////////////////////////// -// VideoReader - -GPU_PERF_TEST(VideoReader, cv::gpu::DeviceInfo, std::string) -{ - std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); - - cv::VideoCapture reader(inputFile); - ASSERT_TRUE( reader.isOpened() ); - - cv::Mat frame; - - reader >> frame; - - declare.time(20); - - TEST_CYCLE_N(10) - { - reader >> frame; - } -} - -INSTANTIATE_TEST_CASE_P(Video, VideoReader, testing::Combine( - ALL_DEVICES, - testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); - -#endif From 1f42de39a33a3a5e2f9f21d4ea36219b42d6a865 Mon Sep 17 00:00:00 2001 From: Victor Passichenko Date: Sun, 19 Aug 2012 13:13:58 +0400 Subject: [PATCH 08/40] Add non-local means denoising algorithm implementatation into photo module --- modules/photo/doc/denoising.rst | 91 ++++ modules/photo/doc/photo.rst | 1 + .../photo/include/opencv2/photo/denoising.hpp | 79 ++++ modules/photo/src/arrays.hpp | 161 +++++++ modules/photo/src/denoising.cpp | 220 ++++++++++ .../src/fast_nlmeans_denoising_invoker.hpp | 342 +++++++++++++++ ...fast_nlmeans_denoising_invoker_commons.hpp | 120 ++++++ .../fast_nlmeans_multi_denoising_invoker.hpp | 394 ++++++++++++++++++ modules/photo/test/test_denoising.cpp | 213 ++++++++++ 9 files changed, 1621 insertions(+) create mode 100644 modules/photo/doc/denoising.rst create mode 100644 modules/photo/include/opencv2/photo/denoising.hpp create mode 100644 modules/photo/src/arrays.hpp create mode 100644 modules/photo/src/denoising.cpp create mode 100644 modules/photo/src/fast_nlmeans_denoising_invoker.hpp create mode 100644 modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp create mode 100644 modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp create mode 100644 modules/photo/test/test_denoising.cpp diff --git a/modules/photo/doc/denoising.rst b/modules/photo/doc/denoising.rst new file mode 100644 index 000000000..957ec8800 --- /dev/null +++ b/modules/photo/doc/denoising.rst @@ -0,0 +1,91 @@ +Denoising +========== + +.. highlight:: cpp + +fastNlMeansDenoising +----------- +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 fastNlMeansDenoising( Mat& src, Mat& dst, int templateWindowSize, int searchWindowSize, int h ) + + :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 templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels + + :param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels + + :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 + +This function expected to be applied to grayscale images. For colored images look at ``fastNlMeansDenoisingColored``. +Advanced usage of this functions can be manual denoising of colored image in different colorspaces. +Such approach is used in ``fastNlMeansDenoisingColored`` by converting image to CIELAB colorspace and then separately denoise L and AB components with different h parameter. + +fastNlMeansDenoisingColored +----------- +Modification of ``fastNlMeansDenoising`` function for colored images + +.. ocv:function:: void fastNlMeansDenoisingColored( Mat& src, Mat& dst, int templateWindowSize, int searchWindowSize, int h, int hForColorComponents ) + + :param src: Input 8-bit 3-channel image. + + :param dst: Output image with the same size and type as ``src`` . + + :param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels + + :param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels + + :param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise + + :param hForColorComponents: 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 + +The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoising`` function. + +fastNlMeansDenoisingMulti +----------- +Modification of ``fastNlMeansDenoising`` function for images sequence where consequtive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. +For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394 + +.. ocv:function:: void fastNlMeansDenoisingMulti( const std::vector& srcImgs, int imgToDenoiseIndex, int temporalWindowSize, Mat& dst, int templateWindowSize, int searchWindowSize, int h) + + :param srcImgs: Input 8-bit 1-channel, 2-channel or 3-channel images sequence. All images should have the same type and size. + + :param imgToDenoiseIndex: Target image to denoise index in ``srcImgs`` sequence + + :param temporalWindowSize: Number of surrounding images to use for target image denoising. Should be odd. Images from ``imgToDenoiseIndex - temporalWindowSize / 2`` to ``imgToDenoiseIndex - temporalWindowSize / 2`` from ``srcImgs`` will be used to denoise ``srcImgs[imgToDenoiseIndex]`` image. + + :param dst: Output image with the same size and type as ``srcImgs`` images. + + :param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels + + :param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels + + :param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise + +fastNlMeansDenoisingColoredMulti +----------- +Modification of ``fastNlMeansDenoisingMulti`` function for colored images sequences + +.. ocv:function:: void fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, int imgToDenoiseIndex, int temporalWindowSize, Mat& dst, int templateWindowSize, int searchWindowSize, int h, int hForColorComponents) + + :param srcImgs: Input 8-bit 3-channel images sequence. All images should have the same type and size. + + :param imgToDenoiseIndex: Target image to denoise index in ``srcImgs`` sequence + + :param temporalWindowSize: Number of surrounding images to use for target image denoising. Should be odd. Images from ``imgToDenoiseIndex - temporalWindowSize / 2`` to ``imgToDenoiseIndex - temporalWindowSize / 2`` from ``srcImgs`` will be used to denoise ``srcImgs[imgToDenoiseIndex]`` image. + + :param dst: Output image with the same size and type as ``srcImgs`` images. + + :param templateWindowSize: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels + + :param searchWindowSize: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels + + :param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise. + + :param hForColorComponents: The same as h but for color components. + +The function converts images to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoisingMulti`` function. + diff --git a/modules/photo/doc/photo.rst b/modules/photo/doc/photo.rst index 9d8636ee7..6f0523912 100644 --- a/modules/photo/doc/photo.rst +++ b/modules/photo/doc/photo.rst @@ -8,3 +8,4 @@ photo. Computational Photography :maxdepth: 2 inpainting + denoising diff --git a/modules/photo/include/opencv2/photo/denoising.hpp b/modules/photo/include/opencv2/photo/denoising.hpp new file mode 100644 index 000000000..b322c3175 --- /dev/null +++ b/modules/photo/include/opencv2/photo/denoising.hpp @@ -0,0 +1,79 @@ +/*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) 2008-2012, 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*/ + +#ifndef __OPENCV_DENOISING_HPP__ +#define __OPENCV_DENOISING_HPP__ + +#include "opencv2/core/core.hpp" +#include "opencv2/imgproc/imgproc.hpp" +#include + +#ifdef __cplusplus + +/*! \namespace cv + Namespace where all the C++ OpenCV functionality resides + */ +namespace cv +{ + +CV_EXPORTS void fastNlMeansDenoising( const Mat& src, Mat& dst, + int templateWindowSize, int searchWindowSize, int h); + +CV_EXPORTS void fastNlMeansDenoisingColored( const Mat& src, Mat& dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents); + +CV_EXPORTS void fastNlMeansDenoisingMulti( const std::vector& srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + Mat& dst, + int templateWindowSize, int searchWindowSize, int h); + +CV_EXPORTS void fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + Mat& dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents); + +} +#endif + +#endif diff --git a/modules/photo/src/arrays.hpp b/modules/photo/src/arrays.hpp new file mode 100644 index 000000000..c1c4e5f97 --- /dev/null +++ b/modules/photo/src/arrays.hpp @@ -0,0 +1,161 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective icvers. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_DENOISING_ARRAYS_HPP__ +#define __OPENCV_DENOISING_ARRAYS_HPP__ + +template struct Array2d { + T* a; + int n1,n2; + bool needToDeallocArray; + + Array2d(const Array2d& array2d): + a(array2d.a), n1(array2d.n1), n2(array2d.n2), needToDeallocArray(false) + { + if (array2d.needToDeallocArray) { + // copy constructor for self allocating arrays not supported + throw new exception(); + } + } + + Array2d(T* _a, int _n1, int _n2): + a(_a), n1(_n1), n2(_n2), needToDeallocArray(false) {} + + Array2d(int _n1, int _n2): + n1(_n1), n2(_n2), needToDeallocArray(true) + { + a = new T[n1*n2]; + } + + ~Array2d() { + if (needToDeallocArray) { + delete a; + } + } + + T* operator [] (int i) { + return a + i*n2; + } + + inline T* row_ptr(int i) { + return (*this)[i]; + } +}; + +template struct Array3d { + T* a; + int n1,n2,n3; + bool needToDeallocArray; + + Array3d(T* _a, int _n1, int _n2, int _n3): + a(_a), n1(_n1), n2(_n2), n3(_n3), needToDeallocArray(false) {} + + Array3d(int _n1, int _n2, int _n3): + n1(_n1), n2(_n2), n3(_n3), needToDeallocArray(true) + { + a = new T[n1*n2*n3]; + } + + ~Array3d() { + if (needToDeallocArray) { + delete a; + } + } + + Array2d operator [] (int i) { + Array2d array2d(a + i*n2*n3, n2, n3); + return array2d; + } + + inline T* row_ptr(int i1, int i2) { + return a + i1*n2*n3 + i2*n3; + } +}; + +template struct Array4d { + T* a; + int n1,n2,n3,n4; + bool needToDeallocArray; + int steps[4]; + + void init_steps() { + steps[0] = n2*n3*n4; + steps[1] = n3*n4; + steps[2] = n4; + steps[3] = 1; + } + + Array4d(T* _a, int _n1, int _n2, int _n3, int _n4): + a(_a), n1(_n1), n2(_n2), n3(_n3), n4(_n4), needToDeallocArray(false) + { + init_steps(); + } + + Array4d(int _n1, int _n2, int _n3, int _n4): + n1(_n1), n2(_n2), n3(_n3), n4(_n4), needToDeallocArray(true) + { + a = new T[n1*n2*n3*n4]; + init_steps(); + } + + ~Array4d() { + if (needToDeallocArray) { + delete a; + } + } + + Array3d operator [] (int i) { + Array3d array3d(a + i*n2*n3*n4, n2, n3, n4); + return array3d; + } + + inline T* row_ptr(int i1, int i2, int i3) { + return a + i1*n2*n3*n4 + i2*n3*n4 + i3*n4; + } + + inline int step_size(int dimension) { + return steps[dimension]; + } +}; + +#endif + + diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp new file mode 100644 index 000000000..39643e33d --- /dev/null +++ b/modules/photo/src/denoising.cpp @@ -0,0 +1,220 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective icvers. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "precomp.hpp" +#include "opencv2/photo/denoising.hpp" +#include "opencv2/imgproc/imgproc.hpp" +#include "fast_nlmeans_denoising_invoker.hpp" +#include "fast_nlmeans_multi_denoising_invoker.hpp" + +void cv::fastNlMeansDenoising( const cv::Mat& src, cv::Mat& dst, + int templateWindowSize, int searchWindowSize, int h) +{ + switch (src.type()) { + case CV_8U: + parallel_for(cv::BlockedRange(0, src.rows), + FastNlMeansDenoisingInvoker( + src, dst, templateWindowSize, searchWindowSize, h)); + break; + case CV_8UC2: + parallel_for(cv::BlockedRange(0, src.rows), + FastNlMeansDenoisingInvoker( + src, dst, templateWindowSize, searchWindowSize, h)); + break; + case CV_8UC3: + parallel_for(cv::BlockedRange(0, src.rows), + FastNlMeansDenoisingInvoker( + src, dst, templateWindowSize, searchWindowSize, h)); + break; + default: + CV_Error(CV_StsBadArg, + "Unsupported matrix format! Only uchar, Vec2b, Vec3b are supported"); + } +} + +void cv::fastNlMeansDenoisingColored( const cv::Mat& src, cv::Mat& dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents) +{ + if (src.type() != CV_8UC3) { + CV_Error(CV_StsBadArg, "Type of input image should be CV_8UC3!"); + return; + } + + Mat src_lab; + cvtColor(src, src_lab, CV_LBGR2Lab); + + Mat l(src.size(), CV_8U); + Mat ab(src.size(), CV_8UC2); + Mat l_ab[] = { l, ab }; + int from_to[] = { 0,0, 1,1, 2,2 }; + mixChannels(&src_lab, 1, l_ab, 2, from_to, 3); + + fastNlMeansDenoising(l, l, templateWindowSize, searchWindowSize, h); + fastNlMeansDenoising(ab, ab, templateWindowSize, searchWindowSize, hForColorComponents); + + Mat l_ab_denoised[] = { l, ab }; + Mat dst_lab(src.size(), src.type()); + mixChannels(l_ab_denoised, 2, &dst_lab, 1, from_to, 3); + + cvtColor(dst_lab, dst, CV_Lab2LBGR); +} + +static void fastNlMeansDenoisingMultiCheckPreconditions( + const std::vector& srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + int templateWindowSize, int searchWindowSize) +{ + int src_imgs_size = srcImgs.size(); + if (src_imgs_size == 0) { + CV_Error(CV_StsBadArg, "Input images vector should not be empty!"); + } + + if (temporalWindowSize % 2 == 0 || + searchWindowSize % 2 == 0 || + templateWindowSize % 2 == 0) { + CV_Error(CV_StsBadArg, "All windows sizes should be odd!"); + } + + int temporalWindowHalfSize = temporalWindowSize / 2; + if (imgToDenoiseIndex - temporalWindowHalfSize < 0 || + imgToDenoiseIndex + temporalWindowHalfSize >= src_imgs_size) + { + CV_Error(CV_StsBadArg, + "imgToDenoiseIndex and temporalWindowSize " + "should be choosen corresponding srcImgs size!"); + } + + for (int i = 1; i < src_imgs_size; i++) { + if (srcImgs[0].size() != srcImgs[i].size() || srcImgs[0].type() != srcImgs[i].type()) { + CV_Error(CV_StsBadArg, "Input images should have the same size and type!"); + } + } +} + +void cv::fastNlMeansDenoisingMulti( const std::vector& srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + cv::Mat& dst, + int templateWindowSize, int searchWindowSize, int h) +{ + fastNlMeansDenoisingMultiCheckPreconditions( + srcImgs, imgToDenoiseIndex, + temporalWindowSize, templateWindowSize, searchWindowSize + ); + + switch (srcImgs[0].type()) { + case CV_8U: + parallel_for(cv::BlockedRange(0, srcImgs[0].rows), + FastNlMeansMultiDenoisingInvoker( + srcImgs, imgToDenoiseIndex, temporalWindowSize, + dst, templateWindowSize, searchWindowSize, h)); + break; + case CV_8UC2: + parallel_for(cv::BlockedRange(0, srcImgs[0].rows), + FastNlMeansMultiDenoisingInvoker( + srcImgs, imgToDenoiseIndex, temporalWindowSize, + dst, templateWindowSize, searchWindowSize, h)); + break; + case CV_8UC3: + parallel_for(cv::BlockedRange(0, srcImgs[0].rows), + FastNlMeansMultiDenoisingInvoker( + srcImgs, imgToDenoiseIndex, temporalWindowSize, + dst, templateWindowSize, searchWindowSize, h)); + break; + default: + CV_Error(CV_StsBadArg, + "Unsupported matrix format! Only uchar, Vec2b, Vec3b are supported"); + } +} + +void cv::fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + cv::Mat& dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents) +{ + fastNlMeansDenoisingMultiCheckPreconditions( + srcImgs, imgToDenoiseIndex, + temporalWindowSize, templateWindowSize, searchWindowSize + ); + + int src_imgs_size = srcImgs.size(); + + if (srcImgs[0].type() != CV_8UC3) { + CV_Error(CV_StsBadArg, "Type of input images should be CV_8UC3!"); + return; + } + + int from_to[] = { 0,0, 1,1, 2,2 }; + + // TODO convert only required images + vector src_lab(src_imgs_size); + vector l(src_imgs_size); + vector ab(src_imgs_size); + for (int i = 0; i < src_imgs_size; i++) { + src_lab[i] = Mat::zeros(srcImgs[0].size(), CV_8UC3); + l[i] = Mat::zeros(srcImgs[0].size(), CV_8UC1); + ab[i] = Mat::zeros(srcImgs[0].size(), CV_8UC2); + cvtColor(srcImgs[i], src_lab[i], CV_LBGR2Lab); + + Mat l_ab[] = { l[i], ab[i] }; + mixChannels(&src_lab[i], 1, l_ab, 2, from_to, 3); + } + + Mat dst_l; + Mat dst_ab; + + fastNlMeansDenoisingMulti( + l, imgToDenoiseIndex, temporalWindowSize, + dst_l, templateWindowSize, searchWindowSize, h); + + fastNlMeansDenoisingMulti( + ab, imgToDenoiseIndex, temporalWindowSize, + dst_ab, templateWindowSize, searchWindowSize, hForColorComponents); + + Mat l_ab_denoised[] = { dst_l, dst_ab }; + Mat dst_lab(srcImgs[0].size(), srcImgs[0].type()); + mixChannels(l_ab_denoised, 2, &dst_lab, 1, from_to, 3); + + cvtColor(dst_lab, dst, CV_Lab2LBGR); +} + + diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp new file mode 100644 index 000000000..58e4a45e1 --- /dev/null +++ b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp @@ -0,0 +1,342 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective icvers. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_HPP__ +#define __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_HPP__ + +#include "precomp.hpp" +#include +#include +#include +#include + +#include "fast_nlmeans_denoising_invoker_commons.hpp" +#include "arrays.hpp" + +using namespace std; +using namespace cv; + +template +struct FastNlMeansDenoisingInvoker { + public: + FastNlMeansDenoisingInvoker(const Mat& src, Mat& dst, + int template_window_size, int search_window_size, const double h); + + void operator() (const BlockedRange& range) const; + + private: + const Mat& src_; + Mat& dst_; + + Mat extended_src_; + int border_size_; + + int template_window_size_; + int search_window_size_; + + int template_window_half_size_; + int search_window_half_size_; + + int fixed_point_mult_; + int almost_template_window_size_sq_bin_shift; + vector almost_dist2weight; + + void calcDistSumsForFirstElementInRow( + int i, + Array2d& dist_sums, + Array3d& col_dist_sums, + Array3d& up_col_dist_sums) const; + + void calcDistSumsForElementInFirstRow( + int i, + int j, + int first_col_num, + Array2d& dist_sums, + Array3d& col_dist_sums, + Array3d& up_col_dist_sums) const; +}; + +template +FastNlMeansDenoisingInvoker::FastNlMeansDenoisingInvoker( + const cv::Mat& src, + cv::Mat& dst, + int template_window_size, + int search_window_size, + const double h) : src_(src), dst_(dst) +{ + template_window_half_size_ = template_window_size / 2; + search_window_half_size_ = search_window_size / 2; + template_window_size_ = template_window_half_size_ * 2 + 1; + search_window_size_ = search_window_half_size_ * 2 + 1; + + border_size_ = search_window_half_size_ + template_window_half_size_; + copyMakeBorder(src_, extended_src_, + border_size_, border_size_, border_size_, border_size_, cv::BORDER_DEFAULT); + + const int max_estimate_sum_value = search_window_size_ * search_window_size_ * 255; + fixed_point_mult_ = numeric_limits::max() / max_estimate_sum_value; + + // precalc weight for every possible l2 dist between blocks + // additional optimization of precalced weights to replace division(averaging) by binary shift + int template_window_size_sq = template_window_size_ * template_window_size_; + almost_template_window_size_sq_bin_shift = 0; + while (1 << almost_template_window_size_sq_bin_shift < template_window_size_sq) { + almost_template_window_size_sq_bin_shift++; + } + + int almost_template_window_size_sq = 1 << almost_template_window_size_sq_bin_shift; + double almost_dist2actual_dist_multiplier = + ((double) almost_template_window_size_sq) / template_window_size_sq; + + int max_dist = 256 * 256 * src_.channels(); + int almost_max_dist = (int) (max_dist / almost_dist2actual_dist_multiplier + 1); + almost_dist2weight.resize(almost_max_dist); + + const double WEIGHT_THRESHOLD = 0.001; + for (int almost_dist = 0; almost_dist < almost_max_dist; almost_dist++) { + double dist = almost_dist * almost_dist2actual_dist_multiplier; + int weight = cvRound(fixed_point_mult_ * std::exp(- dist / (h * h * src_.channels()))); + + if (weight < WEIGHT_THRESHOLD * fixed_point_mult_) { + weight = 0; + } + + almost_dist2weight[almost_dist] = weight; + } + // additional optimization init end + + if (dst_.empty()) { + dst_ = Mat::zeros(src_.size(), src_.type()); + } +} + +template +void FastNlMeansDenoisingInvoker::operator() (const BlockedRange& range) const { + int row_from = range.begin(); + int row_to = range.end() - 1; + + int dist_sums_array[search_window_size_ * search_window_size_]; + Array2d dist_sums(dist_sums_array, search_window_size_, search_window_size_); + + // for lazy calc optimization + int col_dist_sums_array[template_window_size_ * search_window_size_ * search_window_size_]; + Array3d col_dist_sums(&col_dist_sums_array[0], + template_window_size_, search_window_size_, search_window_size_); + + int first_col_num = -1; + + Array3d up_col_dist_sums(src_.cols, search_window_size_, search_window_size_); + + for (int i = row_from; i <= row_to; i++) { + for (int j = 0; j < src_.cols; j++) { + int search_window_y = i - search_window_half_size_; + int search_window_x = j - search_window_half_size_; + + // calc dist_sums + if (j == 0) { + calcDistSumsForFirstElementInRow(i, dist_sums, col_dist_sums, up_col_dist_sums); + first_col_num = 0; + + } else { // calc cur dist_sums using previous dist_sums + if (i == row_from) { + calcDistSumsForElementInFirstRow(i, j, first_col_num, + dist_sums, col_dist_sums, up_col_dist_sums); + + } else { + int ay = border_size_ + i; + int ax = border_size_ + j + template_window_half_size_; + + int start_by = + border_size_ + i - search_window_half_size_; + + int start_bx = + border_size_ + j - search_window_half_size_ + template_window_half_size_; + + T a_up = extended_src_.at(ay - template_window_half_size_ - 1, ax); + T a_down = extended_src_.at(ay + template_window_half_size_, ax); + + // copy class member to local variable for optimization + int search_window_size = search_window_size_; + + for (int y = 0; y < search_window_size; y++) { + int* dist_sums_row = dist_sums.row_ptr(y); + + int* col_dist_sums_row = col_dist_sums.row_ptr(first_col_num,y); + + int* up_col_dist_sums_row = up_col_dist_sums.row_ptr(j, y); + + const T* b_up_ptr = + extended_src_.ptr(start_by - template_window_half_size_ - 1 + y); + + const T* b_down_ptr = + extended_src_.ptr(start_by + template_window_half_size_ + y); + + for (int x = 0; x < search_window_size; x++) { + dist_sums_row[x] -= col_dist_sums_row[x]; + + col_dist_sums_row[x] = + up_col_dist_sums_row[x] + + calcUpDownDist( + a_up, a_down, + b_up_ptr[start_bx + x], b_down_ptr[start_bx + x] + ); + + dist_sums_row[x] += col_dist_sums_row[x]; + + up_col_dist_sums_row[x] = col_dist_sums_row[x]; + + } + } + } + + first_col_num = (first_col_num + 1) % template_window_size_; + } + + // calc weights + int weights_sum = 0; + + int estimation[src_.channels()]; + for (int channel_num = 0; channel_num < src_.channels(); channel_num++) { + estimation[channel_num] = 0; + } + + for (int y = 0; y < search_window_size_; y++) { + const T* cur_row_ptr = extended_src_.ptr(border_size_ + search_window_y + y); + int* dist_sums_row = dist_sums.row_ptr(y); + for (int x = 0; x < search_window_size_; x++) { + int almostAvgDist = + dist_sums_row[x] >> almost_template_window_size_sq_bin_shift; + + int weight = almost_dist2weight[almostAvgDist]; + weights_sum += weight; + + T p = cur_row_ptr[border_size_ + search_window_x + x]; + incWithWeight(estimation, weight, p); + } + } + + if (weights_sum > 0) { + for (int channel_num = 0; channel_num < src_.channels(); channel_num++) { + estimation[channel_num] = + cvRound(((double)estimation[channel_num]) / weights_sum); + } + + dst_.at(i,j) = saturateCastFromArray(estimation); + + } else { // weights_sum == 0 + dst_.at(i,j) = src_.at(i,j); + } + } + } +} + +template +inline void FastNlMeansDenoisingInvoker::calcDistSumsForFirstElementInRow( + int i, + Array2d& dist_sums, + Array3d& col_dist_sums, + Array3d& up_col_dist_sums) const +{ + int j = 0; + + for (int y = 0; y < search_window_size_; y++) { + for (int x = 0; x < search_window_size_; x++) { + dist_sums[y][x] = 0; + for (int tx = 0; tx < template_window_size_; tx++) { + col_dist_sums[tx][y][x] = 0; + } + + int start_y = i + y - search_window_half_size_; + int start_x = j + x - search_window_half_size_; + + for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) { + for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++) { + int dist = calcDist(extended_src_, + border_size_ + i + ty, border_size_ + j + tx, + border_size_ + start_y + ty, border_size_ + start_x + tx); + + dist_sums[y][x] += dist; + col_dist_sums[tx + template_window_half_size_][y][x] += dist; + } + } + + up_col_dist_sums[j][y][x] = col_dist_sums[template_window_size_ - 1][y][x]; + } + } +} + +template +inline void FastNlMeansDenoisingInvoker::calcDistSumsForElementInFirstRow( + int i, + int j, + int first_col_num, + Array2d& dist_sums, + Array3d& col_dist_sums, + Array3d& up_col_dist_sums) const +{ + int ay = border_size_ + i; + int ax = border_size_ + j + template_window_half_size_; + + int start_by = border_size_ + i - search_window_half_size_; + int start_bx = border_size_ + j - search_window_half_size_ + template_window_half_size_; + + int new_last_col_num = first_col_num; + + for (int y = 0; y < search_window_size_; y++) { + for (int x = 0; x < search_window_size_; x++) { + dist_sums[y][x] -= col_dist_sums[first_col_num][y][x]; + + col_dist_sums[new_last_col_num][y][x] = 0; + int by = start_by + y; + int bx = start_bx + x; + for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) { + col_dist_sums[new_last_col_num][y][x] += + calcDist(extended_src_, ay + ty, ax, by + ty, bx); + } + + dist_sums[y][x] += col_dist_sums[new_last_col_num][y][x]; + + up_col_dist_sums[j][y][x] = col_dist_sums[new_last_col_num][y][x]; + } + } +} + +#endif diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp new file mode 100644 index 000000000..c1084f15e --- /dev/null +++ b/modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp @@ -0,0 +1,120 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective icvers. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_COMMONS_HPP__ +#define __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_COMMONS_HPP__ + +#include +#include +#include + +using namespace std; +using namespace cv; + +template static inline int calcDist(const T a, const T b); + +template <> inline int calcDist(const uchar a, const uchar b) { + return (a-b) * (a-b); +} + +template <> inline int calcDist(const Vec2b a, const Vec2b b) { + return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]); +} + +template <> inline int calcDist(const Vec3b a, const Vec3b b) { + return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]) + (a[2]-b[2])*(a[2]-b[2]); +} + +template static inline int calcDist(const Mat& m, int i1, int j1, int i2, int j2) { + const T a = m.at(i1, j1); + const T b = m.at(i2, j2); + return calcDist(a,b); +} + +template static inline int calcUpDownDist(T a_up, T a_down, T b_up, T b_down) { + return calcDist(a_down,b_down) - calcDist(a_up, b_up); +} + +template <> inline int calcUpDownDist(uchar a_up, uchar a_down, uchar b_up, uchar b_down) { + int A = a_down - b_down; + int B = a_up - b_up; + return (A-B)*(A+B); +} + +template static inline void incWithWeight(int* estimation, int weight, T p); + +template <> inline void incWithWeight(int* estimation, int weight, uchar p) { + estimation[0] += weight * p; +} + +template <> inline void incWithWeight(int* estimation, int weight, Vec2b p) { + estimation[0] += weight * p[0]; + estimation[1] += weight * p[1]; +} + +template <> inline void incWithWeight(int* estimation, int weight, Vec3b p) { + estimation[0] += weight * p[0]; + estimation[1] += weight * p[1]; + estimation[2] += weight * p[2]; +} + +template static inline T saturateCastFromArray(int* estimation); + +template <> inline uchar saturateCastFromArray(int* estimation) { + return saturate_cast(estimation[0]); +} + +template <> inline Vec2b saturateCastFromArray(int* estimation) { + Vec2b res; + res[0] = saturate_cast(estimation[0]); + res[1] = saturate_cast(estimation[1]); + return res; +} + +template <> inline Vec3b saturateCastFromArray(int* estimation) { + Vec3b res; + res[0] = saturate_cast(estimation[0]); + res[1] = saturate_cast(estimation[1]); + res[2] = saturate_cast(estimation[2]); + return res; +} + +#endif diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp new file mode 100644 index 000000000..cb08c7e43 --- /dev/null +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -0,0 +1,394 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective icvers. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FAST_NLMEANS_MULTI_DENOISING_INVOKER_HPP__ +#define __OPENCV_FAST_NLMEANS_MULTI_DENOISING_INVOKER_HPP__ + +#include "precomp.hpp" +#include +#include +#include +#include + +#include "fast_nlmeans_denoising_invoker_commons.hpp" +#include "arrays.hpp" + +using namespace std; +using namespace cv; + +template +struct FastNlMeansMultiDenoisingInvoker { + public: + FastNlMeansMultiDenoisingInvoker( + const std::vector& srcImgs, int imgToDenoiseIndex, int temporalWindowSize, + Mat& dst, int template_window_size, int search_window_size, const double h); + + void operator() (const BlockedRange& range) const; + + private: + int rows_; + int cols_; + int channels_count_; + + Mat& dst_; + + vector extended_srcs_; + Mat main_extended_src_; + int border_size_; + + int template_window_size_; + int search_window_size_; + int temporal_window_size_; + + int template_window_half_size_; + int search_window_half_size_; + int temporal_window_half_size_; + + int fixed_point_mult_; + int almost_template_window_size_sq_bin_shift; + vector almost_dist2weight; + + void calcDistSumsForFirstElementInRow( + int i, + Array3d& dist_sums, + Array4d& col_dist_sums, + Array4d& up_col_dist_sums) const; + + void calcDistSumsForElementInFirstRow( + int i, + int j, + int first_col_num, + Array3d& dist_sums, + Array4d& col_dist_sums, + Array4d& up_col_dist_sums) const; +}; + +template +FastNlMeansMultiDenoisingInvoker::FastNlMeansMultiDenoisingInvoker( + const vector& srcImgs, + int imgToDenoiseIndex, + int temporalWindowSize, + cv::Mat& dst, + int template_window_size, + int search_window_size, + const double h) : dst_(dst), extended_srcs_(srcImgs.size()) +{ + rows_ = srcImgs[0].rows; + cols_ = srcImgs[0].cols; + channels_count_ = srcImgs[0].channels(); + + template_window_half_size_ = template_window_size / 2; + search_window_half_size_ = search_window_size / 2; + temporal_window_half_size_ = temporalWindowSize / 2; + + template_window_size_ = template_window_half_size_ * 2 + 1; + search_window_size_ = search_window_half_size_ * 2 + 1; + temporal_window_size_ = temporal_window_half_size_ * 2 + 1; + + border_size_ = search_window_half_size_ + template_window_half_size_; + for (int i = 0; i < temporal_window_size_; i++) { + copyMakeBorder( + srcImgs[imgToDenoiseIndex - temporal_window_half_size_ + i], extended_srcs_[i], + border_size_, border_size_, border_size_, border_size_, cv::BORDER_DEFAULT); + } + main_extended_src_ = extended_srcs_[temporal_window_half_size_]; + + const int max_estimate_sum_value = + temporal_window_size_ * search_window_size_ * search_window_size_ * 255; + + fixed_point_mult_ = numeric_limits::max() / max_estimate_sum_value; + + // precalc weight for every possible l2 dist between blocks + // additional optimization of precalced weights to replace division(averaging) by binary shift + int template_window_size_sq = template_window_size_ * template_window_size_; + almost_template_window_size_sq_bin_shift = 0; + while (1 << almost_template_window_size_sq_bin_shift < template_window_size_sq) { + almost_template_window_size_sq_bin_shift++; + } + + int almost_template_window_size_sq = 1 << almost_template_window_size_sq_bin_shift; + double almost_dist2actual_dist_multiplier = + ((double) almost_template_window_size_sq) / template_window_size_sq; + + int max_dist = 256 * 256 * channels_count_; + int almost_max_dist = (int) (max_dist / almost_dist2actual_dist_multiplier + 1); + almost_dist2weight.resize(almost_max_dist); + + const double WEIGHT_THRESHOLD = 0.001; + for (int almost_dist = 0; almost_dist < almost_max_dist; almost_dist++) { + double dist = almost_dist * almost_dist2actual_dist_multiplier; + int weight = cvRound(fixed_point_mult_ * std::exp(- dist / (h * h * channels_count_))); + + if (weight < WEIGHT_THRESHOLD * fixed_point_mult_) { + weight = 0; + } + + almost_dist2weight[almost_dist] = weight; + } + // additional optimization init end + + if (dst_.empty()) { + dst_ = Mat::zeros(srcImgs[0].size(), srcImgs[0].type()); + } +} + +template +void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) const { + int row_from = range.begin(); + int row_to = range.end() - 1; + + int dist_sums_array[temporal_window_size_ * search_window_size_ * search_window_size_]; + Array3d dist_sums(dist_sums_array, + temporal_window_size_, search_window_size_, search_window_size_); + + // for lazy calc optimization + int col_dist_sums_array[ + template_window_size_ * temporal_window_size_ * search_window_size_ * search_window_size_]; + + Array4d col_dist_sums(col_dist_sums_array, + template_window_size_, temporal_window_size_, search_window_size_, search_window_size_); + + int first_col_num = -1; + + Array4d up_col_dist_sums( + cols_, temporal_window_size_, search_window_size_, search_window_size_); + + for (int i = row_from; i <= row_to; i++) { + for (int j = 0; j < cols_; j++) { + int search_window_y = i - search_window_half_size_; + int search_window_x = j - search_window_half_size_; + + // calc dist_sums + if (j == 0) { + calcDistSumsForFirstElementInRow(i, dist_sums, col_dist_sums, up_col_dist_sums); + first_col_num = 0; + + } else { // calc cur dist_sums using previous dist_sums + if (i == row_from) { + calcDistSumsForElementInFirstRow(i, j, first_col_num, + dist_sums, col_dist_sums, up_col_dist_sums); + + } else { + int ay = border_size_ + i; + int ax = border_size_ + j + template_window_half_size_; + + int start_by = + border_size_ + i - search_window_half_size_; + + int start_bx = + border_size_ + j - search_window_half_size_ + template_window_half_size_; + + T a_up = main_extended_src_.at(ay - template_window_half_size_ - 1, ax); + T a_down = main_extended_src_.at(ay + template_window_half_size_, ax); + + // copy class member to local variable for optimization + int search_window_size = search_window_size_; + + for (int d = 0; d < temporal_window_size_; d++) { + Mat cur_extended_src = extended_srcs_[d]; + Array2d cur_dist_sums = dist_sums[d]; + Array2d cur_col_dist_sums = col_dist_sums[first_col_num][d]; + Array2d cur_up_col_dist_sums = up_col_dist_sums[j][d]; + for (int y = 0; y < search_window_size; y++) { + int* dist_sums_row = cur_dist_sums.row_ptr(y); + + int* col_dist_sums_row = cur_col_dist_sums.row_ptr(y); + + int* up_col_dist_sums_row = cur_up_col_dist_sums.row_ptr(y); + + const T* b_up_ptr = + cur_extended_src.ptr(start_by - template_window_half_size_ - 1 + y); + const T* b_down_ptr = + cur_extended_src.ptr(start_by + template_window_half_size_ + y); + + for (int x = 0; x < search_window_size; x++) { + dist_sums_row[x] -= col_dist_sums_row[x]; + + col_dist_sums_row[x] = up_col_dist_sums_row[x] + + calcUpDownDist( + a_up, a_down, + b_up_ptr[start_bx + x], b_down_ptr[start_bx + x] + ); + + dist_sums_row[x] += col_dist_sums_row[x]; + + up_col_dist_sums_row[x] = col_dist_sums_row[x]; + + } + } + } + } + + first_col_num = (first_col_num + 1) % template_window_size_; + } + + // calc weights + int weights_sum = 0; + + int estimation[channels_count_]; + for (int channel_num = 0; channel_num < channels_count_; channel_num++) { + estimation[channel_num] = 0; + } + for (int d = 0; d < temporal_window_size_; d++) { + for (int y = 0; y < search_window_size_; y++) { + const T* cur_row_ptr = + extended_srcs_[d].ptr(border_size_ + search_window_y + y); + + int* dist_sums_row = dist_sums.row_ptr(d, y); + + for (int x = 0; x < search_window_size_; x++) { + int almostAvgDist = + dist_sums_row[x] >> almost_template_window_size_sq_bin_shift; + + int weight = almost_dist2weight[almostAvgDist]; + weights_sum += weight; + + T p = cur_row_ptr[border_size_ + search_window_x + x]; + incWithWeight(estimation, weight, p); + } + } + } + + if (weights_sum > 0) { + for (int channel_num = 0; channel_num < channels_count_; channel_num++) { + estimation[channel_num] = + cvRound(((double)estimation[channel_num]) / weights_sum); + } + + dst_.at(i,j) = saturateCastFromArray(estimation); + + } else { // weights_sum == 0 + dst_.at(i,j) = extended_srcs_[temporal_window_half_size_].at(i,j); + } + } + } +} + +template +inline void FastNlMeansMultiDenoisingInvoker::calcDistSumsForFirstElementInRow( + int i, + Array3d& dist_sums, + Array4d& col_dist_sums, + Array4d& up_col_dist_sums) const +{ + int j = 0; + + for (int d = 0; d < temporal_window_size_; d++) { + Mat cur_extended_src = extended_srcs_[d]; + for (int y = 0; y < search_window_size_; y++) { + for (int x = 0; x < search_window_size_; x++) { + dist_sums[d][y][x] = 0; + for (int tx = 0; tx < template_window_size_; tx++) { + col_dist_sums[tx][d][y][x] = 0; + } + + int start_y = i + y - search_window_half_size_; + int start_x = j + x - search_window_half_size_; + + int* dist_sums_ptr = &dist_sums[d][y][x]; + int* col_dist_sums_ptr = &col_dist_sums[0][d][y][x]; + int col_dist_sums_step = col_dist_sums.step_size(0); + for (int tx = -template_window_half_size_; tx <= template_window_half_size_; tx++) { + for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) { + int dist = calcDist( + main_extended_src_.at( + border_size_ + i + ty, border_size_ + j + tx), + cur_extended_src.at( + border_size_ + start_y + ty, border_size_ + start_x + tx) + ); + + *dist_sums_ptr += dist; + *col_dist_sums_ptr += dist; + } + col_dist_sums_ptr += col_dist_sums_step; + } + + up_col_dist_sums[j][d][y][x] = col_dist_sums[template_window_size_ - 1][d][y][x]; + } + } + } +} + +template +inline void FastNlMeansMultiDenoisingInvoker::calcDistSumsForElementInFirstRow( + int i, + int j, + int first_col_num, + Array3d& dist_sums, + Array4d& col_dist_sums, + Array4d& up_col_dist_sums) const +{ + int ay = border_size_ + i; + int ax = border_size_ + j + template_window_half_size_; + + int start_by = border_size_ + i - search_window_half_size_; + int start_bx = border_size_ + j - search_window_half_size_ + template_window_half_size_; + + int new_last_col_num = first_col_num; + + for (int d = 0; d < temporal_window_size_; d++) { + Mat cur_extended_src = extended_srcs_[d]; + for (int y = 0; y < search_window_size_; y++) { + for (int x = 0; x < search_window_size_; x++) { + dist_sums[d][y][x] -= col_dist_sums[first_col_num][d][y][x]; + + col_dist_sums[new_last_col_num][d][y][x] = 0; + int by = start_by + y; + int bx = start_bx + x; + + int* col_dist_sums_ptr = &col_dist_sums[new_last_col_num][d][y][x]; + for (int ty = -template_window_half_size_; ty <= template_window_half_size_; ty++) { + *col_dist_sums_ptr += + calcDist( + main_extended_src_.at(ay + ty, ax), + cur_extended_src.at(by + ty, bx) + ); + } + + dist_sums[d][y][x] += col_dist_sums[new_last_col_num][d][y][x]; + + up_col_dist_sums[j][d][y][x] = col_dist_sums[new_last_col_num][d][y][x]; + } + } + } +} + +#endif diff --git a/modules/photo/test/test_denoising.cpp b/modules/photo/test/test_denoising.cpp new file mode 100644 index 000000000..39aa69981 --- /dev/null +++ b/modules/photo/test/test_denoising.cpp @@ -0,0 +1,213 @@ +/*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 "test_precomp.hpp" +#include "opencv2/photo/denoising.hpp" +#include + +using namespace cv; +using namespace std; + +class CV_DenoisingGrayscaleTest : public cvtest::BaseTest +{ +public: + CV_DenoisingGrayscaleTest(); + ~CV_DenoisingGrayscaleTest(); +protected: + void run(int); +}; + +CV_DenoisingGrayscaleTest::CV_DenoisingGrayscaleTest() {} +CV_DenoisingGrayscaleTest::~CV_DenoisingGrayscaleTest() {} + +void CV_DenoisingGrayscaleTest::run( int ) +{ + string folder = string(ts->get_data_path()) + "denoising/"; + Mat orig = imread(folder + "lena_noised_gaussian_sigma=10.png", 0); + Mat exp = imread(folder + "lena_noised_denoised_grayscale_tw=7_sw=21_h=10.png", 0); + + if (orig.empty() || exp.empty()) + { + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); + return; + } + + Mat res; + fastNlMeansDenoising(orig, res, 7, 21, 10); + + if (norm(res - exp) > 0) { + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } else { + ts->set_failed_test_info(cvtest::TS::OK); + } +} + +class CV_DenoisingColoredTest : public cvtest::BaseTest +{ +public: + CV_DenoisingColoredTest(); + ~CV_DenoisingColoredTest(); +protected: + void run(int); +}; + +CV_DenoisingColoredTest::CV_DenoisingColoredTest() {} +CV_DenoisingColoredTest::~CV_DenoisingColoredTest() {} + +void CV_DenoisingColoredTest::run( int ) +{ + string folder = string(ts->get_data_path()) + "denoising/"; + Mat orig = imread(folder + "lena_noised_gaussian_sigma=10.png", 1); + Mat exp = imread(folder + "lena_noised_denoised_lab12_tw=7_sw=21_h=10_h2=10.png", 1); + + if (orig.empty() || exp.empty()) + { + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); + return; + } + + Mat res; + fastNlMeansDenoisingColored(orig, res, 7, 21, 10, 10); + + if (norm(res - exp) > 0) { + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } else { + ts->set_failed_test_info(cvtest::TS::OK); + } +} + +class CV_DenoisingGrayscaleMultiTest : public cvtest::BaseTest +{ +public: + CV_DenoisingGrayscaleMultiTest(); + ~CV_DenoisingGrayscaleMultiTest(); +protected: + void run(int); +}; + +CV_DenoisingGrayscaleMultiTest::CV_DenoisingGrayscaleMultiTest() {} +CV_DenoisingGrayscaleMultiTest::~CV_DenoisingGrayscaleMultiTest() {} + +void CV_DenoisingGrayscaleMultiTest::run( int ) +{ + string folder = string(ts->get_data_path()) + "denoising/"; + + const int imgs_count = 3; + vector src_imgs(imgs_count); + src_imgs[0] = imread(folder + "lena_noised_gaussian_sigma=20_multi_0.png", 0); + src_imgs[1] = imread(folder + "lena_noised_gaussian_sigma=20_multi_1.png", 0); + src_imgs[2] = imread(folder + "lena_noised_gaussian_sigma=20_multi_2.png", 0); + + Mat exp = imread(folder + "lena_noised_denoised_multi_tw=7_sw=21_h=15.png", 0); + + bool have_empty_src = false; + for (int i = 0; i < imgs_count; i++) { + have_empty_src |= src_imgs[i].empty(); + } + + if (have_empty_src || exp.empty()) + { + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); + return; + } + + Mat res; + fastNlMeansDenoisingMulti(src_imgs, imgs_count / 2, imgs_count, res, 7, 21, 15); + + if (norm(res - exp) > 0) { + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } else { + ts->set_failed_test_info(cvtest::TS::OK); + } +} + +class CV_DenoisingColoredMultiTest : public cvtest::BaseTest +{ +public: + CV_DenoisingColoredMultiTest(); + ~CV_DenoisingColoredMultiTest(); +protected: + void run(int); +}; + +CV_DenoisingColoredMultiTest::CV_DenoisingColoredMultiTest() {} +CV_DenoisingColoredMultiTest::~CV_DenoisingColoredMultiTest() {} + +void CV_DenoisingColoredMultiTest::run( int ) +{ + string folder = string(ts->get_data_path()) + "denoising/"; + + const int imgs_count = 3; + vector src_imgs(imgs_count); + src_imgs[0] = imread(folder + "lena_noised_gaussian_sigma=20_multi_0.png", 1); + src_imgs[1] = imread(folder + "lena_noised_gaussian_sigma=20_multi_1.png", 1); + src_imgs[2] = imread(folder + "lena_noised_gaussian_sigma=20_multi_2.png", 1); + + Mat exp = imread(folder + "lena_noised_denoised_multi_lab12_tw=7_sw=21_h=10_h2=15.png", 1); + + bool have_empty_src = false; + for (int i = 0; i < imgs_count; i++) { + have_empty_src |= src_imgs[i].empty(); + } + + if (have_empty_src || exp.empty()) + { + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); + return; + } + + Mat res; + fastNlMeansDenoisingColoredMulti(src_imgs, imgs_count / 2, imgs_count, res, 7, 21, 10, 15); + + if (norm(res - exp) > 0) { + ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); + } else { + ts->set_failed_test_info(cvtest::TS::OK); + } +} + + +TEST(Imgproc_DenoisingGrayscale, regression) { CV_DenoisingGrayscaleTest test; test.safe_run(); } +TEST(Imgproc_DenoisingColored, regression) { CV_DenoisingColoredTest test; test.safe_run(); } +TEST(Imgproc_DenoisingGrayscaleMulti, regression) { CV_DenoisingGrayscaleMultiTest test; test.safe_run(); } +TEST(Imgproc_DenoisingColoredMulti, regression) { CV_DenoisingColoredMultiTest test; test.safe_run(); } + From 66eb96d719309ed8f3252ef0ea27632005d65ec6 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Sun, 19 Aug 2012 22:43:27 +0400 Subject: [PATCH 09/40] minor warning fix --- modules/core/src/cuda/matrix_operations.cu | 13 +++++++++++-- modules/core/src/gpumat.cpp | 4 ---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/core/src/cuda/matrix_operations.cu b/modules/core/src/cuda/matrix_operations.cu index 6bf1549dd..671fa5fc3 100644 --- a/modules/core/src/cuda/matrix_operations.cu +++ b/modules/core/src/cuda/matrix_operations.cu @@ -44,7 +44,7 @@ #include "opencv2/gpu/device/transform.hpp" #include "opencv2/gpu/device/functional.hpp" -namespace cv { namespace gpu { namespace device +namespace cv { namespace gpu { namespace device { template struct shift_and_sizeof; template <> struct shift_and_sizeof { enum { shift = 0 }; }; @@ -272,7 +272,7 @@ namespace cv { namespace gpu { namespace device template struct TransformFunctorTraits< Convertor > : detail::ConvertTraits< Convertor > { }; - + template void cvt_(DevMem2Db src, DevMem2Db dst, double alpha, double beta, cudaStream_t stream) { @@ -282,6 +282,11 @@ namespace cv { namespace gpu { namespace device cv::gpu::device::transform((DevMem2D_)src, (DevMem2D_)dst, op, WithOutMask(), stream); } +#if defined __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmissing-declarations" +#endif + void convert_gpu(DevMem2Db src, int sdepth, DevMem2Db dst, int ddepth, double alpha, double beta, cudaStream_t stream) { typedef void (*caller_t)(DevMem2Db src, DevMem2Db dst, double alpha, double beta, cudaStream_t stream); @@ -318,4 +323,8 @@ namespace cv { namespace gpu { namespace device func(src, dst, alpha, beta, stream); } + +#if defined __clang__ +# pragma clang diagnostic pop +#endif }}} // namespace cv { namespace gpu { namespace device diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index c901bf492..105a5ff15 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -1199,10 +1199,6 @@ namespace void setTo(GpuMat& m, Scalar s, const GpuMat& mask) const { - NppiSize sz; - sz.width = m.cols; - sz.height = m.rows; - if (mask.empty()) { if (s[0] == 0.0 && s[1] == 0.0 && s[2] == 0.0 && s[3] == 0.0) From 9c13b84e35b8108dd958416451e404eeccb9a37b Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 00:06:12 +0400 Subject: [PATCH 10/40] fixed unused warnings --- modules/gpu/perf/perf_core.cpp | 3 ++ modules/gpu/perf_cpu/perf_core.cpp | 3 ++ modules/gpu/src/calib3d.cpp | 21 ++++----- modules/gpu/src/cascadeclassifier.cpp | 8 ++-- modules/gpu/src/match_template.cpp | 65 ++++++++++++++------------- modules/gpu/src/split_merge.cpp | 1 - modules/gpu/test/test_objdetect.cpp | 21 ++++----- 7 files changed, 65 insertions(+), 57 deletions(-) diff --git a/modules/gpu/perf/perf_core.cpp b/modules/gpu/perf/perf_core.cpp index f41343204..588bae59d 100644 --- a/modules/gpu/perf/perf_core.cpp +++ b/modules/gpu/perf/perf_core.cpp @@ -1607,6 +1607,7 @@ GPU_PERF_TEST(Norm, cv::gpu::DeviceInfo, cv::Size, MatDepth, NormType) { dst = cv::gpu::norm(src, normType, buf); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, Norm, testing::Combine( @@ -1642,6 +1643,7 @@ GPU_PERF_TEST(NormDiff, cv::gpu::DeviceInfo, cv::Size, NormType) { dst = cv::gpu::norm(src1, src2, normType); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, NormDiff, testing::Combine( @@ -1829,6 +1831,7 @@ GPU_PERF_TEST(CountNonZero, cv::gpu::DeviceInfo, cv::Size, MatDepth) { dst = cv::gpu::countNonZero(src, buf); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, CountNonZero, testing::Combine( diff --git a/modules/gpu/perf_cpu/perf_core.cpp b/modules/gpu/perf_cpu/perf_core.cpp index fb8700958..24e19a8ab 100644 --- a/modules/gpu/perf_cpu/perf_core.cpp +++ b/modules/gpu/perf_cpu/perf_core.cpp @@ -1229,6 +1229,7 @@ GPU_PERF_TEST(Norm, cv::gpu::DeviceInfo, cv::Size, MatDepth, NormType) { dst = cv::norm(src, normType); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, Norm, testing::Combine( @@ -1259,6 +1260,7 @@ GPU_PERF_TEST(NormDiff, cv::gpu::DeviceInfo, cv::Size, NormType) { dst = cv::norm(src1, src2, normType); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, NormDiff, testing::Combine( @@ -1338,6 +1340,7 @@ GPU_PERF_TEST(CountNonZero, cv::gpu::DeviceInfo, cv::Size, MatDepth) { dst = cv::countNonZero(src); } + (void)dst; } INSTANTIATE_TEST_CASE_P(Core, CountNonZero, testing::Combine( diff --git a/modules/gpu/src/calib3d.cpp b/modules/gpu/src/calib3d.cpp index bc522f372..889799626 100644 --- a/modules/gpu/src/calib3d.cpp +++ b/modules/gpu/src/calib3d.cpp @@ -56,14 +56,14 @@ void cv::gpu::solvePnPRansac(const Mat&, const Mat&, const Mat&, const Mat&, Mat #else -namespace cv { namespace gpu { namespace device +namespace cv { namespace gpu { namespace device { - namespace transform_points + namespace transform_points { void call(const DevMem2D_ src, const float* rot, const float* transl, DevMem2D_ dst, cudaStream_t stream); } - namespace project_points + namespace project_points { void call(const DevMem2D_ src, const float* rot, const float* transl, const float* proj, DevMem2D_ dst, cudaStream_t stream); } @@ -154,11 +154,11 @@ namespace class TransformHypothesesGenerator { public: - TransformHypothesesGenerator(const Mat& object_, const Mat& image_, const Mat& dist_coef_, - const Mat& camera_mat_, int num_points_, int subset_size_, + TransformHypothesesGenerator(const Mat& object_, const Mat& image_, const Mat& dist_coef_, + const Mat& camera_mat_, int num_points_, int subset_size_, Mat rot_matrices_, Mat transl_vectors_) - : object(&object_), image(&image_), dist_coef(&dist_coef_), camera_mat(&camera_mat_), - num_points(num_points_), subset_size(subset_size_), rot_matrices(rot_matrices_), + : object(&object_), image(&image_), dist_coef(&dist_coef_), camera_mat(&camera_mat_), + num_points(num_points_), subset_size(subset_size_), rot_matrices(rot_matrices_), transl_vectors(transl_vectors_) {} void operator()(const BlockedRange& range) const @@ -211,9 +211,10 @@ namespace void cv::gpu::solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat, const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess, - int num_iters, float max_dist, int min_inlier_count, + int num_iters, float max_dist, int min_inlier_count, vector* inliers) { + (void)min_inlier_count; CV_Assert(object.rows == 1 && object.cols > 0 && object.type() == CV_32FC3); CV_Assert(image.rows == 1 && image.cols > 0 && image.type() == CV_32FC2); CV_Assert(object.cols == image.cols); @@ -236,7 +237,7 @@ void cv::gpu::solvePnPRansac(const Mat& object, const Mat& image, const Mat& cam Mat transl_vectors(1, num_iters * 3, CV_32F); // Generate set of hypotheses using small subsets of the input data - TransformHypothesesGenerator body(object, image_normalized, empty_dist_coef, eye_camera_mat, + TransformHypothesesGenerator body(object, image_normalized, empty_dist_coef, eye_camera_mat, num_points, subset_size, rot_matrices, transl_vectors); parallel_for(BlockedRange(0, num_iters), body); @@ -246,7 +247,7 @@ void cv::gpu::solvePnPRansac(const Mat& object, const Mat& image, const Mat& cam GpuMat d_hypothesis_scores(1, num_iters, CV_32S); solve_pnp_ransac::computeHypothesisScores( num_iters, num_points, rot_matrices.ptr(), transl_vectors.ptr(), - d_object.ptr(), d_image_normalized.ptr(), max_dist * max_dist, + d_object.ptr(), d_image_normalized.ptr(), max_dist * max_dist, d_hypothesis_scores.ptr()); // Find the best hypothesis index diff --git a/modules/gpu/src/cascadeclassifier.cpp b/modules/gpu/src/cascadeclassifier.cpp index 1f277f0cf..570cb7a80 100644 --- a/modules/gpu/src/cascadeclassifier.cpp +++ b/modules/gpu/src/cascadeclassifier.cpp @@ -143,7 +143,7 @@ public: } unsigned int process(const GpuMat& image, GpuMat& objectsBuf, float scaleFactor, int minNeighbors, - bool findLargestObject, bool visualizeInPlace, cv::Size minSize, cv::Size maxObjectSize) + bool findLargestObject, bool visualizeInPlace, cv::Size minSize, cv::Size /*maxObjectSize*/) { CV_Assert( scaleFactor > 1 && image.depth() == CV_8U); @@ -380,12 +380,12 @@ public: LbpCascade(){} virtual ~LbpCascade(){} - virtual unsigned int process(const GpuMat& image, GpuMat& objects, float scaleFactor, int groupThreshold, bool findLargestObject, - bool visualizeInPlace, cv::Size minObjectSize, cv::Size maxObjectSize) + virtual unsigned int process(const GpuMat& image, GpuMat& objects, float scaleFactor, int groupThreshold, bool /*findLargestObject*/, + bool /*visualizeInPlace*/, cv::Size minObjectSize, cv::Size maxObjectSize) { CV_Assert(scaleFactor > 1 && image.depth() == CV_8U); - const int defaultObjSearchNum = 100; + // const int defaultObjSearchNum = 100; const float grouping_eps = 0.2f; if( !objects.empty() && objects.depth() == CV_32S) diff --git a/modules/gpu/src/match_template.cpp b/modules/gpu/src/match_template.cpp index c4a818068..c988000a5 100644 --- a/modules/gpu/src/match_template.cpp +++ b/modules/gpu/src/match_template.cpp @@ -52,9 +52,9 @@ void cv::gpu::matchTemplate(const GpuMat&, const GpuMat&, GpuMat&, int, Stream&) #else -namespace cv { namespace gpu { namespace device +namespace cv { namespace gpu { namespace device { - namespace match_template + namespace match_template { void matchTemplateNaive_CCORR_8U(const DevMem2Db image, const DevMem2Db templ, DevMem2Df result, int cn, cudaStream_t stream); void matchTemplateNaive_CCORR_32F(const DevMem2Db image, const DevMem2Db templ, DevMem2Df result, int cn, cudaStream_t stream); @@ -71,47 +71,47 @@ namespace cv { namespace gpu { namespace device void matchTemplatePrepared_CCOFF_8U(int w, int h, const DevMem2D_ image_sum, unsigned int templ_sum, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_8UC2( int w, int h, - const DevMem2D_ image_sum_r, - const DevMem2D_ image_sum_g, + const DevMem2D_ image_sum_r, + const DevMem2D_ image_sum_g, unsigned int templ_sum_r, - unsigned int templ_sum_g, + unsigned int templ_sum_g, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_8UC3( - int w, int h, - const DevMem2D_ image_sum_r, + int w, int h, + const DevMem2D_ image_sum_r, const DevMem2D_ image_sum_g, const DevMem2D_ image_sum_b, - unsigned int templ_sum_r, - unsigned int templ_sum_g, - unsigned int templ_sum_b, + unsigned int templ_sum_r, + unsigned int templ_sum_g, + unsigned int templ_sum_b, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_8UC4( - int w, int h, - const DevMem2D_ image_sum_r, + int w, int h, + const DevMem2D_ image_sum_r, const DevMem2D_ image_sum_g, const DevMem2D_ image_sum_b, const DevMem2D_ image_sum_a, - unsigned int templ_sum_r, - unsigned int templ_sum_g, - unsigned int templ_sum_b, - unsigned int templ_sum_a, + unsigned int templ_sum_r, + unsigned int templ_sum_g, + unsigned int templ_sum_b, + unsigned int templ_sum_a, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_NORMED_8U( - int w, int h, const DevMem2D_ image_sum, + int w, int h, const DevMem2D_ image_sum, const DevMem2D_ image_sqsum, unsigned int templ_sum, unsigned long long templ_sqsum, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_NORMED_8UC2( - int w, int h, + int w, int h, const DevMem2D_ image_sum_r, const DevMem2D_ image_sqsum_r, const DevMem2D_ image_sum_g, const DevMem2D_ image_sqsum_g, unsigned int templ_sum_r, unsigned long long templ_sqsum_r, unsigned int templ_sum_g, unsigned long long templ_sqsum_g, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_NORMED_8UC3( - int w, int h, + int w, int h, const DevMem2D_ image_sum_r, const DevMem2D_ image_sqsum_r, const DevMem2D_ image_sum_g, const DevMem2D_ image_sqsum_g, const DevMem2D_ image_sum_b, const DevMem2D_ image_sqsum_b, @@ -120,7 +120,7 @@ namespace cv { namespace gpu { namespace device unsigned int templ_sum_b, unsigned long long templ_sqsum_b, DevMem2Df result, cudaStream_t stream); void matchTemplatePrepared_CCOFF_NORMED_8UC4( - int w, int h, + int w, int h, const DevMem2D_ image_sum_r, const DevMem2D_ image_sqsum_r, const DevMem2D_ image_sum_g, const DevMem2D_ image_sqsum_g, const DevMem2D_ image_sum_b, const DevMem2D_ image_sqsum_b, @@ -131,7 +131,7 @@ namespace cv { namespace gpu { namespace device unsigned int templ_sum_a, unsigned long long templ_sqsum_a, DevMem2Df result, cudaStream_t stream); - void normalize_8U(int w, int h, const DevMem2D_ image_sqsum, + void normalize_8U(int w, int h, const DevMem2D_ image_sqsum, unsigned long long templ_sqsum, DevMem2Df result, int cn, cudaStream_t stream); void extractFirstChannel_32F(const DevMem2Db image, DevMem2Df result, int cn, cudaStream_t stream); @@ -140,17 +140,17 @@ namespace cv { namespace gpu { namespace device using namespace ::cv::gpu::device::match_template; -namespace +namespace { - // Evaluates optimal template's area threshold. If - // template's area is less than the threshold, we use naive match + // Evaluates optimal template's area threshold. If + // template's area is less than the threshold, we use naive match // template version, otherwise FFT-based (if available) int getTemplateThreshold(int method, int depth) { switch (method) { - case CV_TM_CCORR: + case CV_TM_CCORR: if (depth == CV_32F) return 250; if (depth == CV_8U) return 300; break; @@ -162,10 +162,10 @@ namespace return 0; } - + void matchTemplate_CCORR_32F( const GpuMat& image, const GpuMat& templ, GpuMat& result, MatchTemplateBuf &buf, Stream& stream) - { + { result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); if (templ.size().area() < getTemplateThreshold(CV_TM_CCORR, CV_32F)) { @@ -223,10 +223,11 @@ namespace normalize_8U(templ.cols, templ.rows, buf.image_sqsums[0], templ_sqsum, result, image.channels(), StreamAccessor::getStream(stream)); } - + void matchTemplate_SQDIFF_32F( const GpuMat& image, const GpuMat& templ, GpuMat& result, MatchTemplateBuf &buf, Stream& stream) { + (void)buf; result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); matchTemplateNaive_SQDIFF_32F(image, templ, result, image.channels(), StreamAccessor::getStream(stream)); } @@ -362,7 +363,7 @@ namespace { case 2: matchTemplatePrepared_CCOFF_NORMED_8UC2( - templ.cols, templ.rows, + templ.cols, templ.rows, buf.image_sums[0], buf.image_sqsums[0], buf.image_sums[1], buf.image_sqsums[1], (unsigned int)templ_sum[0], (unsigned long long)templ_sqsum[0], @@ -371,7 +372,7 @@ namespace break; case 3: matchTemplatePrepared_CCOFF_NORMED_8UC3( - templ.cols, templ.rows, + templ.cols, templ.rows, buf.image_sums[0], buf.image_sqsums[0], buf.image_sums[1], buf.image_sqsums[1], buf.image_sums[2], buf.image_sqsums[2], @@ -382,7 +383,7 @@ namespace break; case 4: matchTemplatePrepared_CCOFF_NORMED_8UC4( - templ.cols, templ.rows, + templ.cols, templ.rows, buf.image_sums[0], buf.image_sqsums[0], buf.image_sums[1], buf.image_sqsums[1], buf.image_sums[2], buf.image_sqsums[2], @@ -391,7 +392,7 @@ namespace (unsigned int)templ_sum[1], (unsigned long long)templ_sqsum[1], (unsigned int)templ_sum[2], (unsigned long long)templ_sqsum[2], (unsigned int)templ_sum[3], (unsigned long long)templ_sqsum[3], - result, StreamAccessor::getStream(stream)); + result, StreamAccessor::getStream(stream)); break; default: CV_Error(CV_StsBadArg, "matchTemplate: unsupported number of channels"); diff --git a/modules/gpu/src/split_merge.cpp b/modules/gpu/src/split_merge.cpp index 2d5b1b13c..3153c5f33 100644 --- a/modules/gpu/src/split_merge.cpp +++ b/modules/gpu/src/split_merge.cpp @@ -119,7 +119,6 @@ namespace int depth = src.depth(); int num_channels = src.channels(); - Size size = src.size(); if (depth == CV_64F) { diff --git a/modules/gpu/test/test_objdetect.cpp b/modules/gpu/test/test_objdetect.cpp index 927762b2b..f867533c8 100644 --- a/modules/gpu/test/test_objdetect.cpp +++ b/modules/gpu/test/test_objdetect.cpp @@ -302,13 +302,13 @@ PARAM_TEST_CASE(LBP_Read_classifier, cv::gpu::DeviceInfo, int) TEST_P(LBP_Read_classifier, Accuracy) { - cv::gpu::CascadeClassifier_GPU classifier; + cv::gpu::CascadeClassifier_GPU classifier; std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml"; ASSERT_TRUE(classifier.load(classifierXmlPath)); } -INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier, - testing::Combine(ALL_DEVICES, testing::Values(0))); +INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier, + testing::Combine(ALL_DEVICES, testing::Values(0))); PARAM_TEST_CASE(LBP_classify, cv::gpu::DeviceInfo, int) @@ -344,31 +344,32 @@ TEST_P(LBP_classify, Accuracy) for (; it != rects.end(); ++it) cv::rectangle(markedImage, *it, CV_RGB(0, 0, 255)); - cv::gpu::CascadeClassifier_GPU gpuClassifier; + cv::gpu::CascadeClassifier_GPU gpuClassifier; ASSERT_TRUE(gpuClassifier.load(classifierXmlPath)); cv::gpu::GpuMat gpu_rects; cv::gpu::GpuMat tested(grey); int count = gpuClassifier.detectMultiScale(tested, gpu_rects); +#if defined (LOG_CASCADE_STATISTIC) cv::Mat downloaded(gpu_rects); - const cv::Rect* faces = downloaded.ptr(); + const cv::Rect* faces = downloaded.ptr(); for (int i = 0; i < count; i++) { cv::Rect r = faces[i]; -#if defined (LOG_CASCADE_STATISTIC) - std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; + std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; cv::rectangle(markedImage, r , CV_RGB(255, 0, 0)); -#endif } +#endif #if defined (LOG_CASCADE_STATISTIC) - cv::imshow("Res", markedImage); cv::waitKey(); + cv::imshow("Res", markedImage); cv::waitKey(); #endif + (void)count; } INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_classify, - testing::Combine(ALL_DEVICES, testing::Values(0))); + testing::Combine(ALL_DEVICES, testing::Values(0))); } // namespace From aeaf1a6f6d724552f3b7dd4c5dbcd1d0652a6e78 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 02:26:23 +0400 Subject: [PATCH 11/40] refactoring in Emulation --- modules/gpu/src/cuda/ccomponetns.cu | 4 ++-- modules/gpu/src/cuda/lbp.cu | 2 +- modules/gpu/src/opencv2/gpu/device/emulation.hpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/gpu/src/cuda/ccomponetns.cu b/modules/gpu/src/cuda/ccomponetns.cu index 275066a2a..07f2410ca 100644 --- a/modules/gpu/src/cuda/ccomponetns.cu +++ b/modules/gpu/src/cuda/ccomponetns.cu @@ -316,7 +316,7 @@ namespace cv { namespace gpu { namespace device } } - changed = Emulation::sycthOr(changed); + changed = Emulation::syncthreadsOr(changed); if (!changed) break; @@ -474,7 +474,7 @@ namespace cv { namespace gpu { namespace device } } } - } while (Emulation::sycthOr(changed)); + } while (Emulation::syncthreadsOr(changed)); } __global__ void flatten(const DevMem2D edges, DevMem2Di comps) diff --git a/modules/gpu/src/cuda/lbp.cu b/modules/gpu/src/cuda/lbp.cu index e96692cef..edfbf6ea5 100644 --- a/modules/gpu/src/cuda/lbp.cu +++ b/modules/gpu/src/cuda/lbp.cu @@ -279,7 +279,7 @@ namespace cv { namespace gpu { namespace device rect.z = __float2int_rn(windowW * scale); rect.w = __float2int_rn(windowH * scale); - int res = Emulation::smem::atomicInc(classified, (unsigned int)objects.cols); + int res = atomicInc(classified, (unsigned int)objects.cols); objects(0, res) = rect; } } diff --git a/modules/gpu/src/opencv2/gpu/device/emulation.hpp b/modules/gpu/src/opencv2/gpu/device/emulation.hpp index 1a6f5794c..074e91127 100644 --- a/modules/gpu/src/opencv2/gpu/device/emulation.hpp +++ b/modules/gpu/src/opencv2/gpu/device/emulation.hpp @@ -51,11 +51,11 @@ namespace cv { namespace gpu { namespace device struct Emulation { - static __device__ __forceinline__ int sycthOr(int pred) + static __device__ __forceinline__ int syncthreadsOr(int pred) { #if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 200) // just campilation stab - return false; + return 0; #else return __syncthreads_or(pred); #endif From ede3781e3efdcf7e5333638c0808ea80190aa4dd Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 02:27:54 +0400 Subject: [PATCH 12/40] fixed -Wstrict_alliasing warning for GCC --- modules/gpu/src/imgproc.cpp | 8 ++++- .../gpu/src/nvidia/NCVHaarObjectDetection.hpp | 32 ++++++++++++------- .../gpu/src/nvidia/NPP_staging/NPP_staging.cu | 18 +++++++---- .../nvidia/TestHaarCascadeApplication.cpp | 6 ++-- modules/gpu/test/nvidia/main_nvidia.cpp | 4 ++- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 31ab44cb8..fe1ad7bd8 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -261,6 +261,12 @@ namespace } } +#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +typedef Npp32s __attribute__((__may_alias__)) Npp32s_a; +#else +typedef Npp32s Npp32s_a; +#endif + void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType, const Scalar& value, Stream& s) { CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); @@ -308,7 +314,7 @@ void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom case CV_32FC1: { Npp32f val = saturate_cast(value[0]); - Npp32s nVal = *(reinterpret_cast(&val)); + Npp32s nVal = *(reinterpret_cast(&val)); nppSafeCall( nppiCopyConstBorder_32s_C1R(src.ptr(), static_cast(src.step), srcsz, dst.ptr(), static_cast(dst.step), dstsz, top, left, nVal) ); break; diff --git a/modules/gpu/src/nvidia/NCVHaarObjectDetection.hpp b/modules/gpu/src/nvidia/NCVHaarObjectDetection.hpp index 79872cbfa..fd0e53e90 100644 --- a/modules/gpu/src/nvidia/NCVHaarObjectDetection.hpp +++ b/modules/gpu/src/nvidia/NCVHaarObjectDetection.hpp @@ -67,7 +67,11 @@ // Guaranteed size cross-platform classifier structures // //============================================================================== - +#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +typedef Ncv32f __attribute__((__may_alias__)) Ncv32f_a; +#else +typedef Ncv32f Ncv32f_a; +#endif struct HaarFeature64 { @@ -87,7 +91,7 @@ struct HaarFeature64 __host__ NCVStatus setWeight(Ncv32f weight) { - ((Ncv32f*)&(this->_ui2.y))[0] = weight; + ((Ncv32f_a*)&(this->_ui2.y))[0] = weight; return NCV_SUCCESS; } @@ -102,7 +106,7 @@ struct HaarFeature64 __device__ __host__ Ncv32f getWeight(void) { - return *(Ncv32f*)(&this->_ui2.y); + return *(Ncv32f_a*)(&this->_ui2.y); } }; @@ -168,14 +172,13 @@ public: } }; - struct HaarClassifierNodeDescriptor32 { uint1 _ui1; __host__ NCVStatus create(Ncv32f leafValue) { - *(Ncv32f *)&this->_ui1 = leafValue; + *(Ncv32f_a *)&this->_ui1 = leafValue; return NCV_SUCCESS; } @@ -187,7 +190,7 @@ struct HaarClassifierNodeDescriptor32 __host__ Ncv32f getLeafValueHost(void) { - return *(Ncv32f *)&this->_ui1.x; + return *(Ncv32f_a *)&this->_ui1.x; } #ifdef __CUDACC__ @@ -203,6 +206,11 @@ struct HaarClassifierNodeDescriptor32 } }; +#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +typedef Ncv32u __attribute__((__may_alias__)) Ncv32u_a; +#else +typedef Ncv32u Ncv32u_a; +#endif struct HaarClassifierNode128 { @@ -216,19 +224,19 @@ struct HaarClassifierNode128 __host__ NCVStatus setThreshold(Ncv32f t) { - this->_ui4.y = *(Ncv32u *)&t; + this->_ui4.y = *(Ncv32u_a *)&t; return NCV_SUCCESS; } __host__ NCVStatus setLeftNodeDesc(HaarClassifierNodeDescriptor32 nl) { - this->_ui4.z = *(Ncv32u *)&nl; + this->_ui4.z = *(Ncv32u_a *)&nl; return NCV_SUCCESS; } __host__ NCVStatus setRightNodeDesc(HaarClassifierNodeDescriptor32 nr) { - this->_ui4.w = *(Ncv32u *)&nr; + this->_ui4.w = *(Ncv32u_a *)&nr; return NCV_SUCCESS; } @@ -239,7 +247,7 @@ struct HaarClassifierNode128 __host__ __device__ Ncv32f getThreshold(void) { - return *(Ncv32f*)&this->_ui4.y; + return *(Ncv32f_a*)&this->_ui4.y; } __host__ __device__ HaarClassifierNodeDescriptor32 getLeftNodeDesc(void) @@ -264,7 +272,7 @@ struct HaarStage64 __host__ NCVStatus setStageThreshold(Ncv32f t) { - this->_ui2.x = *(Ncv32u *)&t; + this->_ui2.x = *(Ncv32u_a *)&t; return NCV_SUCCESS; } @@ -290,7 +298,7 @@ struct HaarStage64 __host__ __device__ Ncv32f getStageThreshold(void) { - return *(Ncv32f*)&this->_ui2.x; + return *(Ncv32f_a*)&this->_ui2.x; } __host__ __device__ Ncv32u getStartClassifierRootNodeOffset(void) diff --git a/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu b/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu index 6e0f5eb26..f75453930 100644 --- a/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu +++ b/modules/gpu/src/nvidia/NPP_staging/NPP_staging.cu @@ -1423,7 +1423,7 @@ NCVStatus compactVector_32u_device(Ncv32u *d_src, Ncv32u srcLen, (d_hierSums.ptr() + partSumOffsets[i], partSumNums[i], NULL, d_hierSums.ptr() + partSumOffsets[i+1], - NULL); + 0); } else { @@ -1433,7 +1433,7 @@ NCVStatus compactVector_32u_device(Ncv32u *d_src, Ncv32u srcLen, (d_hierSums.ptr() + partSumOffsets[i], partSumNums[i], NULL, NULL, - NULL); + 0); } ncvAssertCUDALastErrorReturn(NPPST_CUDA_KERNEL_EXECUTION_ERROR); @@ -1557,16 +1557,21 @@ NCVStatus nppsStCompact_32s(Ncv32s *d_src, Ncv32u srcLen, } +#if defined __GNUC__ && __GNUC__ > 2 && __GNUC_MINOR__ > 4 +typedef Ncv32u __attribute__((__may_alias__)) Ncv32u_a; +#else +typedef Ncv32u Ncv32u_a; +#endif + NCVStatus nppsStCompact_32f(Ncv32f *d_src, Ncv32u srcLen, Ncv32f *d_dst, Ncv32u *p_dstLen, Ncv32f elemRemove, Ncv8u *pBuffer, Ncv32u bufSize, cudaDeviceProp &devProp) { return nppsStCompact_32u((Ncv32u *)d_src, srcLen, (Ncv32u *)d_dst, p_dstLen, - *(Ncv32u *)&elemRemove, pBuffer, bufSize, devProp); + *(Ncv32u_a *)&elemRemove, pBuffer, bufSize, devProp); } - NCVStatus nppsStCompact_32u_host(Ncv32u *h_src, Ncv32u srcLen, Ncv32u *h_dst, Ncv32u *dstLen, Ncv32u elemRemove) { @@ -1602,17 +1607,16 @@ NCVStatus nppsStCompact_32u_host(Ncv32u *h_src, Ncv32u srcLen, NCVStatus nppsStCompact_32s_host(Ncv32s *h_src, Ncv32u srcLen, Ncv32s *h_dst, Ncv32u *dstLen, Ncv32s elemRemove) { - return nppsStCompact_32u_host((Ncv32u *)h_src, srcLen, (Ncv32u *)h_dst, dstLen, *(Ncv32u *)&elemRemove); + return nppsStCompact_32u_host((Ncv32u *)h_src, srcLen, (Ncv32u *)h_dst, dstLen, *(Ncv32u_a *)&elemRemove); } NCVStatus nppsStCompact_32f_host(Ncv32f *h_src, Ncv32u srcLen, Ncv32f *h_dst, Ncv32u *dstLen, Ncv32f elemRemove) { - return nppsStCompact_32u_host((Ncv32u *)h_src, srcLen, (Ncv32u *)h_dst, dstLen, *(Ncv32u *)&elemRemove); + return nppsStCompact_32u_host((Ncv32u *)h_src, srcLen, (Ncv32u *)h_dst, dstLen, *(Ncv32u_a *)&elemRemove); } - //============================================================================== // // Filter.cu diff --git a/modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp b/modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp index e53f7f3a4..fe4f5d6a3 100644 --- a/modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp +++ b/modules/gpu/test/nvidia/TestHaarCascadeApplication.cpp @@ -245,8 +245,8 @@ bool TestHaarCascadeApplication::process() int devId; ncvAssertCUDAReturn(cudaGetDevice(&devId), false); - cudaDeviceProp devProp; - ncvAssertCUDAReturn(cudaGetDeviceProperties(&devProp, devId), false); + cudaDeviceProp _devProp; + ncvAssertCUDAReturn(cudaGetDeviceProperties(&_devProp, devId), false); ncvStat = ncvApplyHaarClassifierCascade_device( d_integralImage, d_rectStdDev, d_pixelMask, @@ -254,7 +254,7 @@ bool TestHaarCascadeApplication::process() haar, h_HaarStages, d_HaarStages, d_HaarNodes, d_HaarFeatures, false, searchRoiU, 1, 1.0f, *this->allocatorGPU.get(), *this->allocatorCPU.get(), - devProp, 0); + _devProp, 0); ncvAssertReturn(ncvStat == NCV_SUCCESS, false); NCVMatrixAlloc h_pixelMask_d(*this->allocatorCPU.get(), this->width, this->height); diff --git a/modules/gpu/test/nvidia/main_nvidia.cpp b/modules/gpu/test/nvidia/main_nvidia.cpp index bb6160894..15759e10f 100644 --- a/modules/gpu/test/nvidia/main_nvidia.cpp +++ b/modules/gpu/test/nvidia/main_nvidia.cpp @@ -1,4 +1,6 @@ -#pragma warning (disable : 4408 4201 4100) +#if defined _MSC_VER && _MSC_VER >= 1200 +# pragma warning (disable : 4408 4201 4100) +#endif #include From 15213401529574ba4f4ae81d04dd01ec61f83991 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 03:25:52 +0400 Subject: [PATCH 13/40] updated CascadeClassifier_GPU documentation --- modules/gpu/doc/object_detection.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/gpu/doc/object_detection.rst b/modules/gpu/doc/object_detection.rst index 1f522f344..133660236 100644 --- a/modules/gpu/doc/object_detection.rst +++ b/modules/gpu/doc/object_detection.rst @@ -204,7 +204,7 @@ gpu::CascadeClassifier_GPU -------------------------- .. ocv:class:: gpu::CascadeClassifier_GPU -Cascade classifier class used for object detection. :: +Cascade classifier class used for object detection. Supports HAAR and LBP cascades. :: class CV_EXPORTS CascadeClassifier_GPU { @@ -219,6 +219,7 @@ Cascade classifier class used for object detection. :: /* 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); /* Finds only the largest object. Special mode if training is required.*/ bool findLargestObject; @@ -233,11 +234,11 @@ Cascade classifier class used for object detection. :: gpu::CascadeClassifier_GPU::CascadeClassifier_GPU ----------------------------------------------------- -Loads the classifier from a file. +Loads the classifier from a file. Cascade type is detected automatically by constructor parameter. .. ocv:function:: gpu::CascadeClassifier_GPU::CascadeClassifier_GPU(const string& filename) - :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported. + :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported for HAAR and only new type of OpenCV XML cascade supported for LBP. @@ -255,8 +256,7 @@ Loads the classifier from a file. The previous content is destroyed. .. ocv:function:: bool gpu::CascadeClassifier_GPU::load(const string& filename) - :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported. - + :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported for HAAR and only new type of OpenCV XML cascade supported for LBP. gpu::CascadeClassifier_GPU::release @@ -273,13 +273,17 @@ Detects objects of different sizes in the input image. .. ocv:function:: int gpu::CascadeClassifier_GPU::detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size()) +.. ocv:function:: int gpu::CascadeClassifier_GPU::detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4) + :param image: Matrix of type ``CV_8U`` containing an image where objects should be detected. :param objectsBuf: Buffer to store detected objects (rectangles). If it is empty, it is allocated with the default size. If not empty, the function searches not more than N objects, where ``N = sizeof(objectsBufer's data)/sizeof(cv::Rect)``. - :param scaleFactor: Value to specify how much the image size is reduced at each image scale. + :param maxObjectSize: Maximum possible object size. Objects larger than that are ignored. Used for second signature and supported only for LBP cascades. - :param minNeighbors: Value to specify how many neighbours each candidate rectangle has to retain. + :param scaleFactor: Parameter specifying how much the image size is reduced at each image scale. + + :param minNeighbors: Parameter specifying how many neighbors each candidate rectangle should have to retain it. :param minSize: Minimum possible object size. Objects smaller than that are ignored. From f17f4bda6026ea02668c1a6ccf8f0726b1ed8682 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 03:26:53 +0400 Subject: [PATCH 14/40] more warning fixes for GCC --- modules/gpu/src/brute_force_matcher.cpp | 50 ++++++++++++------------- modules/gpu/src/hog.cpp | 6 +-- modules/gpu/src/video_decoder.cpp | 40 ++++++++++---------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/modules/gpu/src/brute_force_matcher.cpp b/modules/gpu/src/brute_force_matcher.cpp index d70926068..a1fe06613 100644 --- a/modules/gpu/src/brute_force_matcher.cpp +++ b/modules/gpu/src/brute_force_matcher.cpp @@ -420,16 +420,16 @@ void cv::gpu::BFMatcher_GPU::matchConvert(const Mat& trainIdx, const Mat& imgIdx const float* distance_ptr = distance.ptr(); for (int queryIdx = 0; queryIdx < nQuery; ++queryIdx, ++trainIdx_ptr, ++imgIdx_ptr, ++distance_ptr) { - int trainIdx = *trainIdx_ptr; + int _trainIdx = *trainIdx_ptr; - if (trainIdx == -1) + if (_trainIdx == -1) continue; - int imgIdx = *imgIdx_ptr; + int _imgIdx = *imgIdx_ptr; - float distance = *distance_ptr; + float _distance = *distance_ptr; - DMatch m(queryIdx, trainIdx, imgIdx, distance); + DMatch m(queryIdx, _trainIdx, _imgIdx, _distance); matches.push_back(m); } @@ -558,13 +558,13 @@ void cv::gpu::BFMatcher_GPU::knnMatchConvert(const Mat& trainIdx, const Mat& dis for (int i = 0; i < k; ++i, ++trainIdx_ptr, ++distance_ptr) { - int trainIdx = *trainIdx_ptr; + int _trainIdx = *trainIdx_ptr; - if (trainIdx != -1) + if (_trainIdx != -1) { - float distance = *distance_ptr; + float _distance = *distance_ptr; - DMatch m(queryIdx, trainIdx, 0, distance); + DMatch m(queryIdx, _trainIdx, 0, _distance); curMatches.push_back(m); } @@ -680,15 +680,15 @@ void cv::gpu::BFMatcher_GPU::knnMatch2Convert(const Mat& trainIdx, const Mat& im for (int i = 0; i < 2; ++i, ++trainIdx_ptr, ++imgIdx_ptr, ++distance_ptr) { - int trainIdx = *trainIdx_ptr; + int _trainIdx = *trainIdx_ptr; - if (trainIdx != -1) + if (_trainIdx != -1) { - int imgIdx = *imgIdx_ptr; + int _imgIdx = *imgIdx_ptr; - float distance = *distance_ptr; + float _distance = *distance_ptr; - DMatch m(queryIdx, trainIdx, imgIdx, distance); + DMatch m(queryIdx, _trainIdx, _imgIdx, _distance); curMatches.push_back(m); } @@ -868,25 +868,25 @@ void cv::gpu::BFMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& const int* trainIdx_ptr = trainIdx.ptr(queryIdx); const float* distance_ptr = distance.ptr(queryIdx); - const int nMatches = std::min(nMatches_ptr[queryIdx], trainIdx.cols); + const int nMatched = std::min(nMatches_ptr[queryIdx], trainIdx.cols); - if (nMatches == 0) + if (nMatched == 0) { if (!compactResult) matches.push_back(vector()); continue; } - matches.push_back(vector(nMatches)); + matches.push_back(vector(nMatched)); vector& curMatches = matches.back(); - for (int i = 0; i < nMatches; ++i, ++trainIdx_ptr, ++distance_ptr) + for (int i = 0; i < nMatched; ++i, ++trainIdx_ptr, ++distance_ptr) { - int trainIdx = *trainIdx_ptr; + int _trainIdx = *trainIdx_ptr; - float distance = *distance_ptr; + float _distance = *distance_ptr; - DMatch m(queryIdx, trainIdx, 0, distance); + DMatch m(queryIdx, _trainIdx, 0, _distance); curMatches[i] = m; } @@ -1009,9 +1009,9 @@ void cv::gpu::BFMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& const int* imgIdx_ptr = imgIdx.ptr(queryIdx); const float* distance_ptr = distance.ptr(queryIdx); - const int nMatches = std::min(nMatches_ptr[queryIdx], trainIdx.cols); + const int nMatched = std::min(nMatches_ptr[queryIdx], trainIdx.cols); - if (nMatches == 0) + if (nMatched == 0) { if (!compactResult) matches.push_back(vector()); @@ -1020,9 +1020,9 @@ void cv::gpu::BFMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& matches.push_back(vector()); vector& curMatches = matches.back(); - curMatches.reserve(nMatches); + curMatches.reserve(nMatched); - for (int i = 0; i < nMatches; ++i, ++trainIdx_ptr, ++imgIdx_ptr, ++distance_ptr) + for (int i = 0; i < nMatched; ++i, ++trainIdx_ptr, ++imgIdx_ptr, ++distance_ptr) { int _trainIdx = *trainIdx_ptr; int _imgIdx = *imgIdx_ptr; diff --git a/modules/gpu/src/hog.cpp b/modules/gpu/src/hog.cpp index fafcce784..5db3be978 100644 --- a/modules/gpu/src/hog.cpp +++ b/modules/gpu/src/hog.cpp @@ -315,7 +315,7 @@ void cv::gpu::HOGDescriptor::computeConfidenceMultiScale(const GpuMat& img, vect double scale = 1.; int levels = 0; - for (levels = 0; levels < conf_out.size(); levels++) + for (levels = 0; levels < (int)conf_out.size(); levels++) { scale = conf_out[levels].scale; level_scale.push_back(scale); @@ -332,8 +332,8 @@ void cv::gpu::HOGDescriptor::computeConfidenceMultiScale(const GpuMat& img, vect for (size_t i = 0; i < level_scale.size(); i++) { - double scale = level_scale[i]; - Size sz(cvRound(img.cols / scale), cvRound(img.rows / scale)); + double _scale = level_scale[i]; + Size sz(cvRound(img.cols / _scale), cvRound(img.rows / _scale)); GpuMat smaller_img; if (sz == img.size()) diff --git a/modules/gpu/src/video_decoder.cpp b/modules/gpu/src/video_decoder.cpp index 9f06adc9c..bee5002a8 100644 --- a/modules/gpu/src/video_decoder.cpp +++ b/modules/gpu/src/video_decoder.cpp @@ -49,36 +49,36 @@ void cv::gpu::detail::VideoDecoder::create(const VideoReader_GPU::FormatInfo& vi { release(); - cudaVideoCodec codec = static_cast(videoFormat.codec); - cudaVideoChromaFormat chromaFormat = static_cast(videoFormat.chromaFormat); + cudaVideoCodec _codec = static_cast(videoFormat.codec); + cudaVideoChromaFormat _chromaFormat = static_cast(videoFormat.chromaFormat); - cudaVideoCreateFlags videoCreateFlags = (codec == cudaVideoCodec_JPEG || codec == cudaVideoCodec_MPEG2) ? + cudaVideoCreateFlags videoCreateFlags = (_codec == cudaVideoCodec_JPEG || _codec == cudaVideoCodec_MPEG2) ? cudaVideoCreate_PreferCUDA : cudaVideoCreate_PreferCUVID; // Validate video format. These are the currently supported formats via NVCUVID - CV_Assert(cudaVideoCodec_MPEG1 == codec || - cudaVideoCodec_MPEG2 == codec || - cudaVideoCodec_MPEG4 == codec || - cudaVideoCodec_VC1 == codec || - cudaVideoCodec_H264 == codec || - cudaVideoCodec_JPEG == codec || - cudaVideoCodec_YUV420== codec || - cudaVideoCodec_YV12 == codec || - cudaVideoCodec_NV12 == codec || - cudaVideoCodec_YUYV == codec || - cudaVideoCodec_UYVY == codec ); + CV_Assert(cudaVideoCodec_MPEG1 == _codec || + cudaVideoCodec_MPEG2 == _codec || + cudaVideoCodec_MPEG4 == _codec || + cudaVideoCodec_VC1 == _codec || + cudaVideoCodec_H264 == _codec || + cudaVideoCodec_JPEG == _codec || + cudaVideoCodec_YUV420== _codec || + cudaVideoCodec_YV12 == _codec || + cudaVideoCodec_NV12 == _codec || + cudaVideoCodec_YUYV == _codec || + cudaVideoCodec_UYVY == _codec ); - CV_Assert(cudaVideoChromaFormat_Monochrome == chromaFormat || - cudaVideoChromaFormat_420 == chromaFormat || - cudaVideoChromaFormat_422 == chromaFormat || - cudaVideoChromaFormat_444 == chromaFormat); + CV_Assert(cudaVideoChromaFormat_Monochrome == _chromaFormat || + cudaVideoChromaFormat_420 == _chromaFormat || + cudaVideoChromaFormat_422 == _chromaFormat || + cudaVideoChromaFormat_444 == _chromaFormat); // Fill the decoder-create-info struct from the given video-format struct. std::memset(&createInfo_, 0, sizeof(CUVIDDECODECREATEINFO)); // Create video decoder - createInfo_.CodecType = codec; + createInfo_.CodecType = _codec; createInfo_.ulWidth = videoFormat.width; createInfo_.ulHeight = videoFormat.height; createInfo_.ulNumDecodeSurfaces = FrameQueue::MaximumSize; @@ -87,7 +87,7 @@ void cv::gpu::detail::VideoDecoder::create(const VideoReader_GPU::FormatInfo& vi while (createInfo_.ulNumDecodeSurfaces * videoFormat.width * videoFormat.height > 16 * 1024 * 1024) createInfo_.ulNumDecodeSurfaces--; - createInfo_.ChromaFormat = chromaFormat; + createInfo_.ChromaFormat = _chromaFormat; createInfo_.OutputFormat = cudaVideoSurfaceFormat_NV12; createInfo_.DeinterlaceMode = cudaVideoDeinterlaceMode_Adaptive; From e7f4dd1a2e5d648c242af0151b0a183eb7dcd950 Mon Sep 17 00:00:00 2001 From: niko Date: Mon, 20 Aug 2012 10:06:41 +0800 Subject: [PATCH 15/40] temp build fix because the new core.hpp impact on this project --- modules/ocl/src/initialization.cpp | 6 +++--- modules/ocl/src/threadsafe.cpp | 4 ++-- modules/ocl/src/threadsafe.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/ocl/src/initialization.cpp b/modules/ocl/src/initialization.cpp index fab81fd46..096b9790d 100644 --- a/modules/ocl/src/initialization.cpp +++ b/modules/ocl/src/initialization.cpp @@ -44,9 +44,9 @@ //M*/ #include "precomp.hpp" -#include "Threadsafe.h" +#include "threadsafe.h" #include -#include "binaryCaching.hpp" +#include "binarycaching.hpp" using namespace cv; using namespace cv::ocl; @@ -775,7 +775,7 @@ namespace cv { if(val == 0) { - AutoLock al(&cs); + myAutoLock al(&cs); if( NULL == clCxt.get()) clCxt.reset(new Context); diff --git a/modules/ocl/src/threadsafe.cpp b/modules/ocl/src/threadsafe.cpp index 9d952d328..25b3773e0 100644 --- a/modules/ocl/src/threadsafe.cpp +++ b/modules/ocl/src/threadsafe.cpp @@ -43,8 +43,8 @@ // //M*/ -#include "precomp.hpp" -#include "Threadsafe.h" +//#include "precomp.hpp" +#include "threadsafe.h" CriticalSection::CriticalSection() { diff --git a/modules/ocl/src/threadsafe.h b/modules/ocl/src/threadsafe.h index b7954fdcd..5905a5517 100644 --- a/modules/ocl/src/threadsafe.h +++ b/modules/ocl/src/threadsafe.h @@ -65,15 +65,15 @@ protected: #endif }; -class AutoLock +class myAutoLock { public: - explicit AutoLock(CriticalSection *lock) + explicit myAutoLock(CriticalSection *lock) { m_lock = lock; m_lock->Lock(); }; - ~AutoLock() + ~myAutoLock() { m_lock->Unlock(); }; From a0aef244d675afc515397e2df3bd7a5d04312b78 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 20 Aug 2012 09:58:37 +0400 Subject: [PATCH 16/40] removed perf_gpu_cpu from CMake scripts --- cmake/OpenCVModule.cmake | 2 - modules/gpu/CMakeLists.txt | 40 ------------------- modules/gpu/perf/perf_precomp.hpp | 2 +- .../perf/{perf_utility.cpp => utility.cpp} | 0 .../perf/{perf_utility.hpp => utility.hpp} | 0 .../test/{precomp.cpp => test_precomp.cpp} | 0 .../test/{precomp.hpp => test_precomp.hpp} | 0 7 files changed, 1 insertion(+), 43 deletions(-) rename modules/gpu/perf/{perf_utility.cpp => utility.cpp} (100%) rename modules/gpu/perf/{perf_utility.hpp => utility.hpp} (100%) rename modules/gpu/test/{precomp.cpp => test_precomp.cpp} (100%) rename modules/gpu/test/{precomp.hpp => test_precomp.hpp} (100%) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 543f9970b..018a46730 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -509,8 +509,6 @@ endmacro() macro(ocv_add_precompiled_headers the_target) if("${the_target}" MATCHES "^opencv_test_.*$") SET(pch_path "test/test_") - elseif("${the_target}" MATCHES "opencv_perf_gpu_cpu") - SET(pch_path "perf_cpu/perf_cpu_") elseif("${the_target}" MATCHES "^opencv_perf_.*$") SET(pch_path "perf/perf_") else() diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index e24b73a77..5d2c440fe 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -111,43 +111,3 @@ ocv_add_accuracy_tests(FILES "Include" ${test_hdrs} FILES "Src" ${test_srcs} ${nvidia}) ocv_add_perf_tests() - - - -set(perf_cpu_path "${CMAKE_CURRENT_SOURCE_DIR}/perf_cpu") -if(BUILD_PERF_TESTS AND EXISTS "${perf_cpu_path}") - # opencv_highgui is required for imread/imwrite - set(perf_deps ${the_module} opencv_ts opencv_highgui opencv_imgproc opencv_calib3d opencv_objdetect opencv_video opencv_nonfree) - ocv_check_dependencies(${perf_deps}) - - if(OCV_DEPENDENCIES_FOUND) - set(the_target "opencv_perf_gpu_cpu") - - ocv_module_include_directories(${perf_deps} "${perf_cpu_path}") - - if(NOT OPENCV_PERF_${the_module}_CPU_SOURCES) - file(GLOB perf_srcs "${perf_cpu_path}/*.cpp") - file(GLOB perf_hdrs "${perf_cpu_path}/*.hpp" "${perf_cpu_path}/*.h") - source_group("Src" FILES ${perf_srcs}) - source_group("Include" FILES ${perf_hdrs}) - set(OPENCV_PERF_${the_module}_CPU_SOURCES ${perf_srcs} ${perf_hdrs}) - endif() - - add_executable(${the_target} ${OPENCV_PERF_${the_module}_CPU_SOURCES}) - target_link_libraries(${the_target} ${OPENCV_MODULE_${the_module}_DEPS} ${perf_deps} ${OPENCV_LINKER_LIBS}) - - # Additional target properties - set_target_properties(${the_target} PROPERTIES - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" - RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" - ) - - if(ENABLE_SOLUTION_FOLDERS) - set_target_properties(${the_target} PROPERTIES FOLDER "tests performance") - endif() - - ocv_add_precompiled_headers(${the_target}) - else(OCV_DEPENDENCIES_FOUND) - #TODO: warn about unsatisfied dependencies - endif(OCV_DEPENDENCIES_FOUND) - endif() diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp index be3f234a3..837859947 100644 --- a/modules/gpu/perf/perf_precomp.hpp +++ b/modules/gpu/perf/perf_precomp.hpp @@ -27,7 +27,7 @@ #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/legacy/legacy.hpp" -#include "perf_utility.hpp" +#include "utility.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_utility.cpp b/modules/gpu/perf/utility.cpp similarity index 100% rename from modules/gpu/perf/perf_utility.cpp rename to modules/gpu/perf/utility.cpp diff --git a/modules/gpu/perf/perf_utility.hpp b/modules/gpu/perf/utility.hpp similarity index 100% rename from modules/gpu/perf/perf_utility.hpp rename to modules/gpu/perf/utility.hpp diff --git a/modules/gpu/test/precomp.cpp b/modules/gpu/test/test_precomp.cpp similarity index 100% rename from modules/gpu/test/precomp.cpp rename to modules/gpu/test/test_precomp.cpp diff --git a/modules/gpu/test/precomp.hpp b/modules/gpu/test/test_precomp.hpp similarity index 100% rename from modules/gpu/test/precomp.hpp rename to modules/gpu/test/test_precomp.hpp From ec7f9566e0df2d535d7ac5123026720cb7e80d2d Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 20 Aug 2012 10:15:36 +0400 Subject: [PATCH 17/40] minor gpu tests fix --- modules/gpu/perf/main.cpp | 6 +- modules/gpu/test/main.cpp | 92 ++++++++++--------- modules/gpu/test/main_test_nvidia.h | 4 +- modules/gpu/test/test_calib3d.cpp | 8 +- modules/gpu/test/test_color.cpp | 2 +- modules/gpu/test/test_copy_make_border.cpp | 6 +- modules/gpu/test/test_core.cpp | 6 +- modules/gpu/test/test_features2d.cpp | 6 +- modules/gpu/test/test_filters.cpp | 6 +- modules/gpu/test/test_global_motion.cpp | 8 +- modules/gpu/test/test_gpumat.cpp | 6 +- modules/gpu/test/test_imgproc.cpp | 6 +- modules/gpu/test/test_labeling.cpp | 6 +- modules/gpu/test/test_nvidia.cpp | 14 +-- modules/gpu/test/test_objdetect.cpp | 25 ++--- modules/gpu/test/test_precomp.cpp | 2 +- modules/gpu/test/test_precomp.hpp | 2 + modules/gpu/test/test_pyramids.cpp | 2 +- modules/gpu/test/test_remap.cpp | 2 +- modules/gpu/test/test_resize.cpp | 3 +- modules/gpu/test/test_threshold.cpp | 2 +- modules/gpu/test/test_video.cpp | 6 +- modules/gpu/test/test_warp_affine.cpp | 2 +- modules/gpu/test/test_warp_perspective.cpp | 2 +- modules/gpu/test/utility.cpp | 101 +-------------------- modules/gpu/test/utility.hpp | 4 +- 26 files changed, 134 insertions(+), 195 deletions(-) diff --git a/modules/gpu/perf/main.cpp b/modules/gpu/perf/main.cpp index 865362f88..aadeee955 100644 --- a/modules/gpu/perf/main.cpp +++ b/modules/gpu/perf/main.cpp @@ -71,9 +71,9 @@ void printCudaInfo() #endif } -int main(int argc, char **argv) +int main(int argc, char** argv) { - CommandLineParser cmd(argc, argv, + CommandLineParser cmd(argc, (const char**) argv, "{ print_info_only | print_info_only | false | Print information about system and exit }" "{ device | device | 0 | Device on which tests will be executed }" "{ cpu | cpu | false | Run tests on cpu }" @@ -119,7 +119,7 @@ int main(int argc, char **argv) cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl; } - testing::InitGoogleTest(&argc, argv); + InitGoogleTest(&argc, argv); perf::TestBase::Init(argc, argv); return RUN_ALL_TESTS(); } diff --git a/modules/gpu/test/main.cpp b/modules/gpu/test/main.cpp index 6df7db0a1..8f216c9fe 100644 --- a/modules/gpu/test/main.cpp +++ b/modules/gpu/test/main.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA @@ -49,93 +49,103 @@ using namespace cv::gpu; using namespace cvtest; using namespace testing; -void printInfo() +void printOsInfo() { #if defined _WIN32 # if defined _WIN64 - puts("OS: Windows x64"); + cout << "OS: Windows x64 \n" << endl; # else - puts("OS: Windows x32"); + cout << "OS: Windows x32 \n" << endl; # endif #elif defined linux # if defined _LP64 - puts("OS: Linux x64"); + cout << "OS: Linux x64 \n" << endl; # else - puts("OS: Linux x32"); + cout << "OS: Linux x32 \n" << endl; # endif #elif defined __APPLE__ # if defined _LP64 - puts("OS: Apple x64"); + cout << "OS: Apple x64 \n" << endl; # else - puts("OS: Apple x32"); + cout << "OS: Apple x32 \n" << endl; # endif #endif +} +void printCudaInfo() +{ +#ifndef HAVE_CUDA + cout << "OpenCV was built without CUDA support \n" << endl; +#else int driver; cudaDriverGetVersion(&driver); - printf("CUDA Driver version: %d\n", driver); - printf("CUDA Runtime version: %d\n", CUDART_VERSION); + cout << "CUDA Driver version: " << driver << '\n'; + cout << "CUDA Runtime version: " << CUDART_VERSION << '\n'; - puts("GPU module was compiled for the following GPU archs:"); - printf(" BIN: %s\n", CUDA_ARCH_BIN); - printf(" PTX: %s\n\n", CUDA_ARCH_PTX); + cout << endl; + + cout << "GPU module was compiled for the following GPU archs:" << endl; + cout << " BIN: " << CUDA_ARCH_BIN << '\n'; + cout << " PTX: " << CUDA_ARCH_PTX << '\n'; + + cout << endl; int deviceCount = getCudaEnabledDeviceCount(); - printf("CUDA device count: %d\n\n", deviceCount); + cout << "CUDA device count: " << deviceCount << '\n'; + + cout << endl; for (int i = 0; i < deviceCount; ++i) { DeviceInfo info(i); - printf("Device %d:\n", i); - printf(" Name: %s\n", info.name().c_str()); - printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion()); - printf(" Multi Processor Count: %d\n", info.multiProcessorCount()); - printf(" Total memory: %d Mb\n", static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0)); - printf(" Free memory: %d Mb\n", static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0)); + cout << "Device [" << i << "] \n"; + cout << "\t Name: " << info.name() << '\n'; + cout << "\t Compute capability: " << info.majorVersion() << '.' << info.minorVersion()<< '\n'; + cout << "\t Multi Processor Count: " << info.multiProcessorCount() << '\n'; + cout << "\t Total memory: " << static_cast(static_cast(info.totalMemory() / 1024.0) / 1024.0) << " Mb \n"; + cout << "\t Free memory: " << static_cast(static_cast(info.freeMemory() / 1024.0) / 1024.0) << " Mb \n"; if (!info.isCompatible()) - puts(" !!! This device is NOT compatible with current GPU module build\n"); - printf("\n"); + cout << "\t !!! This device is NOT compatible with current GPU module build \n"; + + cout << endl; } +#endif } -enum OutputLevel -{ - OutputLevelNone, - OutputLevelCompact, - OutputLevelFull -}; - -extern OutputLevel nvidiaTestOutputLevel; - int main(int argc, char** argv) { try { - CommandLineParser parser(argc, (const char**)argv, - "{ print_info_only | print_info_only | false | Print information about system and exit }" - "{ device | device | -1 | Device on which tests will be executed (-1 means all devices) }" - "{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }"); + CommandLineParser cmd(argc, (const char**)argv, + "{ print_info_only | print_info_only | false | Print information about system and exit }" + "{ device | device | -1 | Device on which tests will be executed (-1 means all devices) }" + "{ nvtest_output_level | nvtest_output_level | compact | NVidia test verbosity level }" + ); - printInfo(); + printOsInfo(); + printCudaInfo(); - if (parser.get("print_info_only")) + if (cmd.get("print_info_only")) return 0; - int device = parser.get("device"); + int device = cmd.get("device"); if (device < 0) { DeviceManager::instance().loadAll(); - std::cout << "Run tests on all supported devices\n" << std::endl; + + cout << "Run tests on all supported devices \n" << endl; } else { DeviceManager::instance().load(device); - std::cout << "Run tests on device " << device << '\n' << std::endl; + + DeviceInfo info(device); + cout << "Run tests on device " << device << " [" << info.name() << "] \n" << endl; } - string outputLevel = parser.get("nvtest_output_level"); + string outputLevel = cmd.get("nvtest_output_level"); if (outputLevel == "none") nvidiaTestOutputLevel = OutputLevelNone; diff --git a/modules/gpu/test/main_test_nvidia.h b/modules/gpu/test/main_test_nvidia.h index d1c362012..15016ca64 100644 --- a/modules/gpu/test/main_test_nvidia.h +++ b/modules/gpu/test/main_test_nvidia.h @@ -1,7 +1,7 @@ #ifndef __main_test_nvidia_h__ #define __main_test_nvidia_h__ -#include +#include enum OutputLevel { @@ -10,6 +10,8 @@ enum OutputLevel OutputLevelFull }; +extern OutputLevel nvidiaTestOutputLevel; + bool nvidia_NPPST_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel); bool nvidia_NPPST_Squared_Integral_Image(const std::string& test_data_path, OutputLevel outputLevel); bool nvidia_NPPST_RectStdDev(const std::string& test_data_path, OutputLevel outputLevel); diff --git a/modules/gpu/test/test_calib3d.cpp b/modules/gpu/test/test_calib3d.cpp index bdc043fc5..5fa1ebb41 100644 --- a/modules/gpu/test/test_calib3d.cpp +++ b/modules/gpu/test/test_calib3d.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -329,7 +331,7 @@ TEST_P(ReprojectImageTo3D, Accuracy) cv::gpu::GpuMat dst; cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3); - + cv::Mat dst_gold; cv::reprojectImageTo3D(disp, dst_gold, Q, false); @@ -343,3 +345,5 @@ INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine( WHOLE_SUBMAT)); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_color.cpp b/modules/gpu/test/test_color.cpp index 645967ef2..c2929fbe7 100644 --- a/modules/gpu/test/test_color.cpp +++ b/modules/gpu/test/test_color.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_copy_make_border.cpp b/modules/gpu/test/test_copy_make_border.cpp index 45b73d302..8bd5a66f9 100644 --- a/modules/gpu/test/test_copy_make_border.cpp +++ b/modules/gpu/test/test_copy_make_border.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -98,3 +100,5 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CopyMakeBorder, testing::Combine( WHOLE_SUBMAT)); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_core.cpp b/modules/gpu/test/test_core.cpp index 6502c4a05..09c6be1ac 100644 --- a/modules/gpu/test/test_core.cpp +++ b/modules/gpu/test/test_core.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -3396,3 +3398,5 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, Reduce, testing::Combine( WHOLE_SUBMAT)); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_features2d.cpp b/modules/gpu/test/test_features2d.cpp index d8ed864eb..b461d4b44 100644 --- a/modules/gpu/test/test_features2d.cpp +++ b/modules/gpu/test/test_features2d.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -984,3 +986,5 @@ INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine( testing::Values(UseMask(false), UseMask(true)))); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_filters.cpp b/modules/gpu/test/test_filters.cpp index 9df6ee27c..0781970e4 100644 --- a/modules/gpu/test/test_filters.cpp +++ b/modules/gpu/test/test_filters.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -552,3 +554,5 @@ INSTANTIATE_TEST_CASE_P(GPU_Filter, Filter2D, testing::Combine( WHOLE_SUBMAT)); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_global_motion.cpp b/modules/gpu/test/test_global_motion.cpp index eb8b2f7c1..b37d08068 100644 --- a/modules/gpu/test/test_global_motion.cpp +++ b/modules/gpu/test/test_global_motion.cpp @@ -39,11 +39,11 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA -#include using namespace std; - using namespace cv; struct CompactPoints : testing::TestWithParam @@ -85,3 +85,5 @@ TEST_P(CompactPoints, CanCompactizeSmallInput) } INSTANTIATE_TEST_CASE_P(GPU_GlobalMotion, CompactPoints, ALL_DEVICES); + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_gpumat.cpp b/modules/gpu/test/test_gpumat.cpp index 4dd419a18..862795759 100644 --- a/modules/gpu/test/test_gpumat.cpp +++ b/modules/gpu/test/test_gpumat.cpp @@ -40,7 +40,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -323,3 +325,5 @@ INSTANTIATE_TEST_CASE_P(GPU_GpuMat, ConvertTo, testing::Combine( WHOLE_SUBMAT)); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_imgproc.cpp b/modules/gpu/test/test_imgproc.cpp index 4d67de59d..7a616a2e4 100644 --- a/modules/gpu/test/test_imgproc.cpp +++ b/modules/gpu/test/test_imgproc.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -1186,3 +1188,5 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughLines, testing::Combine( std::string("../cv/shared/pic6.png")))); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_labeling.cpp b/modules/gpu/test/test_labeling.cpp index c88109af1..46f6f4eeb 100644 --- a/modules/gpu/test/test_labeling.cpp +++ b/modules/gpu/test/test_labeling.cpp @@ -39,9 +39,7 @@ // the use of this software, even if advised of the possibility of such damage. //M*/ -#include "precomp.hpp" -#include -#include +#include "test_precomp.hpp" #ifdef HAVE_CUDA @@ -199,4 +197,4 @@ TEST_P(Labeling, ConnectedComponents) INSTANTIATE_TEST_CASE_P(ConnectedComponents, Labeling, ALL_DEVICES); -#endif \ No newline at end of file +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_nvidia.cpp b/modules/gpu/test/test_nvidia.cpp index 386a66cfd..3de355744 100644 --- a/modules/gpu/test/test_nvidia.cpp +++ b/modules/gpu/test/test_nvidia.cpp @@ -39,21 +39,15 @@ // //M*/ -#include -#include "precomp.hpp" +#include "test_precomp.hpp" + +OutputLevel nvidiaTestOutputLevel = OutputLevelCompact; #ifdef HAVE_CUDA using namespace cvtest; using namespace testing; -//enum OutputLevel -//{ -// OutputLevelNone, -// OutputLevelCompact, -// OutputLevelFull -//}; - struct NVidiaTest : TestWithParam { cv::gpu::DeviceInfo devInfo; @@ -73,8 +67,6 @@ struct NVidiaTest : TestWithParam struct NPPST : NVidiaTest {}; struct NCV : NVidiaTest {}; -OutputLevel nvidiaTestOutputLevel = OutputLevelCompact; - //TEST_P(NPPST, Integral) //{ // bool res = nvidia_NPPST_Integral_Image(path, nvidiaTestOutputLevel); diff --git a/modules/gpu/test/test_objdetect.cpp b/modules/gpu/test/test_objdetect.cpp index 927762b2b..957ee1165 100644 --- a/modules/gpu/test/test_objdetect.cpp +++ b/modules/gpu/test/test_objdetect.cpp @@ -39,8 +39,9 @@ // //M*/ -#include "precomp.hpp" -#include +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA namespace { @@ -302,13 +303,13 @@ PARAM_TEST_CASE(LBP_Read_classifier, cv::gpu::DeviceInfo, int) TEST_P(LBP_Read_classifier, Accuracy) { - cv::gpu::CascadeClassifier_GPU classifier; + cv::gpu::CascadeClassifier_GPU classifier; std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml"; ASSERT_TRUE(classifier.load(classifierXmlPath)); } -INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier, - testing::Combine(ALL_DEVICES, testing::Values(0))); +INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_Read_classifier, + testing::Combine(ALL_DEVICES, testing::Values(0))); PARAM_TEST_CASE(LBP_classify, cv::gpu::DeviceInfo, int) @@ -344,7 +345,7 @@ TEST_P(LBP_classify, Accuracy) for (; it != rects.end(); ++it) cv::rectangle(markedImage, *it, CV_RGB(0, 0, 255)); - cv::gpu::CascadeClassifier_GPU gpuClassifier; + cv::gpu::CascadeClassifier_GPU gpuClassifier; ASSERT_TRUE(gpuClassifier.load(classifierXmlPath)); cv::gpu::GpuMat gpu_rects; @@ -352,23 +353,25 @@ TEST_P(LBP_classify, Accuracy) int count = gpuClassifier.detectMultiScale(tested, gpu_rects); cv::Mat downloaded(gpu_rects); - const cv::Rect* faces = downloaded.ptr(); + const cv::Rect* faces = downloaded.ptr(); for (int i = 0; i < count; i++) { cv::Rect r = faces[i]; #if defined (LOG_CASCADE_STATISTIC) - std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; + std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; cv::rectangle(markedImage, r , CV_RGB(255, 0, 0)); -#endif +#endif } #if defined (LOG_CASCADE_STATISTIC) - cv::imshow("Res", markedImage); cv::waitKey(); + cv::imshow("Res", markedImage); cv::waitKey(); #endif } INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, LBP_classify, - testing::Combine(ALL_DEVICES, testing::Values(0))); + testing::Combine(ALL_DEVICES, testing::Values(0))); } // namespace + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_precomp.cpp b/modules/gpu/test/test_precomp.cpp index dfa724612..34acf2ae9 100644 --- a/modules/gpu/test/test_precomp.cpp +++ b/modules/gpu/test/test_precomp.cpp @@ -39,4 +39,4 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" diff --git a/modules/gpu/test/test_precomp.hpp b/modules/gpu/test/test_precomp.hpp index 753367cce..f6933d51c 100644 --- a/modules/gpu/test/test_precomp.hpp +++ b/modules/gpu/test/test_precomp.hpp @@ -59,6 +59,7 @@ #include #include "cvconfig.h" + #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/calib3d/calib3d.hpp" @@ -72,6 +73,7 @@ #include "utility.hpp" #include "interpolation.hpp" +#include "main_test_nvidia.h" #ifdef HAVE_CUDA #include diff --git a/modules/gpu/test/test_pyramids.cpp b/modules/gpu/test/test_pyramids.cpp index d0bf37b37..1abd7841e 100644 --- a/modules/gpu/test/test_pyramids.cpp +++ b/modules/gpu/test/test_pyramids.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_remap.cpp b/modules/gpu/test/test_remap.cpp index c61a89914..b83e5db07 100644 --- a/modules/gpu/test/test_remap.cpp +++ b/modules/gpu/test/test_remap.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_resize.cpp b/modules/gpu/test/test_resize.cpp index 7a7aacab1..73b8d9fab 100644 --- a/modules/gpu/test/test_resize.cpp +++ b/modules/gpu/test/test_resize.cpp @@ -39,8 +39,7 @@ // //M*/ -#include "precomp.hpp" -#include +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_threshold.cpp b/modules/gpu/test/test_threshold.cpp index cb31c643b..e878e6dfa 100644 --- a/modules/gpu/test/test_threshold.cpp +++ b/modules/gpu/test/test_threshold.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_video.cpp b/modules/gpu/test/test_video.cpp index 0ee66ba52..ca9442d69 100644 --- a/modules/gpu/test/test_video.cpp +++ b/modules/gpu/test/test_video.cpp @@ -39,7 +39,9 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" + +#ifdef HAVE_CUDA //#define DUMP @@ -865,3 +867,5 @@ TEST_P(VideoReader, Regression) INSTANTIATE_TEST_CASE_P(GPU_Video, VideoReader, testing::Combine( ALL_DEVICES, testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")))); + +#endif // HAVE_CUDA diff --git a/modules/gpu/test/test_warp_affine.cpp b/modules/gpu/test/test_warp_affine.cpp index 262937fbe..c81fef354 100644 --- a/modules/gpu/test/test_warp_affine.cpp +++ b/modules/gpu/test/test_warp_affine.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/test_warp_perspective.cpp b/modules/gpu/test/test_warp_perspective.cpp index f14317015..83c170f2e 100644 --- a/modules/gpu/test/test_warp_perspective.cpp +++ b/modules/gpu/test/test_warp_perspective.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" #ifdef HAVE_CUDA diff --git a/modules/gpu/test/utility.cpp b/modules/gpu/test/utility.cpp index 148c9d202..cf3b0fc8c 100644 --- a/modules/gpu/test/utility.cpp +++ b/modules/gpu/test/utility.cpp @@ -39,7 +39,7 @@ // //M*/ -#include "precomp.hpp" +#include "test_precomp.hpp" using namespace std; using namespace cv; @@ -182,105 +182,6 @@ void DeviceManager::loadAll() } } -class DevicesGenerator : public ParamGeneratorInterface -{ -public: - ~DevicesGenerator(); - - ParamIteratorInterface* Begin() const; - ParamIteratorInterface* End() const; - -private: - class Iterator : public ParamIteratorInterface - { - public: - Iterator(const ParamGeneratorInterface* base, vector::const_iterator iterator); - - virtual ~Iterator(); - - virtual const ParamGeneratorInterface* BaseGenerator() const; - - virtual void Advance(); - - virtual ParamIteratorInterface* Clone() const; - - virtual const DeviceInfo* Current() const; - - virtual bool Equals(const ParamIteratorInterface& other) const; - - private: - Iterator(const Iterator& other); - - const ParamGeneratorInterface* const base_; - vector::const_iterator iterator_; - - mutable DeviceInfo value_; - }; -}; - -DevicesGenerator::~DevicesGenerator() -{ -} - -ParamIteratorInterface* DevicesGenerator::Begin() const -{ - return new Iterator(this, DeviceManager::instance().values().begin()); -} - -ParamIteratorInterface* DevicesGenerator::End() const -{ - return new Iterator(this, DeviceManager::instance().values().end()); -} - -DevicesGenerator::Iterator::Iterator(const ParamGeneratorInterface* base, vector::const_iterator iterator) - : base_(base), iterator_(iterator) -{ -} - -DevicesGenerator::Iterator::~Iterator() -{ -} - -const ParamGeneratorInterface* DevicesGenerator::Iterator::BaseGenerator() const -{ - return base_; -} - -void DevicesGenerator::Iterator::Advance() -{ - ++iterator_; -} - -ParamIteratorInterface* DevicesGenerator::Iterator::Clone() const -{ - return new Iterator(*this); -} - -const DeviceInfo* DevicesGenerator::Iterator::Current() const -{ - value_ = *iterator_; - return &value_; -} - -bool DevicesGenerator::Iterator::Equals(const ParamIteratorInterface& other) const -{ - GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) - << "The program attempted to compare iterators " - << "from different generators." << endl; - - return iterator_ == CheckedDowncastToActualType(&other)->iterator_; -} - -DevicesGenerator::Iterator::Iterator(const Iterator& other) : - ParamIteratorInterface(), base_(other.base_), iterator_(other.iterator_) -{ -} - -ParamGenerator DevicesGenerator_() -{ - return ParamGenerator(new DevicesGenerator); -} - ////////////////////////////////////////////////////////////////////// // Additional assertion diff --git a/modules/gpu/test/utility.hpp b/modules/gpu/test/utility.hpp index b36f177f6..f509b786a 100644 --- a/modules/gpu/test/utility.hpp +++ b/modules/gpu/test/utility.hpp @@ -94,9 +94,7 @@ private: std::vector devices_; }; -testing::internal::ParamGenerator DevicesGenerator_(); - -#define ALL_DEVICES DevicesGenerator_() +#define ALL_DEVICES testing::ValuesIn(DeviceManager::instance().values()) ////////////////////////////////////////////////////////////////////// // Additional assertion From 1e4012079d84b5f1742f539f2eae3a85254a1409 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 13:26:51 +0400 Subject: [PATCH 18/40] removed logging from test --- modules/gpu/test/test_labeling.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/gpu/test/test_labeling.cpp b/modules/gpu/test/test_labeling.cpp index 46f6f4eeb..d32dbc1a2 100644 --- a/modules/gpu/test/test_labeling.cpp +++ b/modules/gpu/test/test_labeling.cpp @@ -139,10 +139,9 @@ namespace { if ( (_labels.at(j,i) == gpu.at(j,i + 1)) && (diff.at(j, i) != diff.at(j,i + 1))) { outliers++; - // std::cout << j << " " << i << " " << _labels.at(j,i) << " " << gpu.at(j,i + 1) << " " << diff.at(j, i) << " " << diff.at(j,i + 1) << std::endl; } } - ASSERT_FALSE(outliers); + ASSERT_TRUE(outliers < gpu.cols + gpu.rows); } cv::Mat image; @@ -162,7 +161,7 @@ struct Labeling : testing::TestWithParam cv::Mat loat_image() { - return cv::imread(std::string( cvtest::TS::ptr()->get_data_path() ) + "labeling/IMG_0727.JPG"); + return cv::imread(std::string( cvtest::TS::ptr()->get_data_path() ) + "labeling/label.png"); } }; @@ -189,10 +188,6 @@ TEST_P(Labeling, ConnectedComponents) ASSERT_NO_THROW(cv::gpu::labelComponents(mask, components)); host.checkCorrectness(cv::Mat(components)); - cv::imshow("test", image); - cv::waitKey(0); - cv::imshow("test", host._labels); - cv::waitKey(0); } INSTANTIATE_TEST_CASE_P(ConnectedComponents, Labeling, ALL_DEVICES); From c26d543e1e5007e5566f9fd8d4d3a121c97005d3 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 20 Aug 2012 16:03:01 +0400 Subject: [PATCH 19/40] gpu::HoughLines : minor code improvements --- modules/gpu/include/opencv2/gpu/gpu.hpp | 1 + modules/gpu/perf/perf_imgproc.cpp | 2 +- modules/gpu/src/cuda/hough.cu | 123 ++++++++++++------------ modules/gpu/src/hough.cpp | 44 +++++---- modules/gpu/test/test_imgproc.cpp | 76 ++++++++------- 5 files changed, 129 insertions(+), 117 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index a7f0ab32d..c6f2e1141 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -820,6 +820,7 @@ private: int nLayers_; }; +//! HoughLines 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, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096); CV_EXPORTS void HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta); diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 9104892db..979aaa372 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -1626,7 +1626,7 @@ PERF_TEST_P(Sz_DoSort, ImgProc_HoughLines, Combine(GPU_TYPICAL_MAT_SIZES, Bool() cv::Mat src(size, CV_8UC1, cv::Scalar::all(0)); - const int numLines = rng.uniform(500, 2000); + const int numLines = rng.uniform(100, 300); for (int i = 0; i < numLines; ++i) { cv::Point p1(rng.uniform(0, src.cols), rng.uniform(0, src.rows)); diff --git a/modules/gpu/src/cuda/hough.cu b/modules/gpu/src/cuda/hough.cu index 82bd04caa..66433aba7 100644 --- a/modules/gpu/src/cuda/hough.cu +++ b/modules/gpu/src/cuda/hough.cu @@ -59,7 +59,7 @@ namespace cv { namespace gpu { namespace device { __shared__ int s_queues[4][32 * PIXELS_PER_THREAD]; __shared__ int s_qsize[4]; - __shared__ int s_start[4]; + __shared__ int s_globStart[4]; const int x = blockIdx.x * blockDim.x * PIXELS_PER_THREAD + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -73,9 +73,10 @@ namespace cv { namespace gpu { namespace device __syncthreads(); // fill the queue + const uchar* srcRow = src.ptr(y); for (int i = 0, xx = x; i < PIXELS_PER_THREAD && xx < src.cols; ++i, xx += blockDim.x) { - if (src(y, xx)) + if (srcRow[xx]) { const unsigned int val = (y << 16) | xx; const int qidx = Emulation::smem::atomicAdd(&s_qsize[threadIdx.y], 1); @@ -89,36 +90,34 @@ namespace cv { namespace gpu { namespace device if (threadIdx.x == 0 && threadIdx.y == 0) { // find how many items are stored in each list - int total_size = 0; + int totalSize = 0; for (int i = 0; i < blockDim.y; ++i) { - s_start[i] = total_size; - total_size += s_qsize[i]; + s_globStart[i] = totalSize; + totalSize += s_qsize[i]; } // calculate the offset in the global list - const int global_offset = atomicAdd(&g_counter, total_size); + const int globalOffset = atomicAdd(&g_counter, totalSize); for (int i = 0; i < blockDim.y; ++i) - s_start[i] += global_offset; + s_globStart[i] += globalOffset; } __syncthreads(); // copy local queues to global queue const int qsize = s_qsize[threadIdx.y]; - for(int i = threadIdx.x; i < qsize; i += blockDim.x) - { - const unsigned int val = s_queues[threadIdx.y][i]; - list[s_start[threadIdx.y] + i] = val; - } + int gidx = s_globStart[threadIdx.y] + threadIdx.x; + for(int i = threadIdx.x; i < qsize; i += blockDim.x, gidx += blockDim.x) + list[gidx] = s_queues[threadIdx.y][i]; } int buildPointList_gpu(DevMem2Db src, unsigned int* list) { - void* counter_ptr; - cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, g_counter) ); + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - cudaSafeCall( cudaMemset(counter_ptr, 0, sizeof(int)) ); + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); const dim3 block(32, 4); const dim3 grid(divUp(src.cols, block.x * PIXELS_PER_THREAD), divUp(src.rows, block.y)); @@ -130,10 +129,10 @@ namespace cv { namespace gpu { namespace device cudaSafeCall( cudaDeviceSynchronize() ); - int total_count; - cudaSafeCall( cudaMemcpy(&total_count, counter_ptr, sizeof(int), cudaMemcpyDeviceToHost) ); + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - return total_count; + return totalCount; } //////////////////////////////////////////////////////////////////////// @@ -144,24 +143,26 @@ namespace cv { namespace gpu { namespace device const int n = blockIdx.x; const float ang = n * theta; - float sin_ang; - float cos_ang; - sincosf(ang, &sin_ang, &cos_ang); + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; - const float tabSin = sin_ang * irho; - const float tabCos = cos_ang * irho; + const int shift = (numrho - 1) / 2; + int* accumRow = accum.ptr(n + 1); for (int i = threadIdx.x; i < count; i += blockDim.x) { - const unsigned int qvalue = list[i]; + const unsigned int val = list[i]; - const int x = (qvalue & 0x0000FFFF); - const int y = (qvalue >> 16) & 0x0000FFFF; + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; - int r = __float2int_rn(x * tabCos + y * tabSin); - r += (numrho - 1) / 2; + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; - ::atomicAdd(accum.ptr(n + 1) + r + 1, 1); + ::atomicAdd(accumRow + r + 1, 1); } } @@ -177,30 +178,32 @@ namespace cv { namespace gpu { namespace device const int n = blockIdx.x; const float ang = n * theta; - float sin_ang; - float cos_ang; - sincosf(ang, &sin_ang, &cos_ang); + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; - const float tabSin = sin_ang * irho; - const float tabCos = cos_ang * irho; + const int shift = (numrho - 1) / 2; for (int i = threadIdx.x; i < count; i += blockDim.x) { - const unsigned int qvalue = list[i]; + const unsigned int val = list[i]; - const int x = (qvalue & 0x0000FFFF); - const int y = (qvalue >> 16) & 0x0000FFFF; + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; - int r = __float2int_rn(x * tabCos + y * tabSin); - r += (numrho - 1) / 2; + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; Emulation::smem::atomicAdd(&smem[r + 1], 1); } __syncthreads(); - for (int i = threadIdx.x; i < numrho; i += blockDim.x) - accum(n + 1, i) = smem[i]; + int* accumRow = accum.ptr(n + 1); + for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) + accumRow[i] = smem[i]; } void linesAccum_gpu(const unsigned int* list, int count, DevMem2Di accum, float rho, float theta, size_t sharedMemPerBlock, bool has20) @@ -225,21 +228,21 @@ namespace cv { namespace gpu { namespace device //////////////////////////////////////////////////////////////////////// // linesGetResult - __global__ void linesGetResult(const DevMem2Di accum, float2* out, int* votes, const int maxSize, const float threshold, const float theta, const float rho, const int numrho) + __global__ void linesGetResult(const DevMem2Di accum, float2* out, int* votes, const int maxSize, const float rho, const float theta, const float threshold, const int numrho) { __shared__ int smem[8][32]; - int r = blockIdx.x * (blockDim.x - 2) + threadIdx.x; - int n = blockIdx.y * (blockDim.y - 2) + threadIdx.y; + const int x = blockIdx.x * (blockDim.x - 2) + threadIdx.x; + const int y = blockIdx.y * (blockDim.y - 2) + threadIdx.y; - if (r >= accum.cols || n >= accum.rows) + if (x >= accum.cols || y >= accum.rows) return; - smem[threadIdx.y][threadIdx.x] = accum(n, r); + smem[threadIdx.y][threadIdx.x] = accum(y, x); __syncthreads(); - r -= 1; - n -= 1; + const int r = x - 1; + const int n = y - 1; if (threadIdx.x == 0 || threadIdx.x == blockDim.x - 1 || threadIdx.y == 0 || threadIdx.y == blockDim.y - 1 || r >= accum.cols - 2 || n >= accum.rows - 2) return; @@ -264,32 +267,32 @@ namespace cv { namespace gpu { namespace device int linesGetResult_gpu(DevMem2Di accum, float2* out, int* votes, int maxSize, float rho, float theta, float threshold, bool doSort) { - void* counter_ptr; - cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, g_counter) ); + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - cudaSafeCall( cudaMemset(counter_ptr, 0, sizeof(int)) ); + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); const dim3 block(32, 8); const dim3 grid(divUp(accum.cols, block.x - 2), divUp(accum.rows, block.y - 2)); - linesGetResult<<>>(accum, out, votes, maxSize, threshold, theta, rho, accum.cols - 2); + linesGetResult<<>>(accum, out, votes, maxSize, rho, theta, threshold, accum.cols - 2); cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaDeviceSynchronize() ); - int total_count; - cudaSafeCall( cudaMemcpy(&total_count, counter_ptr, sizeof(int), cudaMemcpyDeviceToHost) ); + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - total_count = ::min(total_count, maxSize); + totalCount = ::min(totalCount, maxSize); - if (doSort && total_count > 0) + if (doSort && totalCount > 0) { - thrust::device_ptr out_ptr(out); - thrust::device_ptr votes_ptr(votes); - thrust::sort_by_key(votes_ptr, votes_ptr + total_count, out_ptr, thrust::greater()); + thrust::device_ptr outPtr(out); + thrust::device_ptr votesPtr(votes); + thrust::sort_by_key(votesPtr, votesPtr + totalCount, outPtr, thrust::greater()); } - return total_count; + return totalCount; } } }}} diff --git a/modules/gpu/src/hough.cpp b/modules/gpu/src/hough.cpp index ba61ad78c..3b683ff40 100644 --- a/modules/gpu/src/hough.cpp +++ b/modules/gpu/src/hough.cpp @@ -57,11 +57,27 @@ namespace cv { namespace gpu { namespace device namespace hough { int buildPointList_gpu(DevMem2Db src, unsigned int* list); + void linesAccum_gpu(const unsigned int* list, int count, DevMem2Di accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); int linesGetResult_gpu(DevMem2Di accum, float2* out, int* votes, int maxSize, float rho, float theta, float threshold, bool doSort); } }}} +////////////////////////////////////////////////////////// +// HoughLines + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + GpuMat accum, buf; + HoughLines(src, lines, accum, buf, rho, theta, threshold, doSort, maxLines); +} + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + HoughLinesTransform(src, accum, buf, rho, theta); + HoughLinesGet(accum, lines, rho, theta, threshold, doSort, maxLines); +} + void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta) { using namespace cv::gpu::device::hough; @@ -80,23 +96,23 @@ void cv::gpu::HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, CV_Assert(numangle > 0 && numrho > 0); ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, accum); - accum.setTo(cv::Scalar::all(0)); + accum.setTo(Scalar::all(0)); - cv::gpu::DeviceInfo devInfo; + DeviceInfo devInfo; if (count > 0) - linesAccum_gpu(buf.ptr(), count, accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(cv::gpu::FEATURE_SET_COMPUTE_20)); + linesAccum_gpu(buf.ptr(), count, accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); } void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) { - using namespace cv::gpu::device; + using namespace cv::gpu::device::hough; CV_Assert(accum.type() == CV_32SC1); ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); - int count = hough::linesGetResult_gpu(accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); + int count = linesGetResult_gpu(accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); if (count > 0) lines.cols = count; @@ -104,18 +120,6 @@ void cv::gpu::HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float lines.release(); } -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - cv::gpu::GpuMat accum, buf; - HoughLines(src, lines, accum, buf, rho, theta, threshold, doSort, maxLines); -} - -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - HoughLinesTransform(src, accum, buf, rho, theta); - HoughLinesGet(accum, lines, rho, theta, threshold, doSort, maxLines); -} - void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_) { if (d_lines.empty()) @@ -129,14 +133,14 @@ void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, Ou CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); h_lines_.create(1, d_lines.cols, CV_32FC2); - cv::Mat h_lines = h_lines_.getMat(); + Mat h_lines = h_lines_.getMat(); d_lines.row(0).download(h_lines); if (h_votes_.needed()) { h_votes_.create(1, d_lines.cols, CV_32SC1); - cv::Mat h_votes = h_votes_.getMat(); - cv::gpu::GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); + Mat h_votes = h_votes_.getMat(); + GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); d_votes.download(h_votes); } } diff --git a/modules/gpu/test/test_imgproc.cpp b/modules/gpu/test/test_imgproc.cpp index 4f402da16..06662d8d2 100644 --- a/modules/gpu/test/test_imgproc.cpp +++ b/modules/gpu/test/test_imgproc.cpp @@ -1129,63 +1129,67 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerMinEigen, testing::Combine( /////////////////////////////////////////////////////////////////////////////////////////////////////// // HoughLines -PARAM_TEST_CASE(HoughLines, cv::gpu::DeviceInfo, std::string) +PARAM_TEST_CASE(HoughLines, cv::gpu::DeviceInfo, cv::Size, UseRoi) { -}; - -void drawLines(cv::Mat& dst, const std::vector& lines) -{ - for (size_t i = 0; i < lines.size(); ++i) + void generateLines(cv::Mat& img) { - float rho = lines[i][0], theta = lines[i][1]; - cv::Point pt1, pt2; - double a = std::cos(theta), b = std::sin(theta); - double x0 = a*rho, y0 = b*rho; - pt1.x = cvRound(x0 + 1000*(-b)); - pt1.y = cvRound(y0 + 1000*(a)); - pt2.x = cvRound(x0 - 1000*(-b)); - pt2.y = cvRound(y0 - 1000*(a)); - cv::line(dst, pt1, pt2, cv::Scalar::all(255)); + img.setTo(cv::Scalar::all(0)); + + cv::line(img, cv::Point(20, 0), cv::Point(20, img.rows), cv::Scalar::all(255)); + cv::line(img, cv::Point(0, 50), cv::Point(img.cols, 50), cv::Scalar::all(255)); + cv::line(img, cv::Point(0, 0), cv::Point(img.cols, img.rows), cv::Scalar::all(255)); + cv::line(img, cv::Point(img.cols, 0), cv::Point(0, img.rows), cv::Scalar::all(255)); } -} + + void drawLines(cv::Mat& dst, const std::vector& lines) + { + dst.setTo(cv::Scalar::all(0)); + + for (size_t i = 0; i < lines.size(); ++i) + { + float rho = lines[i][0], theta = lines[i][1]; + cv::Point pt1, pt2; + double a = std::cos(theta), b = std::sin(theta); + double x0 = a*rho, y0 = b*rho; + pt1.x = cvRound(x0 + 1000*(-b)); + pt1.y = cvRound(y0 + 1000*(a)); + pt2.x = cvRound(x0 - 1000*(-b)); + pt2.y = cvRound(y0 - 1000*(a)); + cv::line(dst, pt1, pt2, cv::Scalar::all(255)); + } + } +}; TEST_P(HoughLines, Accuracy) { const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::gpu::setDevice(devInfo.deviceID()); - const std::string fileName = GET_PARAM(1); + const cv::Size size = GET_PARAM(1); + const bool useRoi = GET_PARAM(2); const float rho = 1.0f; - const float theta = static_cast(CV_PI / 180); - const int threshold = 50; + const float theta = 1.5f * CV_PI / 180.0f; + const int threshold = 100; - cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE); - ASSERT_FALSE(img.empty()); - - cv::Mat edges; - cv::Canny(img, edges, 50, 200); + cv::Mat src(size, CV_8UC1); + generateLines(src); cv::gpu::GpuMat d_lines; - cv::gpu::HoughLines(loadMat(edges), d_lines, rho, theta, threshold); + cv::gpu::HoughLines(loadMat(src, useRoi), d_lines, rho, theta, threshold); + std::vector lines; cv::gpu::HoughLinesDownload(d_lines, lines); - cv::Mat dst(img.size(), CV_8UC1, cv::Scalar::all(0)); + + cv::Mat dst(size, CV_8UC1); drawLines(dst, lines); - std::vector lines_gold; - cv::HoughLines(edges, lines_gold, rho, theta, threshold); - cv::Mat dst_gold(img.size(), CV_8UC1, cv::Scalar::all(0)); - drawLines(dst_gold, lines_gold); - - ASSERT_MAT_NEAR(dst_gold, dst, 0.0); + ASSERT_MAT_NEAR(src, dst, 0.0); } INSTANTIATE_TEST_CASE_P(GPU_ImgProc, HoughLines, testing::Combine( ALL_DEVICES, - testing::Values(std::string("../cv/shared/pic1.png"), - std::string("../cv/shared/pic3.png"), - std::string("../cv/shared/pic5.png"), - std::string("../cv/shared/pic6.png")))); + DIFFERENT_SIZES, + WHOLE_SUBMAT)); } // namespace From 8efb84b5a4cc98c6e3b1266923e744e6032ed52f Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Mon, 20 Aug 2012 19:36:36 +0400 Subject: [PATCH 20/40] added ios camera support in highgui. turned on optimization in opencv2.framework (ticket #2232) --- ios/cmake/Modules/Platform/iOS.cmake | 2 + modules/core/include/opencv2/core/core.hpp | 2 +- modules/highgui/CMakeLists.txt | 6 + .../highgui/include/opencv2/highgui/cap_ios.h | 160 +++++ .../highgui/src/cap_ios_abstract_camera.mm | 408 +++++++++++ modules/highgui/src/cap_ios_photo_camera.mm | 165 +++++ modules/highgui/src/cap_ios_video_camera.mm | 656 ++++++++++++++++++ 7 files changed, 1398 insertions(+), 1 deletion(-) create mode 100644 modules/highgui/include/opencv2/highgui/cap_ios.h create mode 100644 modules/highgui/src/cap_ios_abstract_camera.mm create mode 100644 modules/highgui/src/cap_ios_photo_camera.mm create mode 100644 modules/highgui/src/cap_ios_video_camera.mm diff --git a/ios/cmake/Modules/Platform/iOS.cmake b/ios/cmake/Modules/Platform/iOS.cmake index c657b800f..e8389798b 100644 --- a/ios/cmake/Modules/Platform/iOS.cmake +++ b/ios/cmake/Modules/Platform/iOS.cmake @@ -42,6 +42,8 @@ set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") set (CMAKE_C_FLAGS "") set (CMAKE_CXX_FLAGS "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden") +set (CMAKE_CXX_FLAGS_RELEASE "-O3 -fomit-frame-pointer") + if (HAVE_FLAG_SEARCH_PATHS_FIRST) set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index fbaf13721..5fd927213 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -440,7 +440,7 @@ template class CV_EXPORTS Matx { public: typedef _Tp value_type; - typedef Matx<_Tp, MIN(m, n), 1> diag_type; + typedef Matx<_Tp, (m < n ? m : n), 1> diag_type; typedef Matx<_Tp, m, n> mat_type; enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols, type = CV_MAKETYPE(depth, channels) }; diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 6b9341b32..d53c17c40 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -193,6 +193,12 @@ elseif(APPLE) endif() endif() +if(IOS) + add_definitions(-DHAVE_IOS=1) + list(APPEND highgui_srcs src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm) + list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary") +endif() + if(WIN32) link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW diff --git a/modules/highgui/include/opencv2/highgui/cap_ios.h b/modules/highgui/include/opencv2/highgui/cap_ios.h new file mode 100644 index 000000000..cc6668ace --- /dev/null +++ b/modules/highgui/include/opencv2/highgui/cap_ios.h @@ -0,0 +1,160 @@ +/* + * cap_ios.h + * For iOS video I/O + * by Eduard Feicho on 29/07/12 + * Copyright 2012. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 AUTHOR 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. + * + */ + +#import +#import +#import +#import +#include "opencv2/core/core.hpp" + +/////////////////////////////////////// CvAbstractCamera ///////////////////////////////////// + +@class CvAbstractCamera; + +@interface CvAbstractCamera : NSObject +{ + AVCaptureSession* captureSession; + AVCaptureConnection* videoCaptureConnection; + AVCaptureVideoPreviewLayer *captureVideoPreviewLayer; + + UIDeviceOrientation currentDeviceOrientation; + + BOOL cameraAvailable; + BOOL captureSessionLoaded; + BOOL running; + BOOL useAVCaptureVideoPreviewLayer; + + AVCaptureDevicePosition defaultAVCaptureDevicePosition; + AVCaptureVideoOrientation defaultAVCaptureVideoOrientation; + NSString *const defaultAVCaptureSessionPreset; + + int defaultFPS; + + UIView* parentView; + + int imageWidth; + int imageHeight; +} + +@property (nonatomic, retain) AVCaptureSession* captureSession; +@property (nonatomic, retain) AVCaptureConnection* videoCaptureConnection; + +@property (nonatomic, readonly) BOOL running; +@property (nonatomic, readonly) BOOL captureSessionLoaded; + +@property (nonatomic, assign) int defaultFPS; +@property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition; +@property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation; +@property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer; +@property (nonatomic, strong) NSString *const defaultAVCaptureSessionPreset; + +@property (nonatomic, assign) int imageWidth; +@property (nonatomic, assign) int imageHeight; + +@property (nonatomic, retain) UIView* parentView; + +- (void)pause; +- (void)start; +- (void)stop; +- (void)switchCameras; + +- (id)initWithParentView:(UIView*)parent; + +- (void)createCaptureOutput; +- (void)createVideoPreviewLayer; +- (void)updateOrientation; + + +@end + +///////////////////////////////// CvVideoCamera /////////////////////////////////////////// + +@class CvVideoCamera; + +@protocol CvVideoCameraDelegate + +#ifdef __cplusplus +// delegate method for processing image frames +- (void)processImage:(cv::Mat&)image; +#endif + +@end + +@interface CvVideoCamera : CvAbstractCamera +{ + AVCaptureVideoDataOutput *videoDataOutput; + + dispatch_queue_t videoDataOutputQueue; + CALayer *customPreviewLayer; + + BOOL grayscaleMode; + + BOOL recordVideo; + AVAssetWriterInput* recordAssetWriterInput; + AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; + AVAssetWriter* recordAssetWriter; + +} + +@property (nonatomic, assign) id delegate; +@property (nonatomic, assign) BOOL grayscaleMode; + +@property (nonatomic, assign) BOOL recordVideo; +@property (nonatomic, retain) AVAssetWriterInput* recordAssetWriterInput; +@property (nonatomic, retain) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; +@property (nonatomic, retain) AVAssetWriter* recordAssetWriter; + +- (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; +- (void)layoutPreviewLayer; +- (void)saveVideo; + +@end + +///////////////////////////////// CvPhotoCamera /////////////////////////////////////////// + +@class CvPhotoCamera; + +@protocol CvPhotoCameraDelegate + +- (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image; +- (void)photoCameraCancel:(CvPhotoCamera*)photoCamera; + +@end + +@interface CvPhotoCamera : CvAbstractCamera +{ + AVCaptureStillImageOutput *stillImageOutput; +} + +@property (nonatomic, assign) id delegate; + +- (void)takePicture; + +@end diff --git a/modules/highgui/src/cap_ios_abstract_camera.mm b/modules/highgui/src/cap_ios_abstract_camera.mm new file mode 100644 index 000000000..45b53b018 --- /dev/null +++ b/modules/highgui/src/cap_ios_abstract_camera.mm @@ -0,0 +1,408 @@ +/* + * cap_ios_abstract_camera.mm + * For iOS video I/O + * by Eduard Feicho on 29/07/12 + * Copyright 2012. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 AUTHOR 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. + * + */ + + +#import "opencv2/highgui/cap_ios.h" +#include "precomp.hpp" + +#pragma mark - Private Interface + +@interface CvAbstractCamera () + +@property (nonatomic, retain) AVCaptureVideoPreviewLayer* captureVideoPreviewLayer; + +- (void)deviceOrientationDidChange:(NSNotification*)notification; +- (void)startCaptureSession; + +- (void)setDesiredCameraPosition:(AVCaptureDevicePosition)desiredPosition; + +- (void)updateSize; + +@end + + +#pragma mark - Implementation + + +@implementation CvAbstractCamera + + + +#pragma mark Public + +@synthesize imageWidth; +@synthesize imageHeight; + + +@synthesize defaultFPS; +@synthesize defaultAVCaptureDevicePosition; +@synthesize defaultAVCaptureVideoOrientation; +@synthesize defaultAVCaptureSessionPreset; + + + +@synthesize captureSession; +@synthesize captureVideoPreviewLayer; +@synthesize videoCaptureConnection; +@synthesize running; +@synthesize captureSessionLoaded; +@synthesize useAVCaptureVideoPreviewLayer; + +@synthesize parentView; + +#pragma mark - Constructors + +- (id)init; +{ + self = [super init]; + if (self) { + // react to device orientation notifications + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(deviceOrientationDidChange:) + name:UIDeviceOrientationDidChangeNotification + object:nil]; + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + currentDeviceOrientation = [[UIDevice currentDevice] orientation]; + + + // check if camera available + cameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; + NSLog(@"camera available: %@", (cameraAvailable == YES ? @"YES" : @"NO") ); + + running = NO; + + // set camera default configuration + self.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront; + self.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationLandscapeLeft; + self.defaultFPS = 15; + self.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288; + + self.parentView = nil; + self.useAVCaptureVideoPreviewLayer = NO; + } + return self; +} + + + +- (id)initWithParentView:(UIView*)parent; +{ + self = [super init]; + if (self) { + // react to device orientation notifications + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(deviceOrientationDidChange:) + name:UIDeviceOrientationDidChangeNotification + object:nil]; + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + currentDeviceOrientation = [[UIDevice currentDevice] orientation]; + + + // check if camera available + cameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; + NSLog(@"camera available: %@", (cameraAvailable == YES ? @"YES" : @"NO") ); + + running = NO; + + // set camera default configuration + self.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront; + self.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationLandscapeLeft; + self.defaultFPS = 15; + self.defaultAVCaptureSessionPreset = AVCaptureSessionPreset640x480; + + self.parentView = parent; + self.useAVCaptureVideoPreviewLayer = YES; + } + return self; +} + + + +- (void)dealloc; +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; +} + + +#pragma mark - Public interface + + +- (void)start; +{ + if (![NSThread isMainThread]) { + NSLog(@"[Camera] Warning: Call start only from main thread"); + [self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO]; + return; + } + + if (running == YES) { + return; + } + running = YES; + + // TOOD update image size data before actually starting (needed for recording) + [self updateSize]; + + if (cameraAvailable) { + [self startCaptureSession]; + } +} + + +- (void)pause; +{ + running = NO; + [self.captureSession stopRunning]; +} + + + +- (void)stop; +{ + running = NO; + + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; + + [self.captureSession stopRunning]; + self.captureSession = nil; + self.captureVideoPreviewLayer = nil; + self.videoCaptureConnection = nil; + captureSessionLoaded = NO; +} + + + +// use front/back camera +- (void)switchCameras; +{ + BOOL was_running = self.running; + if (was_running) { + [self stop]; + } + if (self.defaultAVCaptureDevicePosition == AVCaptureDevicePositionFront) { + self.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack; + } else { + self.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront; + } + if (was_running) { + [self start]; + } +} + + + +#pragma mark - Device Orientation Changes + + +- (void)deviceOrientationDidChange:(NSNotification*)notification +{ + UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; + + switch (orientation) + { + case UIDeviceOrientationPortrait: + case UIDeviceOrientationPortraitUpsideDown: + case UIDeviceOrientationLandscapeLeft: + case UIDeviceOrientationLandscapeRight: + currentDeviceOrientation = orientation; + break; + + case UIDeviceOrientationFaceUp: + case UIDeviceOrientationFaceDown: + default: + break; + } + NSLog(@"deviceOrientationDidChange: %d", orientation); + + [self updateOrientation]; +} + + + +#pragma mark - Private Interface + +- (void)createCaptureSession; +{ + // set a av capture session preset + self.captureSession = [[AVCaptureSession alloc] init]; + if ([self.captureSession canSetSessionPreset:self.defaultAVCaptureSessionPreset]) { + [self.captureSession setSessionPreset:self.defaultAVCaptureSessionPreset]; + } else if ([self.captureSession canSetSessionPreset:AVCaptureSessionPresetLow]) { + [self.captureSession setSessionPreset:AVCaptureSessionPresetLow]; + } else { + NSLog(@"[Camera] Error: could not set session preset"); + } +} + +- (void)createCaptureDevice; +{ + // setup the device + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + [self setDesiredCameraPosition:self.defaultAVCaptureDevicePosition]; + NSLog(@"[Camera] device connected? %@", device.connected ? @"YES" : @"NO"); + NSLog(@"[Camera] device position %@", (device.position == AVCaptureDevicePositionBack) ? @"back" : @"front"); +} + + +- (void)createVideoPreviewLayer; +{ + self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession]; + + if ([self.captureVideoPreviewLayer isOrientationSupported]) { + [self.captureVideoPreviewLayer setOrientation:self.defaultAVCaptureVideoOrientation]; + } + + if (parentView != nil) { + self.captureVideoPreviewLayer.frame = self.parentView.bounds; + self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; + [self.parentView.layer addSublayer:self.captureVideoPreviewLayer]; + } + NSLog(@"[Camera] created AVCaptureVideoPreviewLayer"); +} + + + + +- (void)setDesiredCameraPosition:(AVCaptureDevicePosition)desiredPosition; +{ + for (AVCaptureDevice *device in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { + if ([device position] == desiredPosition) { + [self.captureSession beginConfiguration]; + + NSError* error; + AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; + if (!input) { + NSLog(@"error creating input %@", [error localizedDescription]); + } + + // support for autofocus + if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) { + NSError *error = nil; + if ([device lockForConfiguration:&error]) { + device.focusMode = AVCaptureFocusModeContinuousAutoFocus; + [device unlockForConfiguration]; + } else { + NSLog(@"unable to lock device for autofocos configuration %@", [error localizedDescription]); + } + } + [self.captureSession addInput:input]; + + for (AVCaptureInput *oldInput in self.captureSession.inputs) { + [self.captureSession removeInput:oldInput]; + } + [self.captureSession addInput:input]; + [self.captureSession commitConfiguration]; + + break; + } + } +} + + + +- (void)startCaptureSession +{ + if (!cameraAvailable) { + return; + } + + if (self.captureSessionLoaded == NO) { + [self createCaptureSession]; + [self createCaptureDevice]; + [self createCaptureOutput]; + + // setup preview layer + if (self.useAVCaptureVideoPreviewLayer) { + [self createVideoPreviewLayer]; + } else { + [self createCustomVideoPreview]; + } + + captureSessionLoaded = YES; + } + + [self.captureSession startRunning]; +} + + +- (void)createCaptureOutput; +{ + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; +} + +- (void)createCustomVideoPreview; +{ + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; +} + +- (void)updateOrientation; +{ + // nothing to do here +} + + +- (void)updateSize; +{ + if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPresetPhoto]) { + //TODO: find the correct resolution + self.imageWidth = 640; + self.imageHeight = 480; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPresetHigh]) { + //TODO: find the correct resolution + self.imageWidth = 640; + self.imageHeight = 480; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPresetMedium]) { + //TODO: find the correct resolution + self.imageWidth = 640; + self.imageHeight = 480; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPresetLow]) { + //TODO: find the correct resolution + self.imageWidth = 640; + self.imageHeight = 480; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPreset352x288]) { + self.imageWidth = 352; + self.imageHeight = 288; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPreset640x480]) { + self.imageWidth = 640; + self.imageHeight = 480; + } else if ([self.defaultAVCaptureSessionPreset isEqualToString:AVCaptureSessionPreset1280x720]) { + self.imageWidth = 1280; + self.imageHeight = 720; + } else { + self.imageWidth = 640; + self.imageHeight = 480; + } +} + +@end diff --git a/modules/highgui/src/cap_ios_photo_camera.mm b/modules/highgui/src/cap_ios_photo_camera.mm new file mode 100644 index 000000000..51e5ce229 --- /dev/null +++ b/modules/highgui/src/cap_ios_photo_camera.mm @@ -0,0 +1,165 @@ +/* + * cap_ios_photo_camera.mm + * For iOS video I/O + * by Eduard Feicho on 29/07/12 + * Copyright 2012. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 AUTHOR 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. + * + */ + + +#import "opencv2/highgui/cap_ios.h" +#include "precomp.hpp" + +#pragma mark - Private Interface + + +@interface CvPhotoCamera () + +@property (nonatomic, retain) AVCaptureStillImageOutput* stillImageOutput; + +@end + + + +#pragma mark - Implementation + + +@implementation CvPhotoCamera + + + +#pragma mark Public + +@synthesize stillImageOutput; +@synthesize delegate; + + +#pragma mark - Public interface + + +- (void)takePicture +{ + if (cameraAvailable == NO) { + return; + } + cameraAvailable = NO; + + + [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:self.videoCaptureConnection + completionHandler: + ^(CMSampleBufferRef imageSampleBuffer, NSError *error) + { + if (error == nil && imageSampleBuffer != NULL) + { + // TODO check + // NSNumber* imageOrientation = [UIImage cgImageOrientationForUIDeviceOrientation:currentDeviceOrientation]; + // CMSetAttachment(imageSampleBuffer, kCGImagePropertyOrientation, imageOrientation, 1); + + NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.captureSession stopRunning]; + + // Make sure we create objects on the main thread in the main context + UIImage* newImage = [UIImage imageWithData:jpegData]; + + //UIImageOrientation orientation = [newImage imageOrientation]; + + // TODO: only apply rotation, don't scale, since we can set this directly in the camera + /* + switch (orientation) { + case UIImageOrientationUp: + case UIImageOrientationDown: + newImage = [newImage imageWithAppliedRotationAndMaxSize:CGSizeMake(640.0, 480.0)]; + break; + case UIImageOrientationLeft: + case UIImageOrientationRight: + newImage = [newImage imageWithMaxSize:CGSizeMake(640.0, 480.0)]; + default: + break; + } + */ + + // We have captured the image, we can allow the user to take another picture + cameraAvailable = YES; + + NSLog(@"CvPhotoCamera captured image"); + if (self.delegate) { + [self.delegate photoCamera:self capturedImage:newImage]; + } + + [self.captureSession startRunning]; + }); + } + }]; + + +} + +- (void)stop; +{ + [super stop]; + self.stillImageOutput = nil; +} + + +#pragma mark - Private Interface + + +- (void)createStillImageOutput; +{ + // setup still image output with jpeg codec + self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; + NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; + [self.stillImageOutput setOutputSettings:outputSettings]; + [self.captureSession addOutput:self.stillImageOutput]; + + for (AVCaptureConnection *connection in self.stillImageOutput.connections) { + for (AVCaptureInputPort *port in [connection inputPorts]) { + if ([port.mediaType isEqual:AVMediaTypeVideo]) { + self.videoCaptureConnection = connection; + break; + } + } + if (self.videoCaptureConnection) { + break; + } + } + NSLog(@"[Camera] still image output created"); +} + + +- (void)createCaptureOutput; +{ + [self createStillImageOutput]; +} + +- (void)createCustomVideoPreview; +{ + //do nothing, always use AVCaptureVideoPreviewLayer +} + + +@end diff --git a/modules/highgui/src/cap_ios_video_camera.mm b/modules/highgui/src/cap_ios_video_camera.mm new file mode 100644 index 000000000..bed17e188 --- /dev/null +++ b/modules/highgui/src/cap_ios_video_camera.mm @@ -0,0 +1,656 @@ +/* + * cap_ios_video_camera.mm + * For iOS video I/O + * by Eduard Feicho on 29/07/12 + * Copyright 2012. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 AUTHOR 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. + * + */ + +#import "opencv2/highgui/cap_ios.h" +#include "precomp.hpp" + +#import + + +static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; + +#pragma mark - Private Interface + + + + +@interface CvVideoCamera () + +- (void)createVideoDataOutput; +- (void)createVideoFileOutput; + + +@property (nonatomic, retain) CALayer *customPreviewLayer; +@property (nonatomic, retain) AVCaptureVideoDataOutput *videoDataOutput; + +@end + + + +#pragma mark - Implementation + + + +@implementation CvVideoCamera + + + + +@synthesize delegate; +@synthesize grayscaleMode; + +@synthesize customPreviewLayer; +@synthesize videoDataOutput; + +@synthesize recordVideo; +//@synthesize videoFileOutput; +@synthesize recordAssetWriterInput; +@synthesize recordPixelBufferAdaptor; +@synthesize recordAssetWriter; + + + +#pragma mark - Constructors + +- (id)initWithParentView:(UIView*)parent; +{ + self = [super initWithParentView:parent]; + if (self) { + self.useAVCaptureVideoPreviewLayer = NO; + self.recordVideo = NO; + } + return self; +} + + + +#pragma mark - Public interface + + +- (void)start; +{ + [super start]; + + if (self.recordVideo == YES) { +// [self.videoFileOutput startRecordingToOutputFileURL:[self tempFileURL] recordingDelegate:self]; + + NSError* error; + if ([[NSFileManager defaultManager] fileExistsAtPath:[self tempFileString]]) [[NSFileManager defaultManager] removeItemAtPath:[self tempFileString] error:&error]; + if (error == nil) { + NSLog(@"[Camera] Delete file %@", [self tempFileString]); + } + + + BOOL started = [self.recordAssetWriter startWriting]; + [self.recordAssetWriter startSessionAtSourceTime:kCMTimeZero]; + + NSLog(@"[Camera] Session started? %d", started); + + if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { + NSLog(@"AVAssetWriter status: unknown"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { + NSLog(@"AVAssetWriter status: writing"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { + NSLog(@"AVAssetWriter status: completed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { + NSLog(@"AVAssetWriter status: failed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { + NSLog(@"AVAssetWriter status: cancelled"); + } + + if (self.recordAssetWriter.status != AVAssetWriterStatusWriting) { + NSLog(@"[Camera] Recording Error: asset writer status is not writing: %@", self.recordAssetWriter.error); + } else { + NSLog(@"[Camera] Recording started"); + } + } +} + + + +- (void)pause; +{ + [super pause]; + if (self.recordVideo == YES) { +// [self.videoFileOutput stopRecording]; + + + if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { + NSLog(@"AVAssetWriter status: unknown"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { + NSLog(@"AVAssetWriter status: writing"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { + NSLog(@"AVAssetWriter status: completed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { + NSLog(@"AVAssetWriter status: failed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { + NSLog(@"AVAssetWriter status: cancelled"); + } + + if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { + [self.recordAssetWriter finishWriting]; + NSLog(@"[Camera] recording stopped"); + } else { + NSLog(@"[Camera] Recording Error: asset writer status is not writing"); + } + } +} + + +- (void)stop; +{ + [super stop]; + + if (self.recordVideo == YES) { + NSLog(@"recording stop"); + if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { + NSLog(@"AVAssetWriter status: unknown"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { + NSLog(@"AVAssetWriter status: writing"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { + NSLog(@"AVAssetWriter status: completed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { + NSLog(@"AVAssetWriter status: failed"); + } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { + NSLog(@"AVAssetWriter status: cancelled"); + } + + + if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { + [self.recordAssetWriter finishWriting]; + NSLog(@"[Camera] recording stopped"); + } else { + NSLog(@"[Camera] Recording Error: asset writer status is not writing"); + } + + self.recordAssetWriter = nil; + self.recordAssetWriterInput = nil; + self.recordPixelBufferAdaptor = nil; + } + + self.videoDataOutput = nil; + if (videoDataOutputQueue) { + dispatch_release(videoDataOutputQueue); + } + + [self.customPreviewLayer removeFromSuperlayer]; + self.customPreviewLayer = nil; +} + +// TODO fix +- (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; +{ + + NSLog(@"layout preview layer"); + if (self.parentView != nil) { + + CALayer* layer = self.customPreviewLayer; + CGRect bounds = self.customPreviewLayer.bounds; + int rotation_angle = 0; + bool flip_bounds = false; + + switch (interfaceOrientation) { + case UIInterfaceOrientationPortrait: + NSLog(@"to Portrait"); + rotation_angle = 270; + break; + case UIInterfaceOrientationPortraitUpsideDown: + rotation_angle = 90; + NSLog(@"to UpsideDown"); + break; + case UIInterfaceOrientationLandscapeLeft: + rotation_angle = 0; + NSLog(@"to LandscapeLeft"); + break; + case UIInterfaceOrientationLandscapeRight: + rotation_angle = 180; + NSLog(@"to LandscapeRight"); + break; + default: + break; // leave the layer in its last known orientation + } + + switch (defaultAVCaptureVideoOrientation) { + case AVCaptureVideoOrientationLandscapeRight: + rotation_angle += 180; + break; + case AVCaptureVideoOrientationPortraitUpsideDown: + rotation_angle += 270; + break; + case AVCaptureVideoOrientationPortrait: + rotation_angle += 90; + case AVCaptureVideoOrientationLandscapeLeft: + break; + default: + break; + } + rotation_angle = rotation_angle % 360; + + if (rotation_angle == 90 || rotation_angle == 270) { + flip_bounds = true; + } + + if (flip_bounds) { + NSLog(@"flip bounds"); + bounds = CGRectMake(0, 0, bounds.size.height, bounds.size.width); + } + + layer.position = CGPointMake(self.parentView.frame.size.width/2., self.parentView.frame.size.height/2.); + self.customPreviewLayer.bounds = CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height); + + layer.affineTransform = CGAffineTransformMakeRotation( DegreesToRadians(rotation_angle) ); + layer.bounds = bounds; + } + +} + +// TODO fix +- (void)layoutPreviewLayer; +{ + NSLog(@"layout preview layer"); + if (self.parentView != nil) { + + CALayer* layer = self.customPreviewLayer; + CGRect bounds = self.customPreviewLayer.bounds; + int rotation_angle = 0; + bool flip_bounds = false; + + switch (currentDeviceOrientation) { + case UIDeviceOrientationPortrait: + rotation_angle = 270; + break; + case UIDeviceOrientationPortraitUpsideDown: + rotation_angle = 90; + break; + case UIDeviceOrientationLandscapeLeft: + NSLog(@"left"); + rotation_angle = 180; + break; + case UIDeviceOrientationLandscapeRight: + NSLog(@"right"); + rotation_angle = 0; + break; + case UIDeviceOrientationFaceUp: + case UIDeviceOrientationFaceDown: + default: + break; // leave the layer in its last known orientation + } + + switch (defaultAVCaptureVideoOrientation) { + case AVCaptureVideoOrientationLandscapeRight: + rotation_angle += 180; + break; + case AVCaptureVideoOrientationPortraitUpsideDown: + rotation_angle += 270; + break; + case AVCaptureVideoOrientationPortrait: + rotation_angle += 90; + case AVCaptureVideoOrientationLandscapeLeft: + break; + default: + break; + } + rotation_angle = rotation_angle % 360; + + if (rotation_angle == 90 || rotation_angle == 270) { + flip_bounds = true; + } + + if (flip_bounds) { + NSLog(@"flip bounds"); + bounds = CGRectMake(0, 0, bounds.size.height, bounds.size.width); + } + + layer.position = CGPointMake(self.parentView.frame.size.width/2., self.parentView.frame.size.height/2.); + layer.affineTransform = CGAffineTransformMakeRotation( DegreesToRadians(rotation_angle) ); + layer.bounds = bounds; + } + +} + + + + +#pragma mark - Private Interface + + + +- (void)createVideoDataOutput; +{ + // Make a video data output + self.videoDataOutput = [AVCaptureVideoDataOutput new]; + + // In grayscale mode we want YUV (YpCbCr 4:2:0) so we can directly access the graylevel intensity values (Y component) + // In color mode we, BGRA format is used + OSType format = self.grayscaleMode ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange : kCVPixelFormatType_32BGRA; + + self.videoDataOutput.videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:format] + forKey:(id)kCVPixelBufferPixelFormatTypeKey]; + + // discard if the data output queue is blocked (as we process the still image) + [self.videoDataOutput setAlwaysDiscardsLateVideoFrames:YES]; + + if ( [self.captureSession canAddOutput:self.videoDataOutput] ) { + [self.captureSession addOutput:self.videoDataOutput]; + } + [[self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:YES]; + + + // set default FPS + if ([self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].supportsVideoMinFrameDuration) { + [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].videoMinFrameDuration = CMTimeMake(1, self.defaultFPS); + } + if ([self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].supportsVideoMaxFrameDuration) { + [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].videoMaxFrameDuration = CMTimeMake(1, self.defaultFPS); + } + + // set video mirroring for front camera (more intuitive) + if ([self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].supportsVideoMirroring) { + if (self.defaultAVCaptureDevicePosition == AVCaptureDevicePositionFront) { + [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].videoMirrored = YES; + } else { + [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].videoMirrored = NO; + } + } + + // set default video orientation + if ([self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].supportsVideoOrientation) { + [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo].videoOrientation = self.defaultAVCaptureVideoOrientation; + } + + + // create a custom preview layer + self.customPreviewLayer = [CALayer layer]; + self.customPreviewLayer.bounds = CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height); + [self layoutPreviewLayer]; + + // create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured + // a serial dispatch queue must be used to guarantee that video frames will be delivered in order + // see the header doc for setSampleBufferDelegate:queue: for more information + videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL); + [self.videoDataOutput setSampleBufferDelegate:self queue:videoDataOutputQueue]; + + + NSLog(@"[Camera] created AVCaptureVideoDataOutput at %d FPS", self.defaultFPS); +} + + + +- (void)createVideoFileOutput; +{ + /* + if (self.recordVideo == YES) { + self.videoFileOutput = [[AVCaptureMovieFileOutput alloc] init]; + if ( [self.captureSession canAddOutput:self.videoFileOutput] ) { + [self.captureSession addOutput:self.videoFileOutput]; + } + } + */ + + /* Video File Output in H.264, via AVAsserWriter */ + NSLog(@"Create Video with dimensions %dx%d", self.imageWidth, self.imageHeight); + + NSDictionary *outputSettings + = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:self.imageWidth], AVVideoWidthKey, + [NSNumber numberWithInt:self.imageHeight], AVVideoHeightKey, + AVVideoCodecH264, AVVideoCodecKey, + nil + ]; + + + self.recordAssetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:outputSettings]; + + + /* I'm going to push pixel buffers to it, so will need a + AVAssetWriterPixelBufferAdaptor, to expect the same 32BGRA input as I've + asked the AVCaptureVideDataOutput to supply */ + int pixelBufferFormat = (self.grayscaleMode == YES) ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange : kCVPixelFormatType_32BGRA; + + self.recordPixelBufferAdaptor = + [[AVAssetWriterInputPixelBufferAdaptor alloc] + initWithAssetWriterInput:self.recordAssetWriterInput + sourcePixelBufferAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:pixelBufferFormat], kCVPixelBufferPixelFormatTypeKey,nil]]; + + NSError* error = nil; + NSLog(@"Create AVAssetWriter with url: %@", [self tempFileURL]); + self.recordAssetWriter = [AVAssetWriter assetWriterWithURL:[self tempFileURL] + fileType:AVFileTypeMPEG4 + error:&error]; + if (error != nil) { + NSLog(@"[Camera] Unable to create AVAssetWriter: %@", error); + } + + [self.recordAssetWriter addInput:self.recordAssetWriterInput]; + self.recordAssetWriterInput.expectsMediaDataInRealTime = NO; + + NSLog(@"[Camera] created AVAssetWriter"); + +} + + +- (void)createCaptureOutput; +{ + [self createVideoDataOutput]; + if (self.recordVideo == YES) { + [self createVideoFileOutput]; + } +} + +- (void)createCustomVideoPreview; +{ + [self.parentView.layer addSublayer:self.customPreviewLayer]; +} + + +#pragma mark - Protocol AVCaptureVideoDataOutputSampleBufferDelegate + + +- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection +{ + if (self.delegate) { + + // convert from Core Media to Core Video + CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); + CVPixelBufferLockBaseAddress(imageBuffer, 0); + + void* bufferAddress; + size_t width; + size_t height; + size_t bytesPerRow; + + CGColorSpaceRef colorSpace; + CGContextRef context; + + int format_opencv; + + OSType format = CVPixelBufferGetPixelFormatType(imageBuffer); + if (format == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) { + + format_opencv = CV_8UC1; + + bufferAddress = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); + width = CVPixelBufferGetWidthOfPlane(imageBuffer, 0); + height = CVPixelBufferGetHeightOfPlane(imageBuffer, 0); + bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0); + + } else { // expect kCVPixelFormatType_32BGRA + + format_opencv = CV_8UC4; + + bufferAddress = CVPixelBufferGetBaseAddress(imageBuffer); + width = CVPixelBufferGetWidth(imageBuffer); + height = CVPixelBufferGetHeight(imageBuffer); + bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); + + } + + // delegate image processing to the delegate + cv::Mat image(height, width, format_opencv, bufferAddress, bytesPerRow); + + cv::Mat* result = NULL; + CGImage* dstImage; + + if ([self.delegate respondsToSelector:@selector(processImage:)]) { + [self.delegate processImage:image]; + } + + // check if matrix data pointer or dimensions were changed by the delegate + bool iOSimage = true; + if (height == image.rows && width == image.cols && format_opencv == image.type() && bufferAddress == image.data && bytesPerRow == image.step) { + iOSimage = false; + } + + + // (create color space, create graphics context, render buffer) + CGBitmapInfo bitmapInfo; + + // basically we decide if it's a grayscale, rgb or rgba image + if (image.channels() == 1) { + colorSpace = CGColorSpaceCreateDeviceGray(); + bitmapInfo = kCGImageAlphaNone; + } else if (image.channels() == 3) { + colorSpace = CGColorSpaceCreateDeviceRGB(); + bitmapInfo = kCGImageAlphaNone; + if (iOSimage) { + bitmapInfo |= kCGBitmapByteOrder32Little; + } else { + bitmapInfo |= kCGBitmapByteOrder32Big; + } + } else { + colorSpace = CGColorSpaceCreateDeviceRGB(); + bitmapInfo = kCGImageAlphaPremultipliedFirst; + if (iOSimage) { + bitmapInfo |= kCGBitmapByteOrder32Little; + } else { + bitmapInfo |= kCGBitmapByteOrder32Big; + } + } + + if (iOSimage) { + context = CGBitmapContextCreate(bufferAddress, width, height, 8, bytesPerRow, colorSpace, bitmapInfo); + dstImage = CGBitmapContextCreateImage(context); + CGContextRelease(context); + } else { + + NSData *data = [NSData dataWithBytes:image.data length:image.elemSize()*image.total()]; + CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data); + + // Creating CGImage from cv::Mat + dstImage = CGImageCreate(image.cols, // width + image.rows, // height + 8, // bits per component + 8 * image.elemSize(), // bits per pixel + image.step, // bytesPerRow + colorSpace, // colorspace + bitmapInfo, // bitmap info + provider, // CGDataProviderRef + NULL, // decode + false, // should interpolate + kCGRenderingIntentDefault // intent + ); + + CGDataProviderRelease(provider); + } + + + + + // render buffer + dispatch_sync(dispatch_get_main_queue(), ^{ + self.customPreviewLayer.contents = (__bridge id)dstImage; + }); + + + if (self.recordVideo == YES) { + // a very dense way to keep track of the time at which this frame + // occurs relative to the output stream, but it's just an example! + + // TODO reset frame number + static int64_t frameNumber = 0; + if (self.recordAssetWriterInput.readyForMoreMediaData) { + [self.recordPixelBufferAdaptor appendPixelBuffer:imageBuffer + withPresentationTime:CMTimeMake(frameNumber, self.defaultFPS)]; + } + frameNumber++; + } + + + // cleanup + CGImageRelease(dstImage); + + CGColorSpaceRelease(colorSpace); + + CVPixelBufferUnlockBaseAddress(imageBuffer, 0); + } +} + + +- (void)updateOrientation; +{ + NSLog(@"rotate.."); + self.customPreviewLayer.bounds = CGRectMake(0, 0, self.parentView.frame.size.width, self.parentView.frame.size.height); + [self layoutPreviewLayer]; +} + + +- (void)saveVideo; +{ + if (self.recordVideo == NO) { + return; + } + + ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; + if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[self tempFileURL]]) { + [library writeVideoAtPathToSavedPhotosAlbum:[self tempFileURL] + completionBlock:^(NSURL *assetURL, NSError *error){}]; + } +} + + +- (NSURL *)tempFileURL; +{ + NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; + NSURL *outputURL = [NSURL fileURLWithPath:outputPath]; + NSFileManager *fileManager = [NSFileManager defaultManager]; + if ([fileManager fileExistsAtPath:outputPath]) { + NSLog(@"file exists"); + } + return outputURL; +} + + + +- (NSString *)tempFileString; +{ + NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; + return outputPath; +} + +@end From d8b69d750df06ddbb1c4de1b884f8d3938b86079 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Mon, 20 Aug 2012 19:46:52 +0400 Subject: [PATCH 21/40] some tweaks in optimization flags for opencv2.framework --- ios/cmake/Modules/Platform/iOS.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/cmake/Modules/Platform/iOS.cmake b/ios/cmake/Modules/Platform/iOS.cmake index e8389798b..4ef75e7f1 100644 --- a/ios/cmake/Modules/Platform/iOS.cmake +++ b/ios/cmake/Modules/Platform/iOS.cmake @@ -42,7 +42,7 @@ set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") set (CMAKE_C_FLAGS "") set (CMAKE_CXX_FLAGS "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden") -set (CMAKE_CXX_FLAGS_RELEASE "-O3 -fomit-frame-pointer") +set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") if (HAVE_FLAG_SEARCH_PATHS_FIRST) set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") From 4a1ef53deb6f64ae88ec25efd8ac262553eecf07 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 20 Aug 2012 19:51:19 +0400 Subject: [PATCH 22/40] Fixed gcc build warning --- modules/objdetect/src/hog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 19decfb53..21bda2411 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -2601,7 +2601,7 @@ void HOGDescriptor::readALTModel(std::string modelfile) double *linearwt = new double[totwords+1]; int length = totwords; nread = fread(linearwt, sizeof(double), totwords + 1, modelfl); - if(nread != length + 1) + if(nread != static_cast(length) + 1) throw Exception(); for(int i = 0; i < length; i++) From 682dede87e9b2d52ef3725608e1438a4ab8f202f Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Mon, 20 Aug 2012 19:52:24 +0400 Subject: [PATCH 23/40] #2215 Fix dependencies escaping in generated OpenCVConfig.cmake --- cmake/OpenCVGenConfig.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake index 7a38e4b4e..fcca310ce 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake @@ -64,9 +64,14 @@ macro(ocv_generate_dependencies_map_configcmake suffix configuration) string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "${OPENCV_LINK_LIBRARY_SUFFIX}" __libname "${__libname}") endif() + string(REPLACE " " "\\ " __mod_deps "${${__ocv_lib}_MODULE_DEPS_${suffix}}") + string(REPLACE " " "\\ " __ext_deps "${${__ocv_lib}_EXTRA_DEPS_${suffix}}") + string(REPLACE "\"" "\\\"" __mod_deps "${__mod_deps}") + string(REPLACE "\"" "\\\"" __ext_deps "${__ext_deps}") + set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_LIBNAME_${suffix} \"${__libname}\")\n") - set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_DEPS_${suffix} ${${__ocv_lib}_MODULE_DEPS_${suffix}})\n") - set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_EXTRA_DEPS_${suffix} ${${__ocv_lib}_EXTRA_DEPS_${suffix}})\n") + set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_DEPS_${suffix} ${__mod_deps})\n") + set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_EXTRA_DEPS_${suffix} ${__ext_deps})\n") list(APPEND OPENCV_PROCESSED_LIBS ${__ocv_lib}) list(APPEND OPENCV_LIBS_TO_PROCESS ${${__ocv_lib}_MODULE_DEPS_${suffix}}) From ee0dd4d4967082c6bf3e4ba8d8bb3871720a7ec8 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Mon, 20 Aug 2012 23:35:29 +0400 Subject: [PATCH 24/40] disabled -Wunused-but-set-variable because of multiple warnings during building nvcc auto generated files (GCC 4.6) --- cmake/OpenCVDetectCUDA.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index 60d800547..43e9c819a 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -88,7 +88,11 @@ if(CUDA_FOUND) if(APPLE) set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -fno-finite-math-only) endif() - string(REPLACE "-Wsign-promo" "" CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}") + + # disabled because of multiple warnings during building nvcc auto generated files + if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GCC_REGEX_VERSION VERSION_GREATER "4.6.0") + ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable) + endif() # we remove -ggdb3 flag as it leads to preprocessor errors when compiling CUDA files (CUDA 4.1) set(CMAKE_CXX_FLAGS_DEBUG_ ${CMAKE_CXX_FLAGS_DEBUG}) From 94f7c3c5923888caf14acb4ea86355888e3040fc Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 21 Aug 2012 01:03:52 +0400 Subject: [PATCH 25/40] Fixed FAST algorithm initializer --- modules/features2d/src/features2d_init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/features2d/src/features2d_init.cpp b/modules/features2d/src/features2d_init.cpp index 6ecffebd4..e21b8d802 100644 --- a/modules/features2d/src/features2d_init.cpp +++ b/modules/features2d/src/features2d_init.cpp @@ -59,7 +59,7 @@ CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", obj.info()->addParam(obj, "threshold", obj.threshold); obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); - obj.info()->addParam(obj, "type", obj.type, FastFeatureDetector::TYPE_9_16)); + obj.info()->addParam(obj, "type", obj.type, static_cast(FastFeatureDetector::TYPE_9_16))); /////////////////////////////////////////////////////////////////////////////////////////////////////////// From 81d6400f45796f701c4f01057ee8216af01fba56 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 21 Aug 2012 14:28:40 +0400 Subject: [PATCH 26/40] fixed compilation under windows --- modules/ts/include/opencv2/ts/ts_perf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ts/include/opencv2/ts/ts_perf.hpp b/modules/ts/include/opencv2/ts/ts_perf.hpp index d2a0b996e..f730b2ce7 100644 --- a/modules/ts/include/opencv2/ts/ts_perf.hpp +++ b/modules/ts/include/opencv2/ts/ts_perf.hpp @@ -442,7 +442,7 @@ CV_EXPORTS void PrintTo(const Size& sz, ::std::ostream* os); // SANITY_CHECK(c); // } #define PERF_TEST_P(fixture, name, params) \ - class fixture##_##name : public ::fixture {\ + class fixture##_##name : public fixture {\ public:\ fixture##_##name() {}\ protected:\ From 017ab51bf4edc45d0da2ccb0ca889c206f6735a1 Mon Sep 17 00:00:00 2001 From: Victor Passichenko Date: Tue, 21 Aug 2012 15:38:38 +0400 Subject: [PATCH 27/40] Fix wrong memory deallocation --- modules/photo/src/arrays.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/photo/src/arrays.hpp b/modules/photo/src/arrays.hpp index c1c4e5f97..0d86cb6e3 100644 --- a/modules/photo/src/arrays.hpp +++ b/modules/photo/src/arrays.hpp @@ -67,7 +67,7 @@ template struct Array2d { ~Array2d() { if (needToDeallocArray) { - delete a; + delete[] a; } } @@ -96,7 +96,7 @@ template struct Array3d { ~Array3d() { if (needToDeallocArray) { - delete a; + delete[] a; } } @@ -138,7 +138,7 @@ template struct Array4d { ~Array4d() { if (needToDeallocArray) { - delete a; + delete[] a; } } From 0d2b8f4ba11651306cf59dfaf4c0c29a0822b881 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 21 Aug 2012 15:41:05 +0400 Subject: [PATCH 28/40] fixed the channel ordering of rgba images (by Eduard) --- modules/highgui/src/cap_ios_video_camera.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/cap_ios_video_camera.mm b/modules/highgui/src/cap_ios_video_camera.mm index bed17e188..6f7bfa20f 100644 --- a/modules/highgui/src/cap_ios_video_camera.mm +++ b/modules/highgui/src/cap_ios_video_camera.mm @@ -522,9 +522,9 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; } // check if matrix data pointer or dimensions were changed by the delegate - bool iOSimage = true; + bool iOSimage = false; if (height == image.rows && width == image.cols && format_opencv == image.type() && bufferAddress == image.data && bytesPerRow == image.step) { - iOSimage = false; + iOSimage = true; } From 92edd4fc6e15bc98f6cd8903bd49ecd06a736253 Mon Sep 17 00:00:00 2001 From: Victor Passichenko Date: Tue, 21 Aug 2012 15:41:51 +0400 Subject: [PATCH 29/40] Fix building for MS VS C++: remove allocation of arrays of dynamic size in stack --- modules/photo/src/denoising.cpp | 4 ++-- .../src/fast_nlmeans_denoising_invoker.hpp | 14 +++++++------- .../fast_nlmeans_multi_denoising_invoker.hpp | 17 ++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index 39643e33d..b980b407b 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -103,7 +103,7 @@ static void fastNlMeansDenoisingMultiCheckPreconditions( int imgToDenoiseIndex, int temporalWindowSize, int templateWindowSize, int searchWindowSize) { - int src_imgs_size = srcImgs.size(); + int src_imgs_size = (int)srcImgs.size(); if (src_imgs_size == 0) { CV_Error(CV_StsBadArg, "Input images vector should not be empty!"); } @@ -176,7 +176,7 @@ void cv::fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, temporalWindowSize, templateWindowSize, searchWindowSize ); - int src_imgs_size = srcImgs.size(); + int src_imgs_size = (int)srcImgs.size(); if (srcImgs[0].type() != CV_8UC3) { CV_Error(CV_StsBadArg, "Type of input images should be CV_8UC3!"); diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp index 58e4a45e1..a45cb15d8 100644 --- a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp @@ -62,6 +62,10 @@ struct FastNlMeansDenoisingInvoker { void operator() (const BlockedRange& range) const; + void operator= (const FastNlMeansDenoisingInvoker& invoker) { + CV_Error(CV_StsNotImplemented, "Assigment operator is not implemented"); + } + private: const Mat& src_; Mat& dst_; @@ -153,16 +157,12 @@ void FastNlMeansDenoisingInvoker::operator() (const BlockedRange& range) cons int row_from = range.begin(); int row_to = range.end() - 1; - int dist_sums_array[search_window_size_ * search_window_size_]; - Array2d dist_sums(dist_sums_array, search_window_size_, search_window_size_); + Array2d dist_sums(search_window_size_, search_window_size_); // for lazy calc optimization - int col_dist_sums_array[template_window_size_ * search_window_size_ * search_window_size_]; - Array3d col_dist_sums(&col_dist_sums_array[0], - template_window_size_, search_window_size_, search_window_size_); + Array3d col_dist_sums(template_window_size_, search_window_size_, search_window_size_); int first_col_num = -1; - Array3d up_col_dist_sums(src_.cols, search_window_size_, search_window_size_); for (int i = row_from; i <= row_to; i++) { @@ -233,7 +233,7 @@ void FastNlMeansDenoisingInvoker::operator() (const BlockedRange& range) cons // calc weights int weights_sum = 0; - int estimation[src_.channels()]; + int estimation[3]; for (int channel_num = 0; channel_num < src_.channels(); channel_num++) { estimation[channel_num] = 0; } diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp index cb08c7e43..8a6a81979 100644 --- a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -63,6 +63,10 @@ struct FastNlMeansMultiDenoisingInvoker { void operator() (const BlockedRange& range) const; + void operator= (const FastNlMeansMultiDenoisingInvoker& invoker) { + CV_Error(CV_StsNotImplemented, "Assigment operator is not implemented"); + } + private: int rows_; int cols_; @@ -175,16 +179,11 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) int row_from = range.begin(); int row_to = range.end() - 1; - int dist_sums_array[temporal_window_size_ * search_window_size_ * search_window_size_]; - Array3d dist_sums(dist_sums_array, - temporal_window_size_, search_window_size_, search_window_size_); + Array3d dist_sums(temporal_window_size_, search_window_size_, search_window_size_); // for lazy calc optimization - int col_dist_sums_array[ - template_window_size_ * temporal_window_size_ * search_window_size_ * search_window_size_]; - - Array4d col_dist_sums(col_dist_sums_array, - template_window_size_, temporal_window_size_, search_window_size_, search_window_size_); + Array4d col_dist_sums( + template_window_size_, temporal_window_size_, search_window_size_, search_window_size_); int first_col_num = -1; @@ -263,7 +262,7 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) // calc weights int weights_sum = 0; - int estimation[channels_count_]; + int estimation[3]; for (int channel_num = 0; channel_num < channels_count_; channel_num++) { estimation[channel_num] = 0; } From 18de45f7bcda86e453156f3d18e1cdb8ded5ec42 Mon Sep 17 00:00:00 2001 From: Victor Passichenko Date: Tue, 21 Aug 2012 16:05:18 +0400 Subject: [PATCH 30/40] Add CV_Asserts for channels count --- modules/photo/src/fast_nlmeans_denoising_invoker.hpp | 2 ++ modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp index a45cb15d8..6724e8272 100644 --- a/modules/photo/src/fast_nlmeans_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_invoker.hpp @@ -106,6 +106,8 @@ FastNlMeansDenoisingInvoker::FastNlMeansDenoisingInvoker( int search_window_size, const double h) : src_(src), dst_(dst) { + CV_Assert(src.channels() <= 3); + template_window_half_size_ = template_window_size / 2; search_window_half_size_ = search_window_size / 2; template_window_size_ = template_window_half_size_ * 2 + 1; diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp index 8a6a81979..02185d13d 100644 --- a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -115,6 +115,9 @@ FastNlMeansMultiDenoisingInvoker::FastNlMeansMultiDenoisingInvoker( int search_window_size, const double h) : dst_(dst), extended_srcs_(srcImgs.size()) { + CV_Assert(srcImgs.size() > 0); + CV_Assert(srcImgs[0].channels() <= 3); + rows_ = srcImgs[0].rows; cols_ = srcImgs[0].cols; channels_count_ = srcImgs[0].channels(); From 2f1cc018c9be148ebe55976e41ab70faafeee45d Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 21 Aug 2012 17:16:06 +0400 Subject: [PATCH 31/40] enabled SSE3 by default; integrated SSE3-optimized bilateral filter (by Grigoriy Frolov); modified API of non-local means (use Input/OutputArrays) --- CMakeLists.txt | 2 +- modules/imgproc/src/smooth.cpp | 237 ++++++++++++++++-- .../photo/include/opencv2/photo/denoising.hpp | 28 +-- modules/photo/src/denoising.cpp | 35 ++- .../fast_nlmeans_multi_denoising_invoker.hpp | 7 +- 5 files changed, 261 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80cf798ee..c81cbd9de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,7 +191,7 @@ OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE "Enable SSE instructions" ON IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE2 "Enable SSE2 instructions" ON IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) -OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" OFF IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" ON IF (MSVC OR CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 058768551..0fe1b6be4 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1294,28 +1294,64 @@ class BilateralFilter_8u_Invoker : public: BilateralFilter_8u_Invoker(Mat& _dest, const Mat& _temp, int _radius, int _maxk, int* _space_ofs, float *_space_weight, float *_color_weight) : - ParallelLoopBody(), dest(&_dest), temp(&_temp), radius(_radius), + temp(&_temp), dest(&_dest), radius(_radius), maxk(_maxk), space_ofs(_space_ofs), space_weight(_space_weight), color_weight(_color_weight) { } - + virtual void operator() (const Range& range) const { int i, j, cn = dest->channels(), k; Size size = dest->size(); - + #if CV_SSE3 + int CV_DECL_ALIGNED(16) buf[4]; + float CV_DECL_ALIGNED(16) bufSum[4]; + static const int CV_DECL_ALIGNED(16) bufSignMask[] = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; + bool haveSSE3 = checkHardwareSupport(CV_CPU_SSE3); + #endif + for( i = range.start; i < range.end; i++ ) { const uchar* sptr = temp->ptr(i+radius) + radius*cn; uchar* dptr = dest->ptr(i); - + if( cn == 1 ) { for( j = 0; j < size.width; j++ ) { float sum = 0, wsum = 0; int val0 = sptr[j]; - for( k = 0; k < maxk; k++ ) + k = 0; + #if CV_SSE3 + if( haveSSE3 ) + { + __m128 _val0 = _mm_set1_ps(val0); + const __m128 _signMask = _mm_load_ps((const float*)bufSignMask); + + for( ; k <= maxk - 4; k += 4 ) + { + __m128 _valF = _mm_set_ps(sptr[j + space_ofs[k+3]], sptr[j + space_ofs[k+2]], + sptr[j + space_ofs[k+1]], sptr[j + space_ofs[k]]); + + __m128 _val = _mm_andnot_ps(_signMask, _mm_sub_ps(_valF, _val0)); + _mm_store_si128((__m128i*)buf, _mm_cvtps_epi32(_val)); + + __m128 _cw = _mm_set_ps(color_weight[buf[3]],color_weight[buf[2]], + color_weight[buf[1]],color_weight[buf[0]]); + __m128 _sw = _mm_loadu_ps(space_weight+k); + __m128 _w = _mm_mul_ps(_cw, _sw); + _cw = _mm_mul_ps(_w, _valF); + + _sw = _mm_hadd_ps(_w, _cw); + _sw = _mm_hadd_ps(_sw, _sw); + _mm_storel_pi((__m64*)bufSum, _sw); + + sum += bufSum[1]; + wsum += bufSum[0]; + } + } + #endif + for( ; k < maxk; k++ ) { int val = sptr[j + space_ofs[k]]; float w = space_weight[k]*color_weight[std::abs(val - val0)]; @@ -1333,7 +1369,57 @@ public: { float sum_b = 0, sum_g = 0, sum_r = 0, wsum = 0; int b0 = sptr[j], g0 = sptr[j+1], r0 = sptr[j+2]; - for( k = 0; k < maxk; k++ ) + k = 0; + #if CV_SSE3 + if( haveSSE3 ) + { + const __m128 _b0 = _mm_set1_ps(b0); + const __m128 _g0 = _mm_set1_ps(g0); + const __m128 _r0 = _mm_set1_ps(r0); + const __m128 _signMask = _mm_load_ps((const float*)bufSignMask); + + for( ; k <= maxk - 4; k += 4 ) + { + const uchar* sptr_k = sptr + j + space_ofs[k]; + const uchar* sptr_k1 = sptr + j + space_ofs[k+1]; + const uchar* sptr_k2 = sptr + j + space_ofs[k+2]; + const uchar* sptr_k3 = sptr + j + space_ofs[k+3]; + + __m128 _b = _mm_set_ps(sptr_k3[0],sptr_k2[0],sptr_k1[0],sptr_k[0]); + __m128 _g = _mm_set_ps(sptr_k3[1],sptr_k2[1],sptr_k1[1],sptr_k[1]); + __m128 _r = _mm_set_ps(sptr_k3[2],sptr_k2[2],sptr_k1[2],sptr_k[2]); + + __m128 bt = _mm_andnot_ps(_signMask, _mm_sub_ps(_b,_b0)); + __m128 gt = _mm_andnot_ps(_signMask, _mm_sub_ps(_g,_g0)); + __m128 rt = _mm_andnot_ps(_signMask, _mm_sub_ps(_r,_r0)); + + bt =_mm_add_ps(rt, _mm_add_ps(bt, gt)); + _mm_store_si128((__m128i*)buf, _mm_cvtps_epi32(bt)); + + __m128 _w = _mm_set_ps(color_weight[buf[3]],color_weight[buf[2]], + color_weight[buf[1]],color_weight[buf[0]]); + __m128 _sw = _mm_loadu_ps(space_weight+k); + + _w = _mm_mul_ps(_w,_sw); + _b = _mm_mul_ps(_b, _w); + _g = _mm_mul_ps(_g, _w); + _r = _mm_mul_ps(_r, _w); + + _w = _mm_hadd_ps(_w, _b); + _g = _mm_hadd_ps(_g, _r); + + _w = _mm_hadd_ps(_w, _g); + _mm_store_ps(bufSum, _w); + + wsum += bufSum[0]; + sum_b += bufSum[1]; + sum_g += bufSum[2]; + sum_r += bufSum[3]; + } + } + #endif + + for( ; k < maxk; k++ ) { const uchar* sptr_k = sptr + j + space_ofs[k]; int b = sptr_k[0], g = sptr_k[1], r = sptr_k[2]; @@ -1351,10 +1437,10 @@ public: } } } - + private: - Mat *dest; const Mat *temp; + Mat *dest; int radius, maxk, *space_ofs; float *space_weight, *color_weight; }; @@ -1364,46 +1450,51 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d, double sigma_color, double sigma_space, int borderType ) { + int cn = src.channels(); int i, j, maxk, radius; Size size = src.size(); - + CV_Assert( (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data ); - + if( sigma_color <= 0 ) sigma_color = 1; if( sigma_space <= 0 ) sigma_space = 1; - + double gauss_color_coeff = -0.5/(sigma_color*sigma_color); double gauss_space_coeff = -0.5/(sigma_space*sigma_space); - + if( d <= 0 ) radius = cvRound(sigma_space*1.5); else radius = d/2; radius = MAX(radius, 1); d = radius*2 + 1; - + Mat temp; copyMakeBorder( src, temp, radius, radius, radius, radius, borderType ); - + vector _color_weight(cn*256); vector _space_weight(d*d); vector _space_ofs(d*d); float* color_weight = &_color_weight[0]; float* space_weight = &_space_weight[0]; int* space_ofs = &_space_ofs[0]; - + // initialize color-related bilateral filter coefficients + for( i = 0; i < 256*cn; i++ ) color_weight[i] = (float)std::exp(i*i*gauss_color_coeff); - + // initialize space-related bilateral filter coefficients for( i = -radius, maxk = 0; i <= radius; i++ ) - for( j = -radius; j <= radius; j++ ) + { + j = -radius; + + for( ;j <= radius; j++ ) { double r = std::sqrt((double)i*i + (double)j*j); if( r > radius ) @@ -1411,7 +1502,8 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d, space_weight[maxk] = (float)std::exp(r*r*gauss_space_coeff); space_ofs[maxk++] = (int)(i*temp.step + j*cn); } - + } + BilateralFilter_8u_Invoker body(dst, temp, radius, maxk, space_ofs, space_weight, color_weight); parallel_for_(Range(0, size.height), body); } @@ -1424,7 +1516,7 @@ public: BilateralFilter_32f_Invoker(int _cn, int _radius, int _maxk, int *_space_ofs, const Mat& _temp, Mat& _dest, float _scale_index, float *_space_weight, float *_expLUT) : - ParallelLoopBody(), cn(_cn), radius(_radius), maxk(_maxk), space_ofs(_space_ofs), + cn(_cn), radius(_radius), maxk(_maxk), space_ofs(_space_ofs), temp(&_temp), dest(&_dest), scale_index(_scale_index), space_weight(_space_weight), expLUT(_expLUT) { } @@ -1433,6 +1525,12 @@ public: { int i, j, k; Size size = dest->size(); + #if CV_SSE3 + int CV_DECL_ALIGNED(16) idxBuf[4]; + float CV_DECL_ALIGNED(16) bufSum32[4]; + static const int CV_DECL_ALIGNED(16) bufSignMask[] = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 }; + bool haveSSE3 = checkHardwareSupport(CV_CPU_SSE3); + #endif for( i = range.start; i < range.end; i++ ) { @@ -1445,7 +1543,44 @@ public: { float sum = 0, wsum = 0; float val0 = sptr[j]; - for( k = 0; k < maxk; k++ ) + k = 0; + #if CV_SSE3 + if( haveSSE3 ) + { + const __m128 _val0 = _mm_set1_ps(sptr[j]); + const __m128 _scale_index = _mm_set1_ps(scale_index); + const __m128 _signMask = _mm_load_ps((const float*)bufSignMask); + + for( ; k <= maxk - 4 ; k += 4 ) + { + __m128 _sw = _mm_loadu_ps(space_weight + k); + __m128 _val = _mm_set_ps(sptr[j + space_ofs[k+3]], sptr[j + space_ofs[k+2]], + sptr[j + space_ofs[k+1]], sptr[j + space_ofs[k]]); + __m128 _alpha = _mm_mul_ps(_mm_andnot_ps( _signMask, _mm_sub_ps(_val,_val0)), _scale_index); + + __m128i _idx = _mm_cvtps_epi32(_alpha); + _mm_store_si128((__m128i*)idxBuf, _idx); + _alpha = _mm_sub_ps(_alpha, _mm_cvtepi32_ps(_idx)); + + __m128 _explut = _mm_set_ps(expLUT[idxBuf[3]], expLUT[idxBuf[2]], + expLUT[idxBuf[1]], expLUT[idxBuf[0]]); + __m128 _explut1 = _mm_set_ps(expLUT[idxBuf[3]+1], expLUT[idxBuf[2]+1], + expLUT[idxBuf[1]+1], expLUT[idxBuf[0]+1]); + + __m128 _w = _mm_mul_ps(_sw, _mm_add_ps(_explut, _mm_mul_ps(_alpha, _mm_sub_ps(_explut1, _explut)))); + _val = _mm_mul_ps(_w, _val); + + _sw = _mm_hadd_ps(_w, _val); + _sw = _mm_hadd_ps(_sw, _sw); + _mm_storel_pi((__m64*)bufSum32, _sw); + + sum += bufSum32[1]; + wsum += bufSum32[0]; + } + } + #endif + + for( ; k < maxk; k++ ) { float val = sptr[j + space_ofs[k]]; float alpha = (float)(std::abs(val - val0)*scale_index); @@ -1465,7 +1600,64 @@ public: { float sum_b = 0, sum_g = 0, sum_r = 0, wsum = 0; float b0 = sptr[j], g0 = sptr[j+1], r0 = sptr[j+2]; - for( k = 0; k < maxk; k++ ) + k = 0; + #if CV_SSE3 + if( haveSSE3 ) + { + const __m128 _b0 = _mm_set1_ps(b0); + const __m128 _g0 = _mm_set1_ps(g0); + const __m128 _r0 = _mm_set1_ps(r0); + const __m128 _scale_index = _mm_set1_ps(scale_index); + const __m128 _signMask = _mm_load_ps((const float*)bufSignMask); + + for( ; k <= maxk-4; k += 4 ) + { + __m128 _sw = _mm_loadu_ps(space_weight + k); + + const float* sptr_k = sptr + j + space_ofs[k]; + const float* sptr_k1 = sptr + j + space_ofs[k+1]; + const float* sptr_k2 = sptr + j + space_ofs[k+2]; + const float* sptr_k3 = sptr + j + space_ofs[k+3]; + + __m128 _b = _mm_set_ps(sptr_k3[0], sptr_k2[0], sptr_k1[0], sptr_k[0]); + __m128 _g = _mm_set_ps(sptr_k3[1], sptr_k2[1], sptr_k1[1], sptr_k[1]); + __m128 _r = _mm_set_ps(sptr_k3[2], sptr_k2[2], sptr_k1[2], sptr_k[2]); + + __m128 _bt = _mm_andnot_ps(_signMask,_mm_sub_ps(_b,_b0)); + __m128 _gt = _mm_andnot_ps(_signMask,_mm_sub_ps(_g,_g0)); + __m128 _rt = _mm_andnot_ps(_signMask,_mm_sub_ps(_r,_r0)); + + __m128 _alpha = _mm_mul_ps(_scale_index, _mm_add_ps(_rt,_mm_add_ps(_bt, _gt))); + + __m128i _idx = _mm_cvtps_epi32(_alpha); + _mm_store_si128((__m128i*)idxBuf, _idx); + _alpha = _mm_sub_ps(_alpha, _mm_cvtepi32_ps(_idx)); + + __m128 _explut = _mm_set_ps(expLUT[idxBuf[3]], expLUT[idxBuf[2]], expLUT[idxBuf[1]], expLUT[idxBuf[0]]); + __m128 _explut1 = _mm_set_ps(expLUT[idxBuf[3]+1], expLUT[idxBuf[2]+1], expLUT[idxBuf[1]+1], expLUT[idxBuf[0]+1]); + + __m128 _w = _mm_mul_ps(_sw, _mm_add_ps(_explut, _mm_mul_ps(_alpha, _mm_sub_ps(_explut1, _explut)))); + + _b = _mm_mul_ps(_b, _w); + _g = _mm_mul_ps(_g, _w); + _r = _mm_mul_ps(_r, _w); + + _w = _mm_hadd_ps(_w, _b); + _g = _mm_hadd_ps(_g, _r); + + _w = _mm_hadd_ps(_w, _g); + _mm_store_ps(bufSum32, _w); + + wsum += bufSum32[0]; + sum_b += bufSum32[1]; + sum_g += bufSum32[2]; + sum_r += bufSum32[3]; + } + + } + #endif + + for(; k < maxk; k++ ) { const float* sptr_k = sptr + j + space_ofs[k]; float b = sptr_k[0], g = sptr_k[1], r = sptr_k[2]; @@ -1493,6 +1685,7 @@ private: Mat *dest; float scale_index, *space_weight, *expLUT; }; + static void bilateralFilter_32f( const Mat& src, Mat& dst, int d, @@ -1569,7 +1762,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, } // initialize space-related bilateral filter coefficients - for( i = -radius, maxk = 0; i <= radius; i++ ) + for( i = -radius, maxk = 0; i <= radius; i++ ) for( j = -radius; j <= radius; j++ ) { double r = std::sqrt((double)i*i + (double)j*j); diff --git a/modules/photo/include/opencv2/photo/denoising.hpp b/modules/photo/include/opencv2/photo/denoising.hpp index b322c3175..1fc35a674 100644 --- a/modules/photo/include/opencv2/photo/denoising.hpp +++ b/modules/photo/include/opencv2/photo/denoising.hpp @@ -55,23 +55,23 @@ namespace cv { -CV_EXPORTS void fastNlMeansDenoising( const Mat& src, Mat& dst, - int templateWindowSize, int searchWindowSize, int h); +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, + int templateWindowSize, int searchWindowSize, int h); -CV_EXPORTS void fastNlMeansDenoisingColored( const Mat& src, Mat& dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents); +CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents); -CV_EXPORTS void fastNlMeansDenoisingMulti( const std::vector& srcImgs, - int imgToDenoiseIndex, int temporalWindowSize, - Mat& dst, - int templateWindowSize, int searchWindowSize, int h); +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + OutputArray dst, + int templateWindowSize, int searchWindowSize, int h); -CV_EXPORTS void fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, - int imgToDenoiseIndex, int temporalWindowSize, - Mat& dst, - int templateWindowSize, int searchWindowSize, - int h, int hForColorComponents); +CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, + int imgToDenoiseIndex, int temporalWindowSize, + OutputArray dst, + int templateWindowSize, int searchWindowSize, + int h, int hForColorComponents); } #endif diff --git a/modules/photo/src/denoising.cpp b/modules/photo/src/denoising.cpp index b980b407b..7452d0d3c 100644 --- a/modules/photo/src/denoising.cpp +++ b/modules/photo/src/denoising.cpp @@ -45,9 +45,13 @@ #include "fast_nlmeans_denoising_invoker.hpp" #include "fast_nlmeans_multi_denoising_invoker.hpp" -void cv::fastNlMeansDenoising( const cv::Mat& src, cv::Mat& dst, +void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, int templateWindowSize, int searchWindowSize, int h) -{ +{ + Mat src = _src.getMat(); + _dst.create(src.size(), src.type()); + Mat dst = _dst.getMat(); + switch (src.type()) { case CV_8U: parallel_for(cv::BlockedRange(0, src.rows), @@ -70,10 +74,14 @@ void cv::fastNlMeansDenoising( const cv::Mat& src, cv::Mat& dst, } } -void cv::fastNlMeansDenoisingColored( const cv::Mat& src, cv::Mat& dst, +void cv::fastNlMeansDenoisingColored( InputArray _src, OutputArray _dst, int templateWindowSize, int searchWindowSize, int h, int hForColorComponents) { + Mat src = _src.getMat(); + _dst.create(src.size(), src.type()); + Mat dst = _dst.getMat(); + if (src.type() != CV_8UC3) { CV_Error(CV_StsBadArg, "Type of input image should be CV_8UC3!"); return; @@ -130,15 +138,20 @@ static void fastNlMeansDenoisingMultiCheckPreconditions( } } -void cv::fastNlMeansDenoisingMulti( const std::vector& srcImgs, +void cv::fastNlMeansDenoisingMulti( InputArrayOfArrays _srcImgs, int imgToDenoiseIndex, int temporalWindowSize, - cv::Mat& dst, + OutputArray _dst, int templateWindowSize, int searchWindowSize, int h) -{ +{ + vector srcImgs; + _srcImgs.getMatVector(srcImgs); + fastNlMeansDenoisingMultiCheckPreconditions( srcImgs, imgToDenoiseIndex, temporalWindowSize, templateWindowSize, searchWindowSize ); + _dst.create(srcImgs[0].size(), srcImgs[0].type()); + Mat dst = _dst.getMat(); switch (srcImgs[0].type()) { case CV_8U: @@ -165,16 +178,22 @@ void cv::fastNlMeansDenoisingMulti( const std::vector& srcImgs, } } -void cv::fastNlMeansDenoisingColoredMulti( const std::vector& srcImgs, +void cv::fastNlMeansDenoisingColoredMulti( InputArrayOfArrays _srcImgs, int imgToDenoiseIndex, int temporalWindowSize, - cv::Mat& dst, + OutputArray _dst, int templateWindowSize, int searchWindowSize, int h, int hForColorComponents) { + vector srcImgs; + _srcImgs.getMatVector(srcImgs); + fastNlMeansDenoisingMultiCheckPreconditions( srcImgs, imgToDenoiseIndex, temporalWindowSize, templateWindowSize, searchWindowSize ); + + _dst.create(srcImgs[0].size(), srcImgs[0].type()); + Mat dst = _dst.getMat(); int src_imgs_size = (int)srcImgs.size(); diff --git a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp index 02185d13d..602007e32 100644 --- a/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp +++ b/modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp @@ -270,9 +270,9 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) estimation[channel_num] = 0; } for (int d = 0; d < temporal_window_size_; d++) { + const Mat& esrc_d = extended_srcs_[d]; for (int y = 0; y < search_window_size_; y++) { - const T* cur_row_ptr = - extended_srcs_[d].ptr(border_size_ + search_window_y + y); + const T* cur_row_ptr = esrc_d.ptr(border_size_ + search_window_y + y); int* dist_sums_row = dist_sums.row_ptr(d, y); @@ -298,7 +298,8 @@ void FastNlMeansMultiDenoisingInvoker::operator() (const BlockedRange& range) dst_.at(i,j) = saturateCastFromArray(estimation); } else { // weights_sum == 0 - dst_.at(i,j) = extended_srcs_[temporal_window_half_size_].at(i,j); + const Mat& esrc = extended_srcs_[temporal_window_half_size_]; + dst_.at(i,j) = esrc.at(i,j); } } } From 10dcf9ea39999a26f5b1d49cf7f742be9899f53d Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 21 Aug 2012 18:34:02 +0400 Subject: [PATCH 32/40] Fix Java API build --- modules/photo/include/opencv2/photo/denoising.hpp | 8 ++++---- modules/photo/include/opencv2/photo/photo.hpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/photo/include/opencv2/photo/denoising.hpp b/modules/photo/include/opencv2/photo/denoising.hpp index 1fc35a674..718c3b73e 100644 --- a/modules/photo/include/opencv2/photo/denoising.hpp +++ b/modules/photo/include/opencv2/photo/denoising.hpp @@ -59,18 +59,18 @@ CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, int templateWindowSize, int searchWindowSize, int h); CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, - int templateWindowSize, int searchWindowSize, + int templateWindowSize, int searchWindowSize, int h, int hForColorComponents); -CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, int imgToDenoiseIndex, int temporalWindowSize, OutputArray dst, int templateWindowSize, int searchWindowSize, int h); -CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, +CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, int imgToDenoiseIndex, int temporalWindowSize, OutputArray dst, - int templateWindowSize, int searchWindowSize, + int templateWindowSize, int searchWindowSize, int h, int hForColorComponents); } diff --git a/modules/photo/include/opencv2/photo/photo.hpp b/modules/photo/include/opencv2/photo/photo.hpp index 40a092432..f771b8fbd 100644 --- a/modules/photo/include/opencv2/photo/photo.hpp +++ b/modules/photo/include/opencv2/photo/photo.hpp @@ -47,6 +47,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/photo/photo_c.h" +#include "opencv2/photo/denoising.hpp" #ifdef __cplusplus From a840d929aca2ffc6429882e92570b69850e88784 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 21 Aug 2012 18:59:51 +0400 Subject: [PATCH 33/40] #2170 fix warning of undefined GTEST_HAS_DEATH_TEST --- modules/ts/include/opencv2/ts/ts_gtest.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/ts/include/opencv2/ts/ts_gtest.h b/modules/ts/include/opencv2/ts/ts_gtest.h index 1300ff2d6..f98f71b28 100644 --- a/modules/ts/include/opencv2/ts/ts_gtest.h +++ b/modules/ts/include/opencv2/ts/ts_gtest.h @@ -1702,6 +1702,8 @@ inline bool operator!=(const GTEST_10_TUPLE_(T)& t, GTEST_OS_OPENBSD || GTEST_OS_QNX) # define GTEST_HAS_DEATH_TEST 1 # include // NOLINT +#else +# define GTEST_HAS_DEATH_TEST 0 #endif // We don't support MSVC 7.1 with exceptions disabled now. Therefore From 64661ea9cd2cdd97b43740f07565a6f64abbb810 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 21 Aug 2012 23:00:50 +0400 Subject: [PATCH 34/40] added SSE2-optimized resizeAreaFast for 8-bit images by Grigoriy Frolov --- modules/imgproc/src/imgwarp.cpp | 117 ++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index a311d5be6..b09588879 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -1328,6 +1328,123 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in } } } + + +template <> static void +resizeAreaFast_( const Mat& src, Mat& dst, const int* ofs, const int* xofs, + int scale_x, int scale_y ) +{ +#if CV_SSE2 + bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2); +#endif + + Size ssize = src.size(), dsize = dst.size(); + int cn = src.channels(); + int dy, dx, k = 0; + int area = scale_x*scale_y; + float scale = 1.f/(scale_x*scale_y); + int dwidth1 = (ssize.width/scale_x)*cn; + dsize.width *= cn; + ssize.width *= cn; + //avg values + for( dy = 0; dy < dsize.height; dy++ ) + { + uchar* D = (uchar*)(dst.data + dst.step*dy); + int sy0 = dy*scale_y, w = sy0 + scale_y <= ssize.height ? dwidth1 : 0; + if( sy0 >= ssize.height ) + { + for( dx = 0; dx < dsize.width; dx++ ) //memset(D,0, dsize.width);//warning, never executed -> not tested + D[dx] = 0; + continue; + } + dx = 0; + + #if CV_SSE2 + if( haveSSE2 ) + { + const __m128 _scale = _mm_set1_ps(scale); + const __m128i _ucMAXs = _mm_set1_epi16(UCHAR_MAX); + const uchar* _S[8]; + + for(; dx < w-8; dx+=8 ) + { + __m128i _sum = _mm_setzero_si128(); + __m128i _sum1 = _mm_setzero_si128(); + _S[0] = (const uchar*)(src.data + src.step*sy0) + xofs[dx]; + _S[1] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+1]; + _S[2] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+2]; + _S[3] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+3]; + + _S[4] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+4]; + _S[5] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+5]; + _S[6] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+6]; + _S[7] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+7]; + + for( k = 0; k < area; k++ ) + { + int ofsk = ofs[k]; + __m128i _temp = _mm_set_epi32(_S[3][ofsk],_S[2][ofsk],_S[1][ofsk],_S[0][ofsk]); + _sum = _mm_add_epi32(_sum, _temp); + + __m128i _temp1 = _mm_set_epi32(_S[7][ofsk],_S[6][ofsk],_S[5][ofsk],_S[4][ofsk]); + _sum1 = _mm_add_epi32(_sum1, _temp1); + } + + __m128i _tempSum = _mm_cvtps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(_sum), _scale)); + __m128i _tempSum1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(_sum1), _scale)); + + _tempSum = _mm_packs_epi32(_tempSum, _tempSum1); + _tempSum = _mm_min_epi16(_ucMAXs, _tempSum); + _tempSum = _mm_packus_epi16(_tempSum, _tempSum); + _mm_storel_epi64((__m128i*)(D+dx),_tempSum); + } + } + #endif + + for(; dx < w; dx++ ) + { + const uchar* S = (const uchar*)(src.data + src.step*sy0) + xofs[dx]; + int sum = 0; + k=0; + + #if CV_ENABLE_UNROLLED + for( ; k <= area - 4; k += 4 ) + sum += S[ofs[k]] + S[ofs[k+1]] + S[ofs[k+2]] + S[ofs[k+3]]; + #endif + + for( ; k < area; k++ ) + sum += S[ofs[k]]; + + + D[dx] = saturate_cast(sum*scale); + } + + for( ; dx < dsize.width; dx++ ) + { + int sum = 0; + int count = 0, sx0 = xofs[dx]; + if( sx0 >= ssize.width ) + D[dx] = 0; + + for( int sy = 0; sy < scale_y; sy++ ) + { + if( sy0 + sy >= ssize.height ) + break; + const uchar* S = (const uchar*)(src.data + src.step*(sy0 + sy)) + sx0; + int sx = 0; + for( ; sx < scale_x*cn; sx += cn ) + { + if( sx0 + sx >= ssize.width ) + break; + sum += S[sx]; + count++; + } + } + + D[dx] = saturate_cast((float)sum/count); + } + } +} typedef void (*ResizeFunc)( const Mat& src, Mat& dst, From 793e8b546d060a6ad032a794afd4cbd351ed87ed Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 21 Aug 2012 23:11:49 +0400 Subject: [PATCH 35/40] fixed build on Ubuntu --- modules/imgproc/src/imgwarp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index b09588879..e5a47e1a2 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -1330,9 +1330,9 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in } -template <> static void -resizeAreaFast_( const Mat& src, Mat& dst, const int* ofs, const int* xofs, - int scale_x, int scale_y ) +static void resizeAreaFast_8u( const Mat& src, Mat& dst, + const int* ofs, const int* xofs, + int scale_x, int scale_y ) { #if CV_SSE2 bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2); @@ -1553,7 +1553,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, static ResizeAreaFastFunc areafast_tab[] = { - resizeAreaFast_, 0, + resizeAreaFast_8u, 0, resizeAreaFast_, resizeAreaFast_, 0, From f2a02feffa582a850800174e9a520e2a4d730777 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 22 Aug 2012 03:59:05 +0400 Subject: [PATCH 36/40] Fix Windows build issues * No /arch:SSE3 in MSVC * Warnings fixed or suppressed --- 3rdparty/libtiff/CMakeLists.txt | 2 +- CMakeLists.txt | 8 ++--- modules/features2d/src/features2d_init.cpp | 2 +- modules/features2d/test/test_fast.cpp | 4 +-- .../features2d/test/test_nearestneighbors.cpp | 6 ++-- .../test_rotation_and_scale_invariance.cpp | 30 +++++++++---------- modules/gpu/perf/perf_imgproc.cpp | 18 +++++------ modules/gpu/perf/perf_labeling.cpp | 9 ++++-- modules/gpu/perf/perf_video.cpp | 2 +- samples/cpp/bagofwords_classification.cpp | 1 + samples/gpu/bgfg_segm.cpp | 6 ++-- samples/gpu/performance/tests.cpp | 4 +-- 12 files changed, 49 insertions(+), 43 deletions(-) diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index ed9d1c86b..6dd7956f5 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -89,7 +89,7 @@ endif(WIN32) ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast) -ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter /wd4100 /wd4244 /wd4706 /wd4127 /wd4701 /wd4018 /wd4267 /wd4306 /wd4305 /wd4312 /wd4311) +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter /wd4100 /wd4244 /wd4706 /wd4127 /wd4701 /wd4018 /wd4267 /wd4306 /wd4305 /wd4312 /wd4311 /wd4703) if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") diff --git a/CMakeLists.txt b/CMakeLists.txt index c81cbd9de..d893f1c74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,11 +189,11 @@ OCV_OPTION(ENABLE_PROFILING "Enable profiling in the GCC compiler (Add OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC" ON IF CMAKE_COMPILER_IS_GNUCXX ) OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) ) OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) -OCV_OPTION(ENABLE_SSE "Enable SSE instructions" ON IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) -OCV_OPTION(ENABLE_SSE2 "Enable SSE2 instructions" ON IF (MSVC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) -OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" ON IF (MSVC OR CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_SSE "Enable SSE instructions" ON IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_SSE2 "Enable SSE2 instructions" ON IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_SSE3 "Enable SSE3 instructions" ON IF ((CV_ICC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) -OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF (CV_ICC OR CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF ((CV_ICC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF ) OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF ) diff --git a/modules/features2d/src/features2d_init.cpp b/modules/features2d/src/features2d_init.cpp index e21b8d802..c9abfefa9 100644 --- a/modules/features2d/src/features2d_init.cpp +++ b/modules/features2d/src/features2d_init.cpp @@ -59,7 +59,7 @@ CV_INIT_ALGORITHM(BriefDescriptorExtractor, "Feature2D.BRIEF", CV_INIT_ALGORITHM(FastFeatureDetector, "Feature2D.FAST", obj.info()->addParam(obj, "threshold", obj.threshold); obj.info()->addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); - obj.info()->addParam(obj, "type", obj.type, static_cast(FastFeatureDetector::TYPE_9_16))); + obj.info()->addParam(obj, "type", obj.type)); /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/modules/features2d/test/test_fast.cpp b/modules/features2d/test/test_fast.cpp index 671e66d5f..761abfcca 100644 --- a/modules/features2d/test/test_fast.cpp +++ b/modules/features2d/test/test_fast.cpp @@ -75,8 +75,8 @@ void CV_FastTest::run( int ) vector keypoints1; vector keypoints2; - FAST(gray1, keypoints1, 30, type); - FAST(gray2, keypoints2, 30, type); + FAST(gray1, keypoints1, 30, true, type); + FAST(gray2, keypoints2, 30, true, type); for(size_t i = 0; i < keypoints1.size(); ++i) { diff --git a/modules/features2d/test/test_nearestneighbors.cpp b/modules/features2d/test/test_nearestneighbors.cpp index 8a0482218..45131eff2 100644 --- a/modules/features2d/test/test_nearestneighbors.cpp +++ b/modules/features2d/test/test_nearestneighbors.cpp @@ -200,7 +200,7 @@ int CV_KDTreeTest_CPP::checkGetPoins( const Mat& data ) int CV_KDTreeTest_CPP::checkFindBoxed() { - vector min( dims, minValue), max(dims, maxValue); + vector min( dims, static_cast(minValue)), max(dims, static_cast(maxValue)); vector indices; tr->findOrthoRange( min, max, indices ); // TODO check indices @@ -214,8 +214,8 @@ int CV_KDTreeTest_CPP::findNeighbors( Mat& points, Mat& neighbors ) const int emax = 20; Mat neighbors2( neighbors.size(), CV_32SC1 ); int j; - vector min(points.cols, minValue); - vector max(points.cols, maxValue); + vector min(points.cols, static_cast(minValue)); + vector max(points.cols, static_cast(maxValue)); for( int pi = 0; pi < points.rows; pi++ ) { // 1st way diff --git a/modules/features2d/test/test_rotation_and_scale_invariance.cpp b/modules/features2d/test/test_rotation_and_scale_invariance.cpp index d98431ba5..48dddd3ee 100644 --- a/modules/features2d/test/test_rotation_and_scale_invariance.cpp +++ b/modules/features2d/test/test_rotation_and_scale_invariance.cpp @@ -54,7 +54,7 @@ static Mat generateHomography(float angle) { // angle - rotation around Oz in degrees - float angleRadian = angle * CV_PI / 180.; + float angleRadian = static_cast(angle * CV_PI / 180); Mat H = Mat::eye(3, 3, CV_32FC1); H.at(0,0) = H.at(1,1) = std::cos(angleRadian); H.at(0,1) = -std::sin(angleRadian); @@ -69,8 +69,8 @@ Mat rotateImage(const Mat& srcImage, float angle, Mat& dstImage, Mat& dstMask) // angle - rotation around Oz in degrees float diag = std::sqrt(static_cast(srcImage.cols * srcImage.cols + srcImage.rows * srcImage.rows)); Mat LUShift = Mat::eye(3, 3, CV_32FC1); // left up - LUShift.at(0,2) = -srcImage.cols/2; - LUShift.at(1,2) = -srcImage.rows/2; + LUShift.at(0,2) = static_cast(-srcImage.cols/2); + LUShift.at(1,2) = static_cast(-srcImage.rows/2); Mat RDShift = Mat::eye(3, 3, CV_32FC1); // right down RDShift.at(0,2) = diag/2; RDShift.at(1,2) = diag/2; @@ -114,7 +114,7 @@ void scaleKeyPoints(const vector& src, vector& dst, float sc static float calcCirclesIntersectArea(const Point2f& p0, float r0, const Point2f& p1, float r1) { - float c = norm(p0 - p1), sqr_c = c * c; + float c = static_cast(norm(p0 - p1)), sqr_c = c * c; float sqr_r0 = r0 * r0; float sqr_r1 = r1 * r1; @@ -125,7 +125,7 @@ float calcCirclesIntersectArea(const Point2f& p0, float r0, const Point2f& p1, f float minR = std::min(r0, r1); float maxR = std::max(r0, r1); if(c + minR <= maxR) - return CV_PI * minR * minR; + return static_cast(CV_PI * minR * minR); float cos_halfA0 = (sqr_r0 + sqr_c - sqr_r1) / (2 * r0 * c); float cos_halfA1 = (sqr_r1 + sqr_c - sqr_r0) / (2 * r1 * c); @@ -133,15 +133,15 @@ float calcCirclesIntersectArea(const Point2f& p0, float r0, const Point2f& p1, f float A0 = 2 * acos(cos_halfA0); float A1 = 2 * acos(cos_halfA1); - return 0.5 * sqr_r0 * (A0 - sin(A0)) + - 0.5 * sqr_r1 * (A1 - sin(A1)); + return 0.5f * sqr_r0 * (A0 - sin(A0)) + + 0.5f * sqr_r1 * (A1 - sin(A1)); } static float calcIntersectRatio(const Point2f& p0, float r0, const Point2f& p1, float r1) { float intersectArea = calcCirclesIntersectArea(p0, r0, p1, r1); - float unionArea = CV_PI * (r0 * r0 + r1 * r1) - intersectArea; + float unionArea = static_cast(CV_PI) * (r0 * r0 + r1 * r1) - intersectArea; return intersectArea / unionArea; } @@ -160,7 +160,7 @@ void matchKeyPoints(const vector& keypoints0, const Mat& H, matches.clear(); vector usedMask(keypoints1.size(), 0); - for(size_t i0 = 0; i0 < keypoints0.size(); i0++) + for(int i0 = 0; i0 < static_cast(keypoints0.size()); i0++) { int nearestPointIndex = -1; float maxIntersectRatio = 0.f; @@ -176,7 +176,7 @@ void matchKeyPoints(const vector& keypoints0, const Mat& H, if(intersectRatio > maxIntersectRatio) { maxIntersectRatio = intersectRatio; - nearestPointIndex = i1; + nearestPointIndex = static_cast(i1); } } @@ -222,7 +222,7 @@ protected: const int maxAngle = 360, angleStep = 15; for(int angle = 0; angle < maxAngle; angle += angleStep) { - Mat H = rotateImage(image0, angle, image1, mask1); + Mat H = rotateImage(image0, static_cast(angle), image1, mask1); vector keypoints1; featureDetector->detect(image1, keypoints1, mask1); @@ -339,10 +339,10 @@ protected: const int maxAngle = 360, angleStep = 15; for(int angle = 0; angle < maxAngle; angle += angleStep) { - Mat H = rotateImage(image0, angle, image1, mask1); + Mat H = rotateImage(image0, static_cast(angle), image1, mask1); vector keypoints1; - rotateKeyPoints(keypoints0, H, angle, keypoints1); + rotateKeyPoints(keypoints0, H, static_cast(angle), keypoints1); Mat descriptors1; descriptorExtractor->compute(image1, keypoints1, descriptors1); @@ -457,7 +457,7 @@ protected: keyPointMatchesCount++; // Check does this inlier have consistent sizes - const float maxSizeDiff = 0.8;//0.9f; // grad + const float maxSizeDiff = 0.8f;//0.9f; // grad float size0 = keypoints0[matches[m].trainIdx].size; float size1 = osiKeypoints1[matches[m].queryIdx].size; CV_Assert(size0 > 0 && size1 > 0); @@ -545,7 +545,7 @@ protected: resize(image0, image1, Size(), 1./scale, 1./scale); vector keypoints1; - scaleKeyPoints(keypoints0, keypoints1, 1./scale); + scaleKeyPoints(keypoints0, keypoints1, 1.0f/scale); Mat descriptors1; descriptorExtractor->compute(image1, keypoints1, descriptors1); diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 979aaa372..f938ca239 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -23,8 +23,8 @@ void generateMap(cv::Mat& map_x, cv::Mat& map_y, int 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 * (i - map_x.cols * 0.25) + 0.5; - map_y.at(j,i) = 2 * (j - map_x.rows * 0.25) + 0.5; + map_x.at(j,i) = 2 * (i - map_x.cols * 0.25f) + 0.5f; + map_y.at(j,i) = 2 * (j - map_x.rows * 0.25f) + 0.5f; } else { @@ -33,16 +33,16 @@ void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode) } break; case UPSIDE_DOWN: - map_x.at(j,i) = i; - map_y.at(j,i) = map_x.rows - j; + 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) = map_x.cols - i; - map_y.at(j,i) = j; + 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) = map_x.cols - i; - map_y.at(j,i) = map_x.rows - j; + 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 } @@ -1619,7 +1619,7 @@ PERF_TEST_P(Sz_DoSort, ImgProc_HoughLines, Combine(GPU_TYPICAL_MAT_SIZES, Bool() const bool doSort = GET_PARAM(1); const float rho = 1.0f; - const float theta = CV_PI / 180.0f; + const float theta = static_cast(CV_PI / 180.0); const int threshold = 300; cv::RNG rng(123456789); diff --git a/modules/gpu/perf/perf_labeling.cpp b/modules/gpu/perf/perf_labeling.cpp index f17dd7d0a..bbab5ecfa 100644 --- a/modules/gpu/perf/perf_labeling.cpp +++ b/modules/gpu/perf/perf_labeling.cpp @@ -31,6 +31,11 @@ struct GreedyLabeling int d = a - b; return lo <= d && d <= hi; } + + private: + InInterval& operator=(const InInterval&); + + }; GreedyLabeling(cv::Mat img) @@ -45,7 +50,7 @@ struct GreedyLabeling int cc = -1; int* dist_labels = (int*)labels.data; - int pitch = labels.step1(); + int pitch = static_cast(labels.step1()); unsigned char* source = (unsigned char*)image.data; int width = image.cols; @@ -82,7 +87,7 @@ struct GreedyLabeling *top++ = dot::make(p.x, p.y + 1); //top - if( p.y > 0 && dl[-pitch] == -1 && inInt(sp[0], sp[-image.step1()])) + if( p.y > 0 && dl[-pitch] == -1 && inInt(sp[0], sp[-static_cast(image.step1())])) *top++ = dot::make(p.x, p.y - 1); p = *--top; diff --git a/modules/gpu/perf/perf_video.cpp b/modules/gpu/perf/perf_video.cpp index 7faea0b88..8346d25f4 100644 --- a/modules/gpu/perf/perf_video.cpp +++ b/modules/gpu/perf/perf_video.cpp @@ -427,7 +427,7 @@ PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576. { string inputFile = perf::TestBase::getDataPath(GET_PARAM(0)); int cn = GET_PARAM(1); - double learningRate = GET_PARAM(2); + float learningRate = static_cast(GET_PARAM(2)); cv::VideoCapture cap(inputFile); ASSERT_TRUE(cap.isOpened()); diff --git a/samples/cpp/bagofwords_classification.cpp b/samples/cpp/bagofwords_classification.cpp index 559e77bfc..071c2a173 100644 --- a/samples/cpp/bagofwords_classification.cpp +++ b/samples/cpp/bagofwords_classification.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #if defined WIN32 || defined _WIN32 #define WIN32_LEAN_AND_MEAN diff --git a/samples/gpu/bgfg_segm.cpp b/samples/gpu/bgfg_segm.cpp index 7c5e148f7..4e4c52096 100644 --- a/samples/gpu/bgfg_segm.cpp +++ b/samples/gpu/bgfg_segm.cpp @@ -86,7 +86,7 @@ int main(int argc, const char** argv) break; case MOG: - mog(d_frame, d_fgmask, 0.01); + mog(d_frame, d_fgmask, 0.01f); break; case MOG2: @@ -127,7 +127,7 @@ int main(int argc, const char** argv) break; case MOG: - mog(d_frame, d_fgmask, 0.01); + mog(d_frame, d_fgmask, 0.01f); mog.getBackgroundImage(d_bgimg); break; @@ -162,7 +162,7 @@ int main(int argc, const char** argv) if (!bgimg.empty()) imshow("mean background image", bgimg); - char key = waitKey(30); + int key = waitKey(30); if (key == 27) break; } diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index aefd9572f..e11720283 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -1341,7 +1341,7 @@ TEST(MOG) cv::gpu::MOG_GPU d_mog; cv::gpu::GpuMat d_foreground; - d_mog(d_frame, d_foreground, 0.01); + d_mog(d_frame, d_foreground, 0.01f); while (!TestSystem::instance().stop()) { @@ -1350,7 +1350,7 @@ TEST(MOG) TestSystem::instance().gpuOn(); - d_mog(d_frame, d_foreground, 0.01); + d_mog(d_frame, d_foreground, 0.01f); TestSystem::instance().gpuOff(); } From 92795ba4769e77a9833a06fcd67c444f3c9c2122 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 22 Aug 2012 11:49:21 +0400 Subject: [PATCH 37/40] parallel version of remap, resize, warpaffine, warpPerspective. Some optimization for 2x decimation in resize algorithm --- modules/imgproc/perf/perf_remap.cpp | 68 + modules/imgproc/perf/perf_resize.cpp | 32 +- modules/imgproc/src/imgwarp.cpp | 1873 +++++++++++++++----------- 3 files changed, 1192 insertions(+), 781 deletions(-) create mode 100644 modules/imgproc/perf/perf_remap.cpp diff --git a/modules/imgproc/perf/perf_remap.cpp b/modules/imgproc/perf/perf_remap.cpp new file mode 100644 index 000000000..e78929673 --- /dev/null +++ b/modules/imgproc/perf/perf_remap.cpp @@ -0,0 +1,68 @@ +#include "perf_precomp.hpp" + +using namespace std; +using namespace cv; +using namespace perf; +using namespace testing; +using std::tr1::make_tuple; +using std::tr1::get; + +CV_ENUM(MatrixType, CV_16UC1, CV_16SC1, CV_32FC1) +CV_ENUM(MapType, CV_16SC2, CV_32FC1, CV_32FC2) +CV_ENUM(InterType, INTER_LINEAR, INTER_CUBIC, INTER_LANCZOS4, INTER_NEAREST) + +typedef TestBaseWithParam< tr1::tuple > TestRemap; + +PERF_TEST_P( TestRemap, Remap, + Combine( + Values( szVGA, sz1080p ), + ValuesIn( MatrixType::all() ), + ValuesIn( MapType::all() ), + ValuesIn( InterType::all() ) + ) +) +{ + Size sz; + int src_type, map1_type, inter_type; + + sz = get<0>(GetParam()); + src_type = get<1>(GetParam()); + map1_type = get<2>(GetParam()); + inter_type = get<3>(GetParam()); + + Mat src(sz, src_type); + Mat map1(sz, map1_type); + Mat dst(sz, src_type); + + Mat map2(map1_type == CV_32FC1 ? sz : Size(), CV_32FC1); + + RNG rng; + rng.fill(src, RNG::UNIFORM, 0, 256); + + for (int j = 0; j < map1.rows; ++j) + for (int i = 0; i < map1.cols; ++i) + switch (map1_type) + { + case CV_32FC1: + map1.at(j, i) = src.cols - i; + map2.at(j, i) = j; + break; + case CV_32FC2: + map1.at(j, i)[0] = src.cols - i; + map1.at(j, i)[1] = j; + break; + case CV_16SC2: + map1.at(j, i)[0] = src.cols - i; + map1.at(j, i)[1] = j; + break; + default: + CV_Assert(0); + } + + + declare.in(src, WARMUP_RNG).out(dst).time(20); + + TEST_CYCLE() remap(src, dst, map1, map2, inter_type); + + SANITY_CHECK(dst); +} diff --git a/modules/imgproc/perf/perf_resize.cpp b/modules/imgproc/perf/perf_resize.cpp index fba12942f..15be0eae1 100644 --- a/modules/imgproc/perf/perf_resize.cpp +++ b/modules/imgproc/perf/perf_resize.cpp @@ -59,11 +59,11 @@ PERF_TEST_P(MatInfo_Size_Size, resizeDownLinear, typedef tr1::tuple MatInfo_Size_Scale_t; typedef TestBaseWithParam MatInfo_Size_Scale; -PERF_TEST_P(MatInfo_Size_Scale, resizeAreaFast, +PERF_TEST_P(MatInfo_Size_Scale, ResizeAreaFast, testing::Combine( testing::Values(CV_8UC1, CV_8UC4), testing::Values(szVGA, szqHD, sz720p, sz1080p), - testing::Values(2, 4) + testing::Values(2) ) ) { @@ -84,3 +84,31 @@ PERF_TEST_P(MatInfo_Size_Scale, resizeAreaFast, //difference equal to 1 is allowed because of different possible rounding modes: round-to-nearest vs bankers' rounding SANITY_CHECK(dst, 1); } + + +typedef TestBaseWithParam > MatInfo_Size_Scale_Area; + +PERF_TEST_P(MatInfo_Size_Scale_Area, ResizeArea, + testing::Combine( + testing::Values(CV_8UC1, CV_8UC4), + testing::Values(szVGA, szqHD, sz720p, sz1080p), + testing::Values(2.4, 3.4, 1.3) + ) + ) +{ + int matType = get<0>(GetParam()); + Size from = get<1>(GetParam()); + double scale = get<2>(GetParam()); + + cv::Mat src(from, matType); + + Size to(cvRound(from.width * scale), cvRound(from.height * scale)); + cv::Mat dst(to, matType); + + declare.in(src, WARMUP_RNG).out(dst); + + TEST_CYCLE() resize(src, dst, dst.size(), 0, 0, INTER_AREA); + + //difference equal to 1 is allowed because of different possible rounding modes: round-to-nearest vs bankers' rounding + SANITY_CHECK(dst, 1); +} diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index e5a47e1a2..1e45fadf2 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -240,6 +240,99 @@ template struct FixedPtCast * Resize * \****************************************************************************************/ +class resizeNNInvoker : + public ParallelLoopBody +{ +public: + resizeNNInvoker(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) : + ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4), + ify(_ify) + { + } + + virtual void operator() (const Range& range) const + { + Size ssize = src.size(), dsize = dst.size(); + int y, x, pix_size = (int)src.elemSize(); + + for( y = range.start; y < range.end; y++ ) + { + uchar* D = dst.data + dst.step*y; + int sy = std::min(cvFloor(y*ify), ssize.height-1); + const uchar* S = src.data + src.step*sy; + + switch( pix_size ) + { + case 1: + for( x = 0; x <= dsize.width - 2; x += 2 ) + { + uchar t0 = S[x_ofs[x]]; + uchar t1 = S[x_ofs[x+1]]; + D[x] = t0; + D[x+1] = t1; + } + + for( ; x < dsize.width; x++ ) + D[x] = S[x_ofs[x]]; + break; + case 2: + for( x = 0; x < dsize.width; x++ ) + *(ushort*)(D + x*2) = *(ushort*)(S + x_ofs[x]); + break; + case 3: + for( x = 0; x < dsize.width; x++, D += 3 ) + { + const uchar* _tS = S + x_ofs[x]; + D[0] = _tS[0]; D[1] = _tS[1]; D[2] = _tS[2]; + } + break; + case 4: + for( x = 0; x < dsize.width; x++ ) + *(int*)(D + x*4) = *(int*)(S + x_ofs[x]); + break; + case 6: + for( x = 0; x < dsize.width; x++, D += 6 ) + { + const ushort* _tS = (const ushort*)(S + x_ofs[x]); + ushort* _tD = (ushort*)D; + _tD[0] = _tS[0]; _tD[1] = _tS[1]; _tD[2] = _tS[2]; + } + break; + case 8: + for( x = 0; x < dsize.width; x++, D += 8 ) + { + const int* _tS = (const int*)(S + x_ofs[x]); + int* _tD = (int*)D; + _tD[0] = _tS[0]; _tD[1] = _tS[1]; + } + break; + case 12: + for( x = 0; x < dsize.width; x++, D += 12 ) + { + const int* _tS = (const int*)(S + x_ofs[x]); + int* _tD = (int*)D; + _tD[0] = _tS[0]; _tD[1] = _tS[1]; _tD[2] = _tS[2]; + } + break; + default: + for( x = 0; x < dsize.width; x++, D += pix_size ) + { + const int* _tS = (const int*)(S + x_ofs[x]); + int* _tD = (int*)D; + for( int k = 0; k < pix_size4; k++ ) + _tD[k] = _tS[k]; + } + } + } + } + +private: + const Mat src; + Mat dst; + int* x_ofs, pix_size4; + double ify; +}; + static void resizeNN( const Mat& src, Mat& dst, double fx, double fy ) { @@ -249,83 +342,17 @@ resizeNN( const Mat& src, Mat& dst, double fx, double fy ) int pix_size = (int)src.elemSize(); int pix_size4 = (int)(pix_size / sizeof(int)); double ifx = 1./fx, ify = 1./fy; - int x, y; + int x; for( x = 0; x < dsize.width; x++ ) { int sx = cvFloor(x*ifx); x_ofs[x] = std::min(sx, ssize.width-1)*pix_size; } - - for( y = 0; y < dsize.height; y++ ) - { - uchar* D = dst.data + dst.step*y; - int sy = std::min(cvFloor(y*ify), ssize.height-1); - const uchar* S = src.data + src.step*sy; - - switch( pix_size ) - { - case 1: - for( x = 0; x <= dsize.width - 2; x += 2 ) - { - uchar t0 = S[x_ofs[x]]; - uchar t1 = S[x_ofs[x+1]]; - D[x] = t0; - D[x+1] = t1; - } - - for( ; x < dsize.width; x++ ) - D[x] = S[x_ofs[x]]; - break; - case 2: - for( x = 0; x < dsize.width; x++ ) - *(ushort*)(D + x*2) = *(ushort*)(S + x_ofs[x]); - break; - case 3: - for( x = 0; x < dsize.width; x++, D += 3 ) - { - const uchar* _tS = S + x_ofs[x]; - D[0] = _tS[0]; D[1] = _tS[1]; D[2] = _tS[2]; - } - break; - case 4: - for( x = 0; x < dsize.width; x++ ) - *(int*)(D + x*4) = *(int*)(S + x_ofs[x]); - break; - case 6: - for( x = 0; x < dsize.width; x++, D += 6 ) - { - const ushort* _tS = (const ushort*)(S + x_ofs[x]); - ushort* _tD = (ushort*)D; - _tD[0] = _tS[0]; _tD[1] = _tS[1]; _tD[2] = _tS[2]; - } - break; - case 8: - for( x = 0; x < dsize.width; x++, D += 8 ) - { - const int* _tS = (const int*)(S + x_ofs[x]); - int* _tD = (int*)D; - _tD[0] = _tS[0]; _tD[1] = _tS[1]; - } - break; - case 12: - for( x = 0; x < dsize.width; x++, D += 12 ) - { - const int* _tS = (const int*)(S + x_ofs[x]); - int* _tD = (int*)D; - _tD[0] = _tS[0]; _tD[1] = _tS[1]; _tD[2] = _tS[2]; - } - break; - default: - for( x = 0; x < dsize.width; x++, D += pix_size ) - { - const int* _tS = (const int*)(S + x_ofs[x]); - int* _tD = (int*)D; - for( int k = 0; k < pix_size4; k++ ) - _tD[k] = _tS[k]; - } - } - } + + Range range(0, dsize.height); + resizeNNInvoker invoker(src, dst, x_ofs, pix_size4, ify); + parallel_for_(range, invoker); } @@ -1092,6 +1119,82 @@ static inline int clip(int x, int a, int b) static const int MAX_ESIZE=16; +template +class resizeGeneric_Invoker : + public ParallelLoopBody +{ +public: + typedef typename HResize::value_type T; + typedef typename HResize::buf_type WT; + typedef typename HResize::alpha_type AT; + + resizeGeneric_Invoker(const Mat& _src, Mat &_dst, const int *_xofs, const int *_yofs, + const AT* _alpha, const AT* __beta, const Size& _ssize, const Size &_dsize, + int _ksize, int _xmin, int _xmax) : + ParallelLoopBody(), src(_src), dst(_dst), xofs(_xofs), yofs(_yofs), + alpha(_alpha), _beta(__beta), ssize(_ssize), dsize(_dsize), + ksize(_ksize), xmin(_xmin), xmax(_xmax) + { + } + + virtual void operator() (const Range& range) const + { + int dy, cn = src.channels(); + HResize hresize; + VResize vresize; + + int bufstep = (int)alignSize(dsize.width, 16); + AutoBuffer _buffer(bufstep*ksize); + const T* srows[MAX_ESIZE]={0}; + WT* rows[MAX_ESIZE]={0}; + int prev_sy[MAX_ESIZE]; + + for(int k = 0; k < ksize; k++ ) + { + prev_sy[k] = -1; + rows[k] = (WT*)_buffer + bufstep*k; + } + + const AT* beta = _beta + ksize * range.start; + + for( dy = range.start; dy < range.end; dy++, beta += ksize ) + { + int sy0 = yofs[dy], k0=ksize, k1=0, ksize2 = ksize/2; + + for(int k = 0; k < ksize; k++ ) + { + int sy = clip(sy0 - ksize2 + 1 + k, 0, ssize.height); + for( k1 = std::max(k1, k); k1 < ksize; k1++ ) + { + if( sy == prev_sy[k1] ) // if the sy-th row has been computed already, reuse it. + { + if( k1 > k ) + memcpy( rows[k], rows[k1], bufstep*sizeof(rows[0][0]) ); + break; + } + } + if( k1 == ksize ) + k0 = std::min(k0, k); // remember the first row that needs to be computed + srows[k] = (T*)(src.data + src.step*sy); + prev_sy[k] = sy; + } + + if( k0 < ksize ) + hresize( (const T**)(srows + k0), (WT**)(rows + k0), ksize - k0, xofs, (const AT*)(alpha), + ssize.width, dsize.width, cn, xmin, xmax ); + vresize( (const WT**)rows, (T*)(dst.data + dst.step*dy), beta, dsize.width ); + } + } + +private: + const Mat src; + Mat dst; + const int* xofs, *yofs; + const AT* alpha, *_beta; + const Size ssize, dsize; + const int ksize, xmin, xmax; +}; + template static void resizeGeneric_( const Mat& src, Mat& dst, const int* xofs, const void* _alpha, @@ -1102,124 +1205,178 @@ static void resizeGeneric_( const Mat& src, Mat& dst, typedef typename HResize::buf_type WT; typedef typename HResize::alpha_type AT; - const AT* alpha = (const AT*)_alpha; const AT* beta = (const AT*)_beta; Size ssize = src.size(), dsize = dst.size(); int cn = src.channels(); ssize.width *= cn; dsize.width *= cn; - int bufstep = (int)alignSize(dsize.width, 16); - AutoBuffer _buffer(bufstep*ksize); - const T* srows[MAX_ESIZE]={0}; - WT* rows[MAX_ESIZE]={0}; - int prev_sy[MAX_ESIZE]; - int dy; xmin *= cn; xmax *= cn; - - HResize hresize; - VResize vresize; - - for(int k = 0; k < ksize; k++ ) - { - prev_sy[k] = -1; - rows[k] = (WT*)_buffer + bufstep*k; - } - // image resize is a separable operation. In case of not too strong - for( dy = 0; dy < dsize.height; dy++, beta += ksize ) - { - int sy0 = yofs[dy], k0=ksize, k1=0, ksize2 = ksize/2; - - for(int k = 0; k < ksize; k++ ) - { - int sy = clip(sy0 - ksize2 + 1 + k, 0, ssize.height); - for( k1 = std::max(k1, k); k1 < ksize; k1++ ) - { - if( sy == prev_sy[k1] ) // if the sy-th row has been computed already, reuse it. - { - if( k1 > k ) - memcpy( rows[k], rows[k1], bufstep*sizeof(rows[0][0]) ); - break; - } - } - if( k1 == ksize ) - k0 = std::min(k0, k); // remember the first row that needs to be computed - srows[k] = (const T*)(src.data + src.step*sy); - prev_sy[k] = sy; - } - - if( k0 < ksize ) - hresize( srows + k0, rows + k0, ksize - k0, xofs, alpha, - ssize.width, dsize.width, cn, xmin, xmax ); - vresize( (const WT**)rows, (T*)(dst.data + dst.step*dy), beta, dsize.width ); - } + + Range range(0, dsize.height); + resizeGeneric_Invoker invoker(src, dst, xofs, yofs, (const AT*)_alpha, beta, + ssize, dsize, ksize, xmin, xmax); + parallel_for_(range, invoker); } +template +struct ResizeAreaFastNoVec +{ + ResizeAreaFastNoVec(int /*_scale_x*/, int /*_scale_y*/, + int /*_cn*/, int /*_step*//*, const int**/ /*_ofs*/) { } + int operator() (const T* /*S*/, T* /*D*/, int /*w*/) const { return 0; } +}; -template +template +struct ResizeAreaFast_2x2_8u +{ + ResizeAreaFast_2x2_8u(int _scale_x, int _scale_y, int _cn, int _step/*, const int* _ofs*/) : + scale_x(_scale_x), scale_y(_scale_y), cn(_cn), step(_step)/*, ofs(_ofs)*/ + { + fast_mode = scale_x == 2 && scale_y == 2 && (cn == 1 || cn == 3 || cn == 4); + } + + int operator() (const T* S, T* D, int w) const + { + if( !fast_mode ) + return 0; + + const T* nextS = S + step; + int dx = 0; + + if (cn == 1) + for( ; dx < w; ++dx ) + { + int index = dx*2; + D[dx] = (S[index] + S[index+1] + nextS[index] + nextS[index+1] + 2) >> 2; + } + else if (cn == 3) + for( ; dx < w; dx += 3 ) + { + int index = dx*2; + D[dx] = (S[index] + S[index+3] + nextS[index] + nextS[index+3] + 2) >> 2; + D[dx+1] = (S[index+1] + S[index+4] + nextS[index+1] + nextS[index+4] + 2) >> 2; + D[dx+2] = (S[index+2] + S[index+5] + nextS[index+2] + nextS[index+5] + 2) >> 2; + } + else + { + assert(cn == 4); + for( ; dx < w; dx += 4 ) + { + int index = dx*2; + D[dx] = (S[index] + S[index+3] + nextS[index] + nextS[index+3] + 2) >> 2; + D[dx+1] = (S[index+1] + S[index+4] + nextS[index+1] + nextS[index+4] + 2) >> 2; + D[dx+2] = (S[index+2] + S[index+5] + nextS[index+2] + nextS[index+5] + 2) >> 2; + D[dx+3] = (S[index+3] + S[index+6] + nextS[index+3] + nextS[index+6] + 2) >> 2; + } + } + + return dx; + } + +private: + const int scale_x, scale_y; + const int cn; + bool fast_mode; + const int step; +}; + +template +class resizeAreaFast_Invoker : + public ParallelLoopBody +{ +public: + resizeAreaFast_Invoker(const Mat &_src, Mat &_dst, + int _scale_x, int _scale_y, const int* _ofs, const int* _xofs) : + ParallelLoopBody(), src(_src), dst(_dst), scale_x(_scale_x), + scale_y(_scale_y), ofs(_ofs), xofs(_xofs) + { + } + + virtual void operator() (const Range& range) const + { + Size ssize = src.size(), dsize = dst.size(); + int cn = src.channels(); + int area = scale_x*scale_y; + float scale = 1.f/(area); + int dwidth1 = (ssize.width/scale_x)*cn; + dsize.width *= cn; + ssize.width *= cn; + int dy, dx, k = 0; + + VecOp vop(scale_x, scale_y, src.channels(), src.step/*, area_ofs*/); + + for( dy = range.start; dy < range.end; dy++ ) + { + T* D = (T*)(dst.data + dst.step*dy); + int sy0 = dy*scale_y; + int w = sy0 + scale_y <= ssize.height ? dwidth1 : 0; + + if( sy0 >= ssize.height ) + { + for( dx = 0; dx < dsize.width; dx++ ) + D[dx] = 0; + continue; + } + + dx = vop((const T*)(src.data + src.step * sy0), D, w); + for( ; dx < w; dx++ ) + { + const T* S = (const T*)(src.data + src.step * sy0) + xofs[dx]; + WT sum = 0; + k = 0; + #if CV_ENABLE_UNROLLED + for( ; k <= area - 4; k += 4 ) + sum += S[ofs[k]] + S[ofs[k+1]] + S[ofs[k+2]] + S[ofs[k+3]]; + #endif + for( ; k < area; k++ ) + sum += S[ofs[k]]; + + D[dx] = saturate_cast(sum * scale); + } + + for( ; dx < dsize.width; dx++ ) + { + WT sum = 0; + int count = 0, sx0 = xofs[dx]; + if( sx0 >= ssize.width ) + D[dx] = 0; + + for( int sy = 0; sy < scale_y; sy++ ) + { + if( sy0 + sy >= ssize.height ) + break; + const T* S = (const T*)(src.data + src.step*(sy0 + sy)) + sx0; + for( int sx = 0; sx < scale_x*cn; sx += cn ) + { + if( sx0 + sx >= ssize.width ) + break; + sum += S[sx]; + count++; + } + } + + D[dx] = saturate_cast((float)sum/count); + } + } + } + +private: + const Mat src; + Mat dst; + const int scale_x, scale_y; + const int *ofs, *xofs; +}; + +template static void resizeAreaFast_( const Mat& src, Mat& dst, const int* ofs, const int* xofs, int scale_x, int scale_y ) { - Size ssize = src.size(), dsize = dst.size(); - int cn = src.channels(); - int dy, dx, k = 0; - int area = scale_x*scale_y; - float scale = 1.f/(scale_x*scale_y); - int dwidth1 = (ssize.width/scale_x)*cn; - dsize.width *= cn; - ssize.width *= cn; - - for( dy = 0; dy < dsize.height; dy++ ) - { - T* D = (T*)(dst.data + dst.step*dy); - int sy0 = dy*scale_y, w = sy0 + scale_y <= ssize.height ? dwidth1 : 0; - if( sy0 >= ssize.height ) - { - for( dx = 0; dx < dsize.width; dx++ ) - D[dx] = 0; - continue; - } - - for( dx = 0; dx < w; dx++ ) - { - const T* S = (const T*)(src.data + src.step*sy0) + xofs[dx]; - WT sum = 0; - k=0; - #if CV_ENABLE_UNROLLED - for( ; k <= area - 4; k += 4 ) - sum += S[ofs[k]] + S[ofs[k+1]] + S[ofs[k+2]] + S[ofs[k+3]]; - #endif - for( ; k < area; k++ ) - sum += S[ofs[k]]; - - D[dx] = saturate_cast(sum*scale); - } - - for( ; dx < dsize.width; dx++ ) - { - WT sum = 0; - int count = 0, sx0 = xofs[dx]; - if( sx0 >= ssize.width ) - D[dx] = 0; - - for( int sy = 0; sy < scale_y; sy++ ) - { - if( sy0 + sy >= ssize.height ) - break; - const T* S = (const T*)(src.data + src.step*(sy0 + sy)) + sx0; - for( int sx = 0; sx < scale_x*cn; sx += cn ) - { - if( sx0 + sx >= ssize.width ) - break; - sum += S[sx]; - count++; - } - } - - D[dx] = saturate_cast((float)sum/count); - } - } + Range range(0, dst.rows); + resizeAreaFast_Invoker invoker(src, dst, scale_x, + scale_y, ofs, xofs); + parallel_for_(range, invoker); } struct DecimateAlpha @@ -1228,222 +1385,260 @@ struct DecimateAlpha float alpha; }; +template +class resizeArea_Invoker : + public ParallelLoopBody +{ +public: + resizeArea_Invoker(const Mat& _src, Mat& _dst, const DecimateAlpha* _xofs, + int _xofs_count, double _scale_y_ +#ifdef HAVE_TBB + , const int* _yofs, const int* _cur_dy_ofs +#endif + ) : + ParallelLoopBody(), src(_src), dst(_dst), xofs(_xofs), + xofs_count(_xofs_count), scale_y_(_scale_y_) +#ifdef HAVE_TBB + , yofs(_yofs), cur_dy_ofs(_cur_dy_ofs) +#endif + { + } + + virtual void operator() (const Range& range) const + { + Size ssize = src.size(), dsize = dst.size(); + int cn = src.channels(); + dsize.width *= cn; + AutoBuffer _buffer(dsize.width*2); + WT *buf = _buffer, *sum = buf + dsize.width; + int k, sy, dx, cur_dy = 0, num = sizeof(WT) * dsize.width; + WT scale_y = (WT)scale_y_; + + CV_Assert( cn <= 4 ); + memset(buf, 0, num * 2); + +#ifdef HAVE_TBB + sy = yofs[range.start]; + cur_dy = cur_dy_ofs[sy]; + for( ; sy < range.start; sy++ ) + { + const T* S = (const T*)(src.data + src.step * sy); + memset(buf, 0, num); + + if( cn == 1 ) + for( k = 0; k < xofs_count; k++ ) + { + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + buf[dxn] += S[xofs[k].si]*alpha; + } + else if( cn == 2 ) + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + buf[dxn] = t0; buf[dxn+1] = t1; + } + else if( cn == 3 ) + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + WT t2 = buf[dxn+2] + S[sxn+2]*alpha; + + buf[dxn] = t0; buf[dxn+1] = t1; buf[dxn+2] = t2; + } + else + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + + buf[dxn] = t0; buf[dxn+1] = t1; + + t0 = buf[dxn+2] + S[sxn+2]*alpha; + t1 = buf[dxn+3] + S[sxn+3]*alpha; + + buf[dxn+2] = t0; buf[dxn+3] = t1; + } + + if( (cur_dy + 1)*scale_y <= sy + 1 || sy == ssize.height - 1 ) + { + WT beta = std::max(sy + 1 - (cur_dy + 1) * scale_y, (WT)0); + if( fabs(beta) < 1e-3 ) + { + if(cur_dy >= dsize.height) + break; + memset(sum, 0, num); + } + else + for( dx = 0; dx < dsize.width; dx++ ) + sum[dx] = buf[dx] * beta; + cur_dy++; + } + else + { + for( dx = 0; dx <= dsize.width - 2; dx += 2 ) + { + WT t0 = sum[dx] + buf[dx]; + WT t1 = sum[dx+1] + buf[dx+1]; + sum[dx] = t0; sum[dx+1] = t1; + } + for( ; dx < dsize.width; dx++ ) + sum[dx] += buf[dx]; + } + } +#endif + + for( sy = range.start; sy < range.end; sy++ ) + { + const T* S = (const T*)(src.data + src.step * sy); + memset(buf, 0, num); + + if( cn == 1 ) + for( k = 0; k < xofs_count; k++ ) + { + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + buf[dxn] += S[xofs[k].si]*alpha; + } + else if( cn == 2 ) + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + buf[dxn] = t0; buf[dxn+1] = t1; + } + else if( cn == 3 ) + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + WT t2 = buf[dxn+2] + S[sxn+2]*alpha; + + buf[dxn] = t0; buf[dxn+1] = t1; buf[dxn+2] = t2; + } + else + for( k = 0; k < xofs_count; k++ ) + { + int sxn = xofs[k].si; + int dxn = xofs[k].di; + WT alpha = xofs[k].alpha; + + WT t0 = buf[dxn] + S[sxn]*alpha; + WT t1 = buf[dxn+1] + S[sxn+1]*alpha; + + buf[dxn] = t0; buf[dxn+1] = t1; + + t0 = buf[dxn+2] + S[sxn+2]*alpha; + t1 = buf[dxn+3] + S[sxn+3]*alpha; + + buf[dxn+2] = t0; buf[dxn+3] = t1; + } + + if( (cur_dy + 1)*scale_y <= sy + 1 || sy == ssize.height - 1 ) + { + WT beta = std::max(sy + 1 - (cur_dy + 1) * scale_y, (WT)0); + T* D = (T*)(dst.data + dst.step*cur_dy); + if( fabs(beta) < 1e-3 ) + { + if(cur_dy >= dsize.height) + return; + for( dx = 0; dx < dsize.width; dx++ ) + D[dx] = saturate_cast((sum[dx] + buf[dx]) / min(scale_y, src.rows - cur_dy * scale_y)); + memset(sum, 0, num); + } + else + { + WT beta1 = 1 - beta; + for( dx = 0; dx < dsize.width; dx++ ) + { + D[dx] = saturate_cast((sum[dx] + buf[dx] * beta1)/ min(scale_y, src.rows - cur_dy * scale_y)); + sum[dx] = buf[dx] * beta; + } + } + cur_dy++; + } + else + { + for( dx = 0; dx <= dsize.width - 2; dx += 2 ) + { + WT t0 = sum[dx] + buf[dx]; + WT t1 = sum[dx+1] + buf[dx+1]; + sum[dx] = t0; sum[dx+1] = t1; + } + for( ; dx < dsize.width; dx++ ) + sum[dx] += buf[dx]; + } + } + } + +private: + const Mat src; + Mat dst; + const DecimateAlpha* xofs; + const int xofs_count; + const double scale_y_; +#ifdef HAVE_TBB + const int *yofs, *cur_dy_ofs; +#endif +}; + template static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, int xofs_count, double scale_y_) { +#ifdef HAVE_TBB Size ssize = src.size(), dsize = dst.size(); - int cn = src.channels(); - dsize.width *= cn; - AutoBuffer _buffer(dsize.width*2); - WT *buf = _buffer, *sum = buf + dsize.width; - int k, sy, dx, cur_dy = 0; - WT scale_y = (WT)scale_y_; - - CV_Assert( cn <= 4 ); - for( dx = 0; dx < dsize.width; dx++ ) - buf[dx] = sum[dx] = 0; - + AutoBuffer _yofs(2 * ssize.height); + int *yofs = _yofs, *cur_dy_ofs = _yofs + ssize.height; + int index = 0, cur_dy = 0, sy; + for( sy = 0; sy < ssize.height; sy++ ) { - const T* S = (const T*)(src.data + src.step*sy); - if( cn == 1 ) - for( k = 0; k < xofs_count; k++ ) - { - int dxn = xofs[k].di; - WT alpha = xofs[k].alpha; - buf[dxn] += S[xofs[k].si]*alpha; - } - else if( cn == 2 ) - for( k = 0; k < xofs_count; k++ ) - { - int sxn = xofs[k].si; - int dxn = xofs[k].di; - WT alpha = xofs[k].alpha; - WT t0 = buf[dxn] + S[sxn]*alpha; - WT t1 = buf[dxn+1] + S[sxn+1]*alpha; - buf[dxn] = t0; buf[dxn+1] = t1; - } - else if( cn == 3 ) - for( k = 0; k < xofs_count; k++ ) - { - int sxn = xofs[k].si; - int dxn = xofs[k].di; - WT alpha = xofs[k].alpha; - WT t0 = buf[dxn] + S[sxn]*alpha; - WT t1 = buf[dxn+1] + S[sxn+1]*alpha; - WT t2 = buf[dxn+2] + S[sxn+2]*alpha; - buf[dxn] = t0; buf[dxn+1] = t1; buf[dxn+2] = t2; - } - else - for( k = 0; k < xofs_count; k++ ) - { - int sxn = xofs[k].si; - int dxn = xofs[k].di; - WT alpha = xofs[k].alpha; - WT t0 = buf[dxn] + S[sxn]*alpha; - WT t1 = buf[dxn+1] + S[sxn+1]*alpha; - buf[dxn] = t0; buf[dxn+1] = t1; - t0 = buf[dxn+2] + S[sxn+2]*alpha; - t1 = buf[dxn+3] + S[sxn+3]*alpha; - buf[dxn+2] = t0; buf[dxn+3] = t1; - } - - if( (cur_dy + 1)*scale_y <= sy + 1 || sy == ssize.height - 1 ) + bool reset = false; + cur_dy_ofs[sy] = cur_dy; + if( (cur_dy + 1)*scale_y_ <= sy + 1 || sy == ssize.height - 1 ) { - WT beta = std::max(sy + 1 - (cur_dy+1)*scale_y, (WT)0); - WT beta1 = 1 - beta; - T* D = (T*)(dst.data + dst.step*cur_dy); + WT beta = std::max(sy + 1 - (cur_dy+1)*scale_y_, 0.); if( fabs(beta) < 1e-3 ) { - if(cur_dy >= dsize.height) return; - for( dx = 0; dx < dsize.width; dx++ ) - { - D[dx] = saturate_cast((sum[dx] + buf[dx]) / min(scale_y, src.rows - cur_dy * scale_y)); - sum[dx] = buf[dx] = 0; - } + if(cur_dy >= dsize.height) + break; + reset = true; } - else - for( dx = 0; dx < dsize.width; dx++ ) - { - D[dx] = saturate_cast((sum[dx] + buf[dx]* beta1)/ min(scale_y, src.rows - cur_dy*scale_y)); - sum[dx] = buf[dx]*beta; - buf[dx] = 0; - } cur_dy++; } - else - { - for( dx = 0; dx <= dsize.width - 2; dx += 2 ) - { - WT t0 = sum[dx] + buf[dx]; - WT t1 = sum[dx+1] + buf[dx+1]; - sum[dx] = t0; sum[dx+1] = t1; - buf[dx] = buf[dx+1] = 0; - } - for( ; dx < dsize.width; dx++ ) - { - sum[dx] += buf[dx]; - buf[dx] = 0; - } - } + yofs[sy] = index; + if (reset) + index = sy + 1; } -} - - -static void resizeAreaFast_8u( const Mat& src, Mat& dst, - const int* ofs, const int* xofs, - int scale_x, int scale_y ) -{ -#if CV_SSE2 - bool haveSSE2 = checkHardwareSupport(CV_CPU_SSE2); #endif - Size ssize = src.size(), dsize = dst.size(); - int cn = src.channels(); - int dy, dx, k = 0; - int area = scale_x*scale_y; - float scale = 1.f/(scale_x*scale_y); - int dwidth1 = (ssize.width/scale_x)*cn; - dsize.width *= cn; - ssize.width *= cn; - //avg values - for( dy = 0; dy < dsize.height; dy++ ) - { - uchar* D = (uchar*)(dst.data + dst.step*dy); - int sy0 = dy*scale_y, w = sy0 + scale_y <= ssize.height ? dwidth1 : 0; - if( sy0 >= ssize.height ) - { - for( dx = 0; dx < dsize.width; dx++ ) //memset(D,0, dsize.width);//warning, never executed -> not tested - D[dx] = 0; - continue; - } - dx = 0; - - #if CV_SSE2 - if( haveSSE2 ) - { - const __m128 _scale = _mm_set1_ps(scale); - const __m128i _ucMAXs = _mm_set1_epi16(UCHAR_MAX); - const uchar* _S[8]; - - for(; dx < w-8; dx+=8 ) - { - __m128i _sum = _mm_setzero_si128(); - __m128i _sum1 = _mm_setzero_si128(); - _S[0] = (const uchar*)(src.data + src.step*sy0) + xofs[dx]; - _S[1] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+1]; - _S[2] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+2]; - _S[3] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+3]; - - _S[4] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+4]; - _S[5] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+5]; - _S[6] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+6]; - _S[7] = (const uchar*)(src.data + src.step*sy0) + xofs[dx+7]; - - for( k = 0; k < area; k++ ) - { - int ofsk = ofs[k]; - __m128i _temp = _mm_set_epi32(_S[3][ofsk],_S[2][ofsk],_S[1][ofsk],_S[0][ofsk]); - _sum = _mm_add_epi32(_sum, _temp); - - __m128i _temp1 = _mm_set_epi32(_S[7][ofsk],_S[6][ofsk],_S[5][ofsk],_S[4][ofsk]); - _sum1 = _mm_add_epi32(_sum1, _temp1); - } - - __m128i _tempSum = _mm_cvtps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(_sum), _scale)); - __m128i _tempSum1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_cvtepi32_ps(_sum1), _scale)); - - _tempSum = _mm_packs_epi32(_tempSum, _tempSum1); - _tempSum = _mm_min_epi16(_ucMAXs, _tempSum); - _tempSum = _mm_packus_epi16(_tempSum, _tempSum); - _mm_storel_epi64((__m128i*)(D+dx),_tempSum); - } - } - #endif - - for(; dx < w; dx++ ) - { - const uchar* S = (const uchar*)(src.data + src.step*sy0) + xofs[dx]; - int sum = 0; - k=0; - - #if CV_ENABLE_UNROLLED - for( ; k <= area - 4; k += 4 ) - sum += S[ofs[k]] + S[ofs[k+1]] + S[ofs[k+2]] + S[ofs[k+3]]; - #endif - - for( ; k < area; k++ ) - sum += S[ofs[k]]; - - - D[dx] = saturate_cast(sum*scale); - } - - for( ; dx < dsize.width; dx++ ) - { - int sum = 0; - int count = 0, sx0 = xofs[dx]; - if( sx0 >= ssize.width ) - D[dx] = 0; - - for( int sy = 0; sy < scale_y; sy++ ) - { - if( sy0 + sy >= ssize.height ) - break; - const uchar* S = (const uchar*)(src.data + src.step*(sy0 + sy)) + sx0; - int sx = 0; - for( ; sx < scale_x*cn; sx += cn ) - { - if( sx0 + sx >= ssize.width ) - break; - sum += S[sx]; - count++; - } - } - - D[dx] = saturate_cast((float)sum/count); - } - } + Range range(0, src.rows); + resizeArea_Invoker invoker(src, dst, xofs, xofs_count, scale_y_ +#ifdef HAVE_TBB + , yofs, cur_dy_ofs +#endif + ); + parallel_for_(range, invoker); } @@ -1457,10 +1652,12 @@ typedef void (*ResizeAreaFastFunc)( const Mat& src, Mat& dst, int scale_x, int scale_y ); typedef void (*ResizeAreaFunc)( const Mat& src, Mat& dst, - const DecimateAlpha* xofs, int xofs_count, double scale_y_); + const DecimateAlpha* xofs, int xofs_count, + double scale_y_); } + ////////////////////////////////////////////////////////////////////////////////////////// void cv::resize( InputArray _src, OutputArray _dst, Size dsize, @@ -1553,30 +1750,33 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, static ResizeAreaFastFunc areafast_tab[] = { - resizeAreaFast_8u, 0, - resizeAreaFast_, - resizeAreaFast_, + resizeAreaFast_ >, 0, - resizeAreaFast_, - resizeAreaFast_, + resizeAreaFast_ >, + resizeAreaFast_ >, + 0, + resizeAreaFast_ >, + resizeAreaFast_ >, 0 }; static ResizeAreaFunc area_tab[] = { - resizeArea_, 0, resizeArea_, resizeArea_, - 0, resizeArea_, resizeArea_, 0 + resizeArea_, 0, resizeArea_, + resizeArea_, 0, resizeArea_, + resizeArea_, 0 }; Mat src = _src.getMat(); Size ssize = src.size(); CV_Assert( ssize.area() > 0 ); - CV_Assert( !(dsize == Size()) || (inv_scale_x > 0 && inv_scale_y > 0) ); - if( dsize == Size() ) + CV_Assert( dsize.area() || (inv_scale_x > 0 && inv_scale_y > 0) ); + if( !dsize.area() ) { dsize = Size(saturate_cast(src.cols*inv_scale_x), saturate_cast(src.rows*inv_scale_y)); + CV_Assert( dsize.area() ); } else { @@ -1601,79 +1801,92 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, resizeNN( src, dst, inv_scale_x, inv_scale_y ); return; } - - // true "area" interpolation is only implemented for the case (scale_x <= 1 && scale_y <= 1). - // In other cases it is emulated using some variant of bilinear interpolation - if( interpolation == INTER_AREA && scale_x >= 1 && scale_y >= 1 ) + { int iscale_x = saturate_cast(scale_x); int iscale_y = saturate_cast(scale_y); + + bool is_area_fast = std::abs(scale_x - iscale_x) < DBL_EPSILON && + std::abs(scale_y - iscale_y) < DBL_EPSILON; + + // in case of scale_x && scale_y is equal to 2 + // INTER_AREA (fast) also is equal to INTER_LINEAR + if ( interpolation == INTER_LINEAR && + scale_x >= 1 && scale_y >= 1 && is_area_fast) + interpolation = INTER_AREA; - if( std::abs(scale_x - iscale_x) < DBL_EPSILON && - std::abs(scale_y - iscale_y) < DBL_EPSILON ) + // true "area" interpolation is only implemented for the case (scale_x <= 1 && scale_y <= 1). + // In other cases it is emulated using some variant of bilinear interpolation + if( interpolation == INTER_AREA && scale_x >= 1 && scale_y >= 1 ) { - int area = iscale_x*iscale_y; - size_t srcstep = src.step / src.elemSize1(); - AutoBuffer _ofs(area + dsize.width*cn); - int* ofs = _ofs; - int* xofs = ofs + area; - ResizeAreaFastFunc func = areafast_tab[depth]; - CV_Assert( func != 0 ); - - for( sy = 0, k = 0; sy < iscale_y; sy++ ) - for( sx = 0; sx < iscale_x; sx++ ) - ofs[k++] = (int)(sy*srcstep + sx*cn); - - for( dx = 0; dx < dsize.width; dx++ ) + if( is_area_fast ) { - sx = dx*iscale_x*cn; - for( k = 0; k < cn; k++ ) - xofs[dx*cn + k] = sx + k; + int area = iscale_x*iscale_y; + size_t srcstep = src.step / src.elemSize1(); + AutoBuffer _ofs(area + dsize.width*cn); + int* ofs = _ofs; + int* xofs = ofs + area; + ResizeAreaFastFunc func = areafast_tab[depth]; + CV_Assert( func != 0 ); + + for( sy = 0, k = 0; sy < iscale_y; sy++ ) + for( sx = 0; sx < iscale_x; sx++ ) + ofs[k++] = (int)(sy*srcstep + sx*cn); + + for( dx = 0; dx < dsize.width; dx++ ) + { + int j = dx * cn; + sx = iscale_x * j; + for( k = 0; k < cn; k++ ) + xofs[j + k] = sx + k; + } + + func( src, dst, ofs, xofs, iscale_x, iscale_y ); + return; } - func( src, dst, ofs, xofs, iscale_x, iscale_y ); + ResizeAreaFunc func = area_tab[depth]; + CV_Assert( func != 0 && cn <= 4 ); + + AutoBuffer _xofs(ssize.width*2); + DecimateAlpha* xofs = _xofs; + + for( dx = 0, k = 0; dx < dsize.width; dx++ ) + { + double fsx1 = dx*scale_x; + double fsx2 = fsx1 + scale_x; + int sx1 = cvCeil(fsx1), sx2 = cvFloor(fsx2); + sx1 = std::min(sx1, ssize.width-1); + sx2 = std::min(sx2, ssize.width-1); + + if( sx1 > fsx1 ) + { + assert( k < ssize.width*2 ); + xofs[k].di = dx*cn; + xofs[k].si = (sx1-1)*cn; + xofs[k++].alpha = (float)((sx1 - fsx1) / min(scale_x, src.cols - fsx1)); + } + + for( sx = sx1; sx < sx2; sx++ ) + { + assert( k < ssize.width*2 ); + xofs[k].di = dx*cn; + xofs[k].si = sx*cn; + xofs[k++].alpha = float(1.0 / min(scale_x, src.cols - fsx1)); + } + + if( fsx2 - sx2 > 1e-3 ) + { + assert( k < ssize.width*2 ); + xofs[k].di = dx*cn; + xofs[k].si = sx2*cn; + xofs[k++].alpha = (float)(min(fsx2 - sx2, 1.) / min(scale_x, src.cols - fsx1)); + } + } + + func( src, dst, xofs, k, scale_y); return; } - - ResizeAreaFunc func = area_tab[depth]; - CV_Assert( func != 0 && cn <= 4 ); - - AutoBuffer _xofs(ssize.width*2); - DecimateAlpha* xofs = _xofs; - - for( dx = 0, k = 0; dx < dsize.width; dx++ ) - { - double fsx1 = dx*scale_x, fsx2 = fsx1 + scale_x; - int sx1 = cvCeil(fsx1), sx2 = cvFloor(fsx2); - sx1 = std::min(sx1, ssize.width-1); - sx2 = std::min(sx2, ssize.width-1); - - if( sx1 > fsx1 ) - { - assert( k < ssize.width*2 ); - xofs[k].di = dx*cn; - xofs[k].si = (sx1-1)*cn; - xofs[k++].alpha = (float)((sx1 - fsx1) / min(scale_x, src.cols - fsx1)); - } - - for( sx = sx1; sx < sx2; sx++ ) - { - assert( k < ssize.width*2 ); - xofs[k].di = dx*cn; - xofs[k].si = sx*cn; - xofs[k++].alpha = float(1.0 / min(scale_x, src.cols - fsx1)); - } - - if( fsx2 - sx2 > 1e-3 ) - { - assert( k < ssize.width*2 ); - xofs[k].di = dx*cn; - xofs[k].si = sx2*cn; - xofs[k++].alpha = (float)(min(fsx2 - sx2, 1.) / min(scale_x, src.cols - fsx1)); - } - } - func( src, dst, xofs, k ,scale_y); - return; } int xmin = 0, xmax = dsize.width, width = dsize.width*cn; @@ -2549,6 +2762,206 @@ typedef void (*RemapFunc)(const Mat& _src, Mat& _dst, const Mat& _xy, const Mat& _fxy, const void* _wtab, int borderType, const Scalar& _borderValue); +class remapInvoker : + public ParallelLoopBody +{ +public: + remapInvoker(const Mat& _src, Mat _dst, const Mat& _map1, const Mat& _map2, const Mat *_m1, + const Mat *_m2, int _interpolation, int _borderType, const Scalar &_borderValue, + int _planar_input, RemapNNFunc _nnfunc, RemapFunc _ifunc, const void *_ctab) : + ParallelLoopBody(), src(_src), dst(_dst), map1(_map1), map2(_map2), m1(_m1), m2(_m2), + interpolation(_interpolation), borderType(_borderType), borderValue(_borderValue), + planar_input(_planar_input), nnfunc(_nnfunc), ifunc(_ifunc), ctab(_ctab) + { + } + + virtual void operator() (const Range& range) const + { + int x, y, x1, y1; + const int buf_size = 1 << 14; + int brows0 = std::min(128, dst.rows), map_depth = map1.depth(); + int bcols0 = std::min(buf_size/brows0, dst.cols); + brows0 = std::min(buf_size/bcols0, dst.rows); + #if CV_SSE2 + bool useSIMD = checkHardwareSupport(CV_CPU_SSE2); + #endif + + Mat _bufxy(brows0, bcols0, CV_16SC2), _bufa; + if( !nnfunc ) + _bufa.create(brows0, bcols0, CV_16UC1); + + for( y = range.start; y < range.end; y += brows0 ) + { + for( x = 0; x < dst.cols; x += bcols0 ) + { + int brows = std::min(brows0, range.end - y); + int bcols = std::min(bcols0, dst.cols - x); + Mat dpart(dst, Rect(x, y, bcols, brows)); + Mat bufxy(_bufxy, Rect(0, 0, bcols, brows)); + + if( nnfunc ) + { + if( map1.type() == CV_16SC2 && !map2.data ) // the data is already in the right format + bufxy = map1(Rect(x, y, bcols, brows)); + else if( map_depth != CV_32F ) + { + for( y1 = 0; y1 < brows; y1++ ) + { + short* XY = (short*)(bufxy.data + bufxy.step*y1); + const short* sXY = (const short*)(m1->data + m1->step*(y+y1)) + x*2; + const ushort* sA = (const ushort*)(m2->data + m2->step*(y+y1)) + x; + + for( x1 = 0; x1 < bcols; x1++ ) + { + int a = sA[x1] & (INTER_TAB_SIZE2-1); + XY[x1*2] = sXY[x1*2] + NNDeltaTab_i[a][0]; + XY[x1*2+1] = sXY[x1*2+1] + NNDeltaTab_i[a][1]; + } + } + } + else if( !planar_input ) + map1(Rect(x, y, bcols, brows)).convertTo(bufxy, bufxy.depth()); + else + { + for( y1 = 0; y1 < brows; y1++ ) + { + short* XY = (short*)(bufxy.data + bufxy.step*y1); + const float* sX = (const float*)(map1.data + map1.step*(y+y1)) + x; + const float* sY = (const float*)(map2.data + map2.step*(y+y1)) + x; + x1 = 0; + + #if CV_SSE2 + if( useSIMD ) + { + for( ; x1 <= bcols - 8; x1 += 8 ) + { + __m128 fx0 = _mm_loadu_ps(sX + x1); + __m128 fx1 = _mm_loadu_ps(sX + x1 + 4); + __m128 fy0 = _mm_loadu_ps(sY + x1); + __m128 fy1 = _mm_loadu_ps(sY + x1 + 4); + __m128i ix0 = _mm_cvtps_epi32(fx0); + __m128i ix1 = _mm_cvtps_epi32(fx1); + __m128i iy0 = _mm_cvtps_epi32(fy0); + __m128i iy1 = _mm_cvtps_epi32(fy1); + ix0 = _mm_packs_epi32(ix0, ix1); + iy0 = _mm_packs_epi32(iy0, iy1); + ix1 = _mm_unpacklo_epi16(ix0, iy0); + iy1 = _mm_unpackhi_epi16(ix0, iy0); + _mm_storeu_si128((__m128i*)(XY + x1*2), ix1); + _mm_storeu_si128((__m128i*)(XY + x1*2 + 8), iy1); + } + } + #endif + + for( ; x1 < bcols; x1++ ) + { + XY[x1*2] = saturate_cast(sX[x1]); + XY[x1*2+1] = saturate_cast(sY[x1]); + } + } + } + nnfunc( src, dpart, bufxy, borderType, borderValue ); + continue; + } + + Mat bufa(_bufa, Rect(0, 0, bcols, brows)); + for( y1 = 0; y1 < brows; y1++ ) + { + short* XY = (short*)(bufxy.data + bufxy.step*y1); + ushort* A = (ushort*)(bufa.data + bufa.step*y1); + + if( (map1.type() == CV_16SC2 && (map2.type() == CV_16UC1 || map2.type() == CV_16SC1)) || + (map2.type() == CV_16SC2 && (map1.type() == CV_16UC1 || map1.type() == CV_16SC1)) ) + { + bufxy = m1->operator()(Rect(x, y, bcols, brows)); + bufa = m2->operator()(Rect(x, y, bcols, brows)); + } + else if( planar_input ) + { + const float* sX = (const float*)(map1.data + map1.step*(y+y1)) + x; + const float* sY = (const float*)(map2.data + map2.step*(y+y1)) + x; + + x1 = 0; + #if CV_SSE2 + if( useSIMD ) + { + __m128 scale = _mm_set1_ps((float)INTER_TAB_SIZE); + __m128i mask = _mm_set1_epi32(INTER_TAB_SIZE-1); + for( ; x1 <= bcols - 8; x1 += 8 ) + { + __m128 fx0 = _mm_loadu_ps(sX + x1); + __m128 fx1 = _mm_loadu_ps(sX + x1 + 4); + __m128 fy0 = _mm_loadu_ps(sY + x1); + __m128 fy1 = _mm_loadu_ps(sY + x1 + 4); + __m128i ix0 = _mm_cvtps_epi32(_mm_mul_ps(fx0, scale)); + __m128i ix1 = _mm_cvtps_epi32(_mm_mul_ps(fx1, scale)); + __m128i iy0 = _mm_cvtps_epi32(_mm_mul_ps(fy0, scale)); + __m128i iy1 = _mm_cvtps_epi32(_mm_mul_ps(fy1, scale)); + __m128i mx0 = _mm_and_si128(ix0, mask); + __m128i mx1 = _mm_and_si128(ix1, mask); + __m128i my0 = _mm_and_si128(iy0, mask); + __m128i my1 = _mm_and_si128(iy1, mask); + mx0 = _mm_packs_epi32(mx0, mx1); + my0 = _mm_packs_epi32(my0, my1); + my0 = _mm_slli_epi16(my0, INTER_BITS); + mx0 = _mm_or_si128(mx0, my0); + _mm_storeu_si128((__m128i*)(A + x1), mx0); + ix0 = _mm_srai_epi32(ix0, INTER_BITS); + ix1 = _mm_srai_epi32(ix1, INTER_BITS); + iy0 = _mm_srai_epi32(iy0, INTER_BITS); + iy1 = _mm_srai_epi32(iy1, INTER_BITS); + ix0 = _mm_packs_epi32(ix0, ix1); + iy0 = _mm_packs_epi32(iy0, iy1); + ix1 = _mm_unpacklo_epi16(ix0, iy0); + iy1 = _mm_unpackhi_epi16(ix0, iy0); + _mm_storeu_si128((__m128i*)(XY + x1*2), ix1); + _mm_storeu_si128((__m128i*)(XY + x1*2 + 8), iy1); + } + } + #endif + + for( ; x1 < bcols; x1++ ) + { + int sx = cvRound(sX[x1]*INTER_TAB_SIZE); + int sy = cvRound(sY[x1]*INTER_TAB_SIZE); + int v = (sy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (sx & (INTER_TAB_SIZE-1)); + XY[x1*2] = (short)(sx >> INTER_BITS); + XY[x1*2+1] = (short)(sy >> INTER_BITS); + A[x1] = (ushort)v; + } + } + else + { + const float* sXY = (const float*)(map1.data + map1.step*(y+y1)) + x*2; + + for( x1 = 0; x1 < bcols; x1++ ) + { + int sx = cvRound(sXY[x1*2]*INTER_TAB_SIZE); + int sy = cvRound(sXY[x1*2+1]*INTER_TAB_SIZE); + int v = (sy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (sx & (INTER_TAB_SIZE-1)); + XY[x1*2] = (short)(sx >> INTER_BITS); + XY[x1*2+1] = (short)(sy >> INTER_BITS); + A[x1] = (ushort)v; + } + } + } + ifunc(src, dpart, bufxy, bufa, ctab, borderType, borderValue); + } + } + } + +private: + const Mat src; + Mat dst; + const Mat map1, map2, *m1, *m2; + int interpolation, borderType; + const Scalar borderValue; + int planar_input; + RemapNNFunc nnfunc; + RemapFunc ifunc; + const void *ctab; +}; + } void cv::remap( InputArray _src, OutputArray _dst, @@ -2590,14 +3003,15 @@ void cv::remap( InputArray _src, OutputArray _dst, Mat src = _src.getMat(), map1 = _map1.getMat(), map2 = _map2.getMat(); - CV_Assert( (!map2.data || map2.size() == map1.size())); + CV_Assert( map1.size().area() > 0 ); + CV_Assert( !map2.data || (map2.size() == map1.size())); _dst.create( map1.size(), src.type() ); Mat dst = _dst.getMat(); if( dst.data == src.data ) src = src.clone(); - int depth = src.depth(), map_depth = map1.depth(); + int depth = src.depth(); RemapNNFunc nnfunc = 0; RemapFunc ifunc = 0; const void* ctab = 0; @@ -2608,12 +3022,6 @@ void cv::remap( InputArray _src, OutputArray _dst, { nnfunc = nn_tab[depth]; CV_Assert( nnfunc != 0 ); - - if( map1.type() == CV_16SC2 && !map2.data ) // the data is already in the right format - { - nnfunc( src, dst, map1, borderType, borderValue ); - return; - } } else { @@ -2639,182 +3047,19 @@ void cv::remap( InputArray _src, OutputArray _dst, { if( map1.type() != CV_16SC2 ) std::swap(m1, m2); - if( ifunc ) - { - ifunc( src, dst, *m1, *m2, ctab, borderType, borderValue ); - return; - } } else { - CV_Assert( (map1.type() == CV_32FC2 && !map2.data) || + CV_Assert( ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && !map2.data) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) ); planar_input = map1.channels() == 1; } - int x, y, x1, y1; - const int buf_size = 1 << 14; - int brows0 = std::min(128, dst.rows); - int bcols0 = std::min(buf_size/brows0, dst.cols); - brows0 = std::min(buf_size/bcols0, dst.rows); -#if CV_SSE2 - bool useSIMD = checkHardwareSupport(CV_CPU_SSE2); -#endif - - Mat _bufxy(brows0, bcols0, CV_16SC2), _bufa; - if( !nnfunc ) - _bufa.create(brows0, bcols0, CV_16UC1); - - for( y = 0; y < dst.rows; y += brows0 ) - { - for( x = 0; x < dst.cols; x += bcols0 ) - { - int brows = std::min(brows0, dst.rows - y); - int bcols = std::min(bcols0, dst.cols - x); - Mat dpart(dst, Rect(x, y, bcols, brows)); - Mat bufxy(_bufxy, Rect(0, 0, bcols, brows)); - - if( nnfunc ) - { - if( map_depth != CV_32F ) - { - for( y1 = 0; y1 < brows; y1++ ) - { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - const short* sXY = (const short*)(m1->data + m1->step*(y+y1)) + x*2; - const ushort* sA = (const ushort*)(m2->data + m2->step*(y+y1)) + x; - - for( x1 = 0; x1 < bcols; x1++ ) - { - int a = sA[x1] & (INTER_TAB_SIZE2-1); - XY[x1*2] = sXY[x1*2] + NNDeltaTab_i[a][0]; - XY[x1*2+1] = sXY[x1*2+1] + NNDeltaTab_i[a][1]; - } - } - } - else if( !planar_input ) - map1(Rect(0,0,bcols,brows)).convertTo(bufxy, bufxy.depth()); - else - { - for( y1 = 0; y1 < brows; y1++ ) - { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - const float* sX = (const float*)(map1.data + map1.step*(y+y1)) + x; - const float* sY = (const float*)(map2.data + map2.step*(y+y1)) + x; - x1 = 0; - - #if CV_SSE2 - if( useSIMD ) - { - for( ; x1 <= bcols - 8; x1 += 8 ) - { - __m128 fx0 = _mm_loadu_ps(sX + x1); - __m128 fx1 = _mm_loadu_ps(sX + x1 + 4); - __m128 fy0 = _mm_loadu_ps(sY + x1); - __m128 fy1 = _mm_loadu_ps(sY + x1 + 4); - __m128i ix0 = _mm_cvtps_epi32(fx0); - __m128i ix1 = _mm_cvtps_epi32(fx1); - __m128i iy0 = _mm_cvtps_epi32(fy0); - __m128i iy1 = _mm_cvtps_epi32(fy1); - ix0 = _mm_packs_epi32(ix0, ix1); - iy0 = _mm_packs_epi32(iy0, iy1); - ix1 = _mm_unpacklo_epi16(ix0, iy0); - iy1 = _mm_unpackhi_epi16(ix0, iy0); - _mm_storeu_si128((__m128i*)(XY + x1*2), ix1); - _mm_storeu_si128((__m128i*)(XY + x1*2 + 8), iy1); - } - } - #endif - - for( ; x1 < bcols; x1++ ) - { - XY[x1*2] = saturate_cast(sX[x1]); - XY[x1*2+1] = saturate_cast(sY[x1]); - } - } - } - nnfunc( src, dpart, bufxy, borderType, borderValue ); - continue; - } - - Mat bufa(_bufa, Rect(0,0,bcols, brows)); - for( y1 = 0; y1 < brows; y1++ ) - { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - ushort* A = (ushort*)(bufa.data + bufa.step*y1); - - if( planar_input ) - { - const float* sX = (const float*)(map1.data + map1.step*(y+y1)) + x; - const float* sY = (const float*)(map2.data + map2.step*(y+y1)) + x; - - x1 = 0; - #if CV_SSE2 - if( useSIMD ) - { - __m128 scale = _mm_set1_ps((float)INTER_TAB_SIZE); - __m128i mask = _mm_set1_epi32(INTER_TAB_SIZE-1); - for( ; x1 <= bcols - 8; x1 += 8 ) - { - __m128 fx0 = _mm_loadu_ps(sX + x1); - __m128 fx1 = _mm_loadu_ps(sX + x1 + 4); - __m128 fy0 = _mm_loadu_ps(sY + x1); - __m128 fy1 = _mm_loadu_ps(sY + x1 + 4); - __m128i ix0 = _mm_cvtps_epi32(_mm_mul_ps(fx0, scale)); - __m128i ix1 = _mm_cvtps_epi32(_mm_mul_ps(fx1, scale)); - __m128i iy0 = _mm_cvtps_epi32(_mm_mul_ps(fy0, scale)); - __m128i iy1 = _mm_cvtps_epi32(_mm_mul_ps(fy1, scale)); - __m128i mx0 = _mm_and_si128(ix0, mask); - __m128i mx1 = _mm_and_si128(ix1, mask); - __m128i my0 = _mm_and_si128(iy0, mask); - __m128i my1 = _mm_and_si128(iy1, mask); - mx0 = _mm_packs_epi32(mx0, mx1); - my0 = _mm_packs_epi32(my0, my1); - my0 = _mm_slli_epi16(my0, INTER_BITS); - mx0 = _mm_or_si128(mx0, my0); - _mm_storeu_si128((__m128i*)(A + x1), mx0); - ix0 = _mm_srai_epi32(ix0, INTER_BITS); - ix1 = _mm_srai_epi32(ix1, INTER_BITS); - iy0 = _mm_srai_epi32(iy0, INTER_BITS); - iy1 = _mm_srai_epi32(iy1, INTER_BITS); - ix0 = _mm_packs_epi32(ix0, ix1); - iy0 = _mm_packs_epi32(iy0, iy1); - ix1 = _mm_unpacklo_epi16(ix0, iy0); - iy1 = _mm_unpackhi_epi16(ix0, iy0); - _mm_storeu_si128((__m128i*)(XY + x1*2), ix1); - _mm_storeu_si128((__m128i*)(XY + x1*2 + 8), iy1); - } - } - #endif - - for( ; x1 < bcols; x1++ ) - { - int sx = cvRound(sX[x1]*INTER_TAB_SIZE); - int sy = cvRound(sY[x1]*INTER_TAB_SIZE); - int v = (sy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (sx & (INTER_TAB_SIZE-1)); - XY[x1*2] = (short)(sx >> INTER_BITS); - XY[x1*2+1] = (short)(sy >> INTER_BITS); - A[x1] = (ushort)v; - } - } - else - { - const float* sXY = (const float*)(map1.data + map1.step*(y+y1)) + x*2; - - for( x1 = 0; x1 < bcols; x1++ ) - { - int sx = cvRound(sXY[x1*2]*INTER_TAB_SIZE); - int sy = cvRound(sXY[x1*2+1]*INTER_TAB_SIZE); - int v = (sy & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + (sx & (INTER_TAB_SIZE-1)); - XY[x1*2] = (short)(sx >> INTER_BITS); - XY[x1*2+1] = (short)(sy >> INTER_BITS); - A[x1] = (ushort)v; - } - } - } - ifunc(src, dpart, bufxy, bufa, ctab, borderType, borderValue); - } - } + Range range(0, dst.rows); + remapInvoker invoker(src, dst, map1, map2, m1, m2, interpolation, + borderType, borderValue, planar_input, nnfunc, ifunc, + ctab); + parallel_for_(range, invoker); } @@ -2956,7 +3201,134 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, } } + +namespace cv +{ +class warpAffineInvoker : + public ParallelLoopBody +{ +public: + warpAffineInvoker(const Mat &_src, Mat &_dst, int _interpolation, int _borderType, + const Scalar &_borderValue, int *_adelta, int *_bdelta, double *_M) : + ParallelLoopBody(), src(_src), dst(_dst), interpolation(_interpolation), + borderType(_borderType), borderValue(_borderValue), adelta(_adelta), bdelta(_bdelta), + M(_M) + { + } + + virtual void operator() (const Range& range) const + { + const int BLOCK_SZ = 64; + short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ]; + const int AB_BITS = MAX(10, (int)INTER_BITS); + const int AB_SCALE = 1 << AB_BITS; + int round_delta = interpolation == INTER_NEAREST ? AB_SCALE/2 : AB_SCALE/INTER_TAB_SIZE/2, x, y, x1, y1; + #if CV_SSE2 + bool useSIMD = checkHardwareSupport(CV_CPU_SSE2); + #endif + + int bh0 = std::min(BLOCK_SZ/2, dst.rows); + int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, dst.cols); + bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, dst.rows); + + for( y = range.start; y < range.end; y += bh0 ) + { + for( x = 0; x < dst.cols; x += bw0 ) + { + int bw = std::min( bw0, dst.cols - x); + int bh = std::min( bh0, range.end - y); + + Mat _XY(bh, bw, CV_16SC2, XY), matA; + Mat dpart(dst, Rect(x, y, bw, bh)); + + for( y1 = 0; y1 < bh; y1++ ) + { + short* xy = XY + y1*bw*2; + int X0 = saturate_cast((M[1]*(y + y1) + M[2])*AB_SCALE) + round_delta; + int Y0 = saturate_cast((M[4]*(y + y1) + M[5])*AB_SCALE) + round_delta; + + if( interpolation == INTER_NEAREST ) + for( x1 = 0; x1 < bw; x1++ ) + { + int X = (X0 + adelta[x+x1]) >> AB_BITS; + int Y = (Y0 + bdelta[x+x1]) >> AB_BITS; + xy[x1*2] = saturate_cast(X); + xy[x1*2+1] = saturate_cast(Y); + } + else + { + short* alpha = A + y1*bw; + x1 = 0; + #if CV_SSE2 + if( useSIMD ) + { + __m128i fxy_mask = _mm_set1_epi32(INTER_TAB_SIZE - 1); + __m128i XX = _mm_set1_epi32(X0), YY = _mm_set1_epi32(Y0); + for( ; x1 <= bw - 8; x1 += 8 ) + { + __m128i tx0, tx1, ty0, ty1; + tx0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(adelta + x + x1)), XX); + ty0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(bdelta + x + x1)), YY); + tx1 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(adelta + x + x1 + 4)), XX); + ty1 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(bdelta + x + x1 + 4)), YY); + + tx0 = _mm_srai_epi32(tx0, AB_BITS - INTER_BITS); + ty0 = _mm_srai_epi32(ty0, AB_BITS - INTER_BITS); + tx1 = _mm_srai_epi32(tx1, AB_BITS - INTER_BITS); + ty1 = _mm_srai_epi32(ty1, AB_BITS - INTER_BITS); + + __m128i fx_ = _mm_packs_epi32(_mm_and_si128(tx0, fxy_mask), + _mm_and_si128(tx1, fxy_mask)); + __m128i fy_ = _mm_packs_epi32(_mm_and_si128(ty0, fxy_mask), + _mm_and_si128(ty1, fxy_mask)); + tx0 = _mm_packs_epi32(_mm_srai_epi32(tx0, INTER_BITS), + _mm_srai_epi32(tx1, INTER_BITS)); + ty0 = _mm_packs_epi32(_mm_srai_epi32(ty0, INTER_BITS), + _mm_srai_epi32(ty1, INTER_BITS)); + fx_ = _mm_adds_epi16(fx_, _mm_slli_epi16(fy_, INTER_BITS)); + + _mm_storeu_si128((__m128i*)(xy + x1*2), _mm_unpacklo_epi16(tx0, ty0)); + _mm_storeu_si128((__m128i*)(xy + x1*2 + 8), _mm_unpackhi_epi16(tx0, ty0)); + _mm_storeu_si128((__m128i*)(alpha + x1), fx_); + } + } + #endif + for( ; x1 < bw; x1++ ) + { + int X = (X0 + adelta[x+x1]) >> (AB_BITS - INTER_BITS); + int Y = (Y0 + bdelta[x+x1]) >> (AB_BITS - INTER_BITS); + xy[x1*2] = saturate_cast(X >> INTER_BITS); + xy[x1*2+1] = saturate_cast(Y >> INTER_BITS); + alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + + (X & (INTER_TAB_SIZE-1))); + } + } + } + + if( interpolation == INTER_NEAREST ) + remap( src, dpart, _XY, Mat(), interpolation, borderType, borderValue ); + else + { + Mat _matA(bh, bw, CV_16U, A); + remap( src, dpart, _XY, _matA, interpolation, borderType, borderValue ); + } + } + } + } + +private: + const Mat src; + Mat dst; + int interpolation, borderType; + const Scalar borderValue; + int *adelta, *bdelta; + double *M; +}; + +} + + void cv::warpAffine( InputArray _src, OutputArray _dst, InputArray _M0, Size dsize, int flags, int borderType, const Scalar& borderValue ) @@ -2968,8 +3340,6 @@ void cv::warpAffine( InputArray _src, OutputArray _dst, if( dst.data == src.data ) src = src.clone(); - const int BLOCK_SZ = 64; - short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ]; double M[6]; Mat matM(2, 3, CV_64F, M); int interpolation = flags & INTER_MAX; @@ -2996,112 +3366,121 @@ void cv::warpAffine( InputArray _src, OutputArray _dst, M[2] = b1; M[5] = b2; } - int x, y, x1, y1, width = dst.cols, height = dst.rows; - AutoBuffer _abdelta(width*2); - int* adelta = &_abdelta[0], *bdelta = adelta + width; + int x; + AutoBuffer _abdelta(dst.cols*2); + int* adelta = &_abdelta[0], *bdelta = adelta + dst.cols; const int AB_BITS = MAX(10, (int)INTER_BITS); const int AB_SCALE = 1 << AB_BITS; - int round_delta = interpolation == INTER_NEAREST ? AB_SCALE/2 : AB_SCALE/INTER_TAB_SIZE/2; -#if CV_SSE2 - bool useSIMD = checkHardwareSupport(CV_CPU_SSE2); -#endif - for( x = 0; x < width; x++ ) + for( x = 0; x < dst.cols; x++ ) { adelta[x] = saturate_cast(M[0]*x*AB_SCALE); bdelta[x] = saturate_cast(M[3]*x*AB_SCALE); } - int bh0 = std::min(BLOCK_SZ/2, height); - int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, width); - bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, height); + Range range(0, dst.rows); + warpAffineInvoker invoker(src, dst, interpolation, borderType, + borderValue, adelta, bdelta, M); + parallel_for_(range, invoker); +} - for( y = 0; y < height; y += bh0 ) + +namespace cv +{ + +class warpPerspectiveInvoker : + public ParallelLoopBody +{ +public: + + warpPerspectiveInvoker(const Mat &_src, Mat &_dst, double *_M, int _interpolation, + int _borderType, const Scalar &_borderValue) : + ParallelLoopBody(), src(_src), dst(_dst), M(_M), interpolation(_interpolation), + borderType(_borderType), borderValue(_borderValue) { - for( x = 0; x < width; x += bw0 ) + } + + virtual void operator() (const Range& range) const + { + const int BLOCK_SZ = 32; + short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ]; + int x, y, x1, y1, width = dst.cols, height = dst.rows; + + int bh0 = std::min(BLOCK_SZ/2, height); + int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, width); + bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, height); + + for( y = range.start; y < range.end; y += bh0 ) { - int bw = std::min( bw0, width - x); - int bh = std::min( bh0, height - y); - - Mat _XY(bh, bw, CV_16SC2, XY), matA; - Mat dpart(dst, Rect(x, y, bw, bh)); - - for( y1 = 0; y1 < bh; y1++ ) + for( x = 0; x < width; x += bw0 ) { - short* xy = XY + y1*bw*2; - int X0 = saturate_cast((M[1]*(y + y1) + M[2])*AB_SCALE) + round_delta; - int Y0 = saturate_cast((M[4]*(y + y1) + M[5])*AB_SCALE) + round_delta; - - if( interpolation == INTER_NEAREST ) - for( x1 = 0; x1 < bw; x1++ ) - { - int X = (X0 + adelta[x+x1]) >> AB_BITS; - int Y = (Y0 + bdelta[x+x1]) >> AB_BITS; - xy[x1*2] = saturate_cast(X); - xy[x1*2+1] = saturate_cast(Y); - } - else + int bw = std::min( bw0, width - x); + int bh = std::min( bh0, range.end - y); // height + + Mat _XY(bh, bw, CV_16SC2, XY), matA; + Mat dpart(dst, Rect(x, y, bw, bh)); + + for( y1 = 0; y1 < bh; y1++ ) { - short* alpha = A + y1*bw; - x1 = 0; - #if CV_SSE2 - if( useSIMD ) - { - __m128i fxy_mask = _mm_set1_epi32(INTER_TAB_SIZE - 1); - __m128i XX = _mm_set1_epi32(X0), YY = _mm_set1_epi32(Y0); - for( ; x1 <= bw - 8; x1 += 8 ) + short* xy = XY + y1*bw*2; + double X0 = M[0]*x + M[1]*(y + y1) + M[2]; + double Y0 = M[3]*x + M[4]*(y + y1) + M[5]; + double W0 = M[6]*x + M[7]*(y + y1) + M[8]; + + if( interpolation == INTER_NEAREST ) + for( x1 = 0; x1 < bw; x1++ ) { - __m128i tx0, tx1, ty0, ty1; - tx0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(adelta + x + x1)), XX); - ty0 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(bdelta + x + x1)), YY); - tx1 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(adelta + x + x1 + 4)), XX); - ty1 = _mm_add_epi32(_mm_loadu_si128((const __m128i*)(bdelta + x + x1 + 4)), YY); - - tx0 = _mm_srai_epi32(tx0, AB_BITS - INTER_BITS); - ty0 = _mm_srai_epi32(ty0, AB_BITS - INTER_BITS); - tx1 = _mm_srai_epi32(tx1, AB_BITS - INTER_BITS); - ty1 = _mm_srai_epi32(ty1, AB_BITS - INTER_BITS); - - __m128i fx_ = _mm_packs_epi32(_mm_and_si128(tx0, fxy_mask), - _mm_and_si128(tx1, fxy_mask)); - __m128i fy_ = _mm_packs_epi32(_mm_and_si128(ty0, fxy_mask), - _mm_and_si128(ty1, fxy_mask)); - tx0 = _mm_packs_epi32(_mm_srai_epi32(tx0, INTER_BITS), - _mm_srai_epi32(tx1, INTER_BITS)); - ty0 = _mm_packs_epi32(_mm_srai_epi32(ty0, INTER_BITS), - _mm_srai_epi32(ty1, INTER_BITS)); - fx_ = _mm_adds_epi16(fx_, _mm_slli_epi16(fy_, INTER_BITS)); - - _mm_storeu_si128((__m128i*)(xy + x1*2), _mm_unpacklo_epi16(tx0, ty0)); - _mm_storeu_si128((__m128i*)(xy + x1*2 + 8), _mm_unpackhi_epi16(tx0, ty0)); - _mm_storeu_si128((__m128i*)(alpha + x1), fx_); + double W = W0 + M[6]*x1; + W = W ? 1./W : 0; + double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); + double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); + int X = saturate_cast(fX); + int Y = saturate_cast(fY); + + xy[x1*2] = saturate_cast(X); + xy[x1*2+1] = saturate_cast(Y); + } + else + { + short* alpha = A + y1*bw; + for( x1 = 0; x1 < bw; x1++ ) + { + double W = W0 + M[6]*x1; + W = W ? INTER_TAB_SIZE/W : 0; + double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); + double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); + int X = saturate_cast(fX); + int Y = saturate_cast(fY); + + xy[x1*2] = saturate_cast(X >> INTER_BITS); + xy[x1*2+1] = saturate_cast(Y >> INTER_BITS); + alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + + (X & (INTER_TAB_SIZE-1))); } } - #endif - for( ; x1 < bw; x1++ ) - { - int X = (X0 + adelta[x+x1]) >> (AB_BITS - INTER_BITS); - int Y = (Y0 + bdelta[x+x1]) >> (AB_BITS - INTER_BITS); - xy[x1*2] = saturate_cast(X >> INTER_BITS); - xy[x1*2+1] = saturate_cast(Y >> INTER_BITS); - alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + - (X & (INTER_TAB_SIZE-1))); - } } - } - - if( interpolation == INTER_NEAREST ) - remap( src, dpart, _XY, Mat(), interpolation, borderType, borderValue ); - else - { - Mat _matA(bh, bw, CV_16U, A); - remap( src, dpart, _XY, _matA, interpolation, borderType, borderValue ); + + if( interpolation == INTER_NEAREST ) + remap( src, dpart, _XY, Mat(), interpolation, borderType, borderValue ); + else + { + Mat _matA(bh, bw, CV_16U, A); + remap( src, dpart, _XY, _matA, interpolation, borderType, borderValue ); + } } } } + +private: + const Mat src; + Mat dst; + double* M; + int interpolation, borderType; + const Scalar borderValue; +}; + } - void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0, Size dsize, int flags, int borderType, const Scalar& borderValue ) { @@ -3113,8 +3492,6 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0, if( dst.data == src.data ) src = src.clone(); - const int BLOCK_SZ = 32; - short XY[BLOCK_SZ*BLOCK_SZ*2], A[BLOCK_SZ*BLOCK_SZ]; double M[9]; Mat matM(3, 3, CV_64F, M); int interpolation = flags & INTER_MAX; @@ -3132,71 +3509,9 @@ void cv::warpPerspective( InputArray _src, OutputArray _dst, InputArray _M0, if( !(flags & WARP_INVERSE_MAP) ) invert(matM, matM); - int x, y, x1, y1, width = dst.cols, height = dst.rows; - - int bh0 = std::min(BLOCK_SZ/2, height); - int bw0 = std::min(BLOCK_SZ*BLOCK_SZ/bh0, width); - bh0 = std::min(BLOCK_SZ*BLOCK_SZ/bw0, height); - - for( y = 0; y < height; y += bh0 ) - { - for( x = 0; x < width; x += bw0 ) - { - int bw = std::min( bw0, width - x); - int bh = std::min( bh0, height - y); - - Mat _XY(bh, bw, CV_16SC2, XY), matA; - Mat dpart(dst, Rect(x, y, bw, bh)); - - for( y1 = 0; y1 < bh; y1++ ) - { - short* xy = XY + y1*bw*2; - double X0 = M[0]*x + M[1]*(y + y1) + M[2]; - double Y0 = M[3]*x + M[4]*(y + y1) + M[5]; - double W0 = M[6]*x + M[7]*(y + y1) + M[8]; - - if( interpolation == INTER_NEAREST ) - for( x1 = 0; x1 < bw; x1++ ) - { - double W = W0 + M[6]*x1; - W = W ? 1./W : 0; - double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); - double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); - int X = saturate_cast(fX); - int Y = saturate_cast(fY); - - xy[x1*2] = saturate_cast(X); - xy[x1*2+1] = saturate_cast(Y); - } - else - { - short* alpha = A + y1*bw; - for( x1 = 0; x1 < bw; x1++ ) - { - double W = W0 + M[6]*x1; - W = W ? INTER_TAB_SIZE/W : 0; - double fX = std::max((double)INT_MIN, std::min((double)INT_MAX, (X0 + M[0]*x1)*W)); - double fY = std::max((double)INT_MIN, std::min((double)INT_MAX, (Y0 + M[3]*x1)*W)); - int X = saturate_cast(fX); - int Y = saturate_cast(fY); - - xy[x1*2] = saturate_cast(X >> INTER_BITS); - xy[x1*2+1] = saturate_cast(Y >> INTER_BITS); - alpha[x1] = (short)((Y & (INTER_TAB_SIZE-1))*INTER_TAB_SIZE + - (X & (INTER_TAB_SIZE-1))); - } - } - } - - if( interpolation == INTER_NEAREST ) - remap( src, dpart, _XY, Mat(), interpolation, borderType, borderValue ); - else - { - Mat _matA(bh, bw, CV_16U, A); - remap( src, dpart, _XY, _matA, interpolation, borderType, borderValue ); - } - } - } + Range range(0, dst.rows); + warpPerspectiveInvoker invoker(src, dst, M, interpolation, borderType, borderValue); + parallel_for_(range, invoker); } From da5aaab27788d32a9f4118b4a90667000c8282aa Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 22 Aug 2012 12:11:11 +0400 Subject: [PATCH 38/40] optimized gpu::integral for Kepler --- modules/core/include/opencv2/core/gpumat.hpp | 4 +- modules/gpu/src/cuda/integral_image.cu | 385 +++++++++++++++++++ modules/gpu/src/imgproc.cpp | 96 ++++- 3 files changed, 463 insertions(+), 22 deletions(-) create mode 100644 modules/gpu/src/cuda/integral_image.cu diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp index 989335925..e09f1bc4c 100644 --- a/modules/core/include/opencv2/core/gpumat.hpp +++ b/modules/core/include/opencv2/core/gpumat.hpp @@ -72,9 +72,11 @@ namespace cv { namespace gpu FEATURE_SET_COMPUTE_13 = 13, FEATURE_SET_COMPUTE_20 = 20, FEATURE_SET_COMPUTE_21 = 21, + FEATURE_SET_COMPUTE_30 = 30, GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, - NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13 + NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, + WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30 }; // Gives information about what GPU archs this OpenCV GPU module was diff --git a/modules/gpu/src/cuda/integral_image.cu b/modules/gpu/src/cuda/integral_image.cu new file mode 100644 index 000000000..ead0ddefe --- /dev/null +++ b/modules/gpu/src/cuda/integral_image.cu @@ -0,0 +1,385 @@ +/*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 bpied warranties, including, but not limited to, the bpied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "opencv2/gpu/device/common.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace imgproc + { + // Utility function to extract unsigned chars from an unsigned integer + __device__ uchar4 int_to_uchar4(unsigned int in) + { + uchar4 bytes; + bytes.x = (in && 0x000000ff) >> 0; + bytes.y = (in && 0x0000ff00) >> 8; + bytes.z = (in && 0x00ff0000) >> 16; + bytes.w = (in && 0xff000000) >> 24; + return bytes; + } + + __global__ void shfl_integral_horizontal(const PtrStep_ img, PtrStep_ integral) + { + #if __CUDA_ARCH__ >= 300 + __shared__ int sums[128]; + + const int id = threadIdx.x; + const int lane_id = id % warpSize; + const int warp_id = id / warpSize; + + const uint4 data = img(blockIdx.x, id); + + const uchar4 a = int_to_uchar4(data.x); + const uchar4 b = int_to_uchar4(data.y); + const uchar4 c = int_to_uchar4(data.z); + const uchar4 d = int_to_uchar4(data.w); + + int result[16]; + + result[0] = a.x; + result[1] = result[0] + a.y; + result[2] = result[1] + a.z; + result[3] = result[2] + a.w; + + result[4] = result[3] + b.x; + result[5] = result[4] + b.y; + result[6] = result[5] + b.z; + result[7] = result[6] + b.w; + + result[8] = result[7] + c.x; + result[9] = result[8] + c.y; + result[10] = result[9] + c.z; + result[11] = result[10] + c.w; + + result[12] = result[11] + d.x; + result[13] = result[12] + d.y; + result[14] = result[13] + d.z; + result[15] = result[14] + d.w; + + int sum = result[15]; + + // the prefix sum for each thread's 16 value is computed, + // now the final sums (result[15]) need to be shared + // with the other threads and add. To do this, + // the __shfl_up() instruction is used and a shuffle scan + // operation is performed to distribute the sums to the correct + // threads + #pragma unroll + for (int i = 1; i < 32; i *= 2) + { + const int n = __shfl_up(sum, i, 32); + + if (lane_id >= i) + { + #pragma unroll + for (int i = 0; i < 16; ++i) + result[i] += n; + + sum += n; + } + } + + // Now the final sum for the warp must be shared + // between warps. This is done by each warp + // having a thread store to shared memory, then + // having some other warp load the values and + // compute a prefix sum, again by using __shfl_up. + // The results are uniformly added back to the warps. + // last thread in the warp holding sum of the warp + // places that in shared + if (threadIdx.x % warpSize == warpSize - 1) + sums[warp_id] = result[15]; + + __syncthreads(); + + if (warp_id == 0) + { + int warp_sum = sums[lane_id]; + + #pragma unroll + for (int i = 1; i <= 32; i *= 2) + { + const int n = __shfl_up(warp_sum, i, 32); + + if (lane_id >= i) + warp_sum += n; + } + + sums[lane_id] = warp_sum; + } + + __syncthreads(); + + int blockSum = 0; + + // fold in unused warp + if (warp_id > 0) + { + blockSum = sums[warp_id - 1]; + + #pragma unroll + for (int i = 0; i < 16; ++i) + result[i] += blockSum; + } + + // assemble result + // Each thread has 16 values to write, which are + // now integer data (to avoid overflow). Instead of + // each thread writing consecutive uint4s, the + // approach shown here experiments using + // the shuffle command to reformat the data + // inside the registers so that each thread holds + // consecutive data to be written so larger contiguous + // segments can be assembled for writing. + + /* + For example data that needs to be written as + + GMEM[16] <- x0 x1 x2 x3 y0 y1 y2 y3 z0 z1 z2 z3 w0 w1 w2 w3 + but is stored in registers (r0..r3), in four threads (0..3) as: + + threadId 0 1 2 3 + r0 x0 y0 z0 w0 + r1 x1 y1 z1 w1 + r2 x2 y2 z2 w2 + r3 x3 y3 z3 w3 + + after apply __shfl_xor operations to move data between registers r1..r3: + + threadId 00 01 10 11 + x0 y0 z0 w0 + xor(01)->y1 x1 w1 z1 + xor(10)->z2 w2 x2 y2 + xor(11)->w3 z3 y3 x3 + + and now x0..x3, and z0..z3 can be written out in order by all threads. + + In the current code, each register above is actually representing + four integers to be written as uint4's to GMEM. + */ + + result[4] = __shfl_xor(result[4] , 1, 32); + result[5] = __shfl_xor(result[5] , 1, 32); + result[6] = __shfl_xor(result[6] , 1, 32); + result[7] = __shfl_xor(result[7] , 1, 32); + + result[8] = __shfl_xor(result[8] , 2, 32); + result[9] = __shfl_xor(result[9] , 2, 32); + result[10] = __shfl_xor(result[10], 2, 32); + result[11] = __shfl_xor(result[11], 2, 32); + + result[12] = __shfl_xor(result[12], 3, 32); + result[13] = __shfl_xor(result[13], 3, 32); + result[14] = __shfl_xor(result[14], 3, 32); + result[15] = __shfl_xor(result[15], 3, 32); + + uint4* integral_row = integral.ptr(blockIdx.x); + uint4 output; + + /////// + + if (threadIdx.x % 4 == 0) + output = make_uint4(result[0], result[1], result[2], result[3]); + + if (threadIdx.x % 4 == 1) + output = make_uint4(result[4], result[5], result[6], result[7]); + + if (threadIdx.x % 4 == 2) + output = make_uint4(result[8], result[9], result[10], result[11]); + + if (threadIdx.x % 4 == 3) + output = make_uint4(result[12], result[13], result[14], result[15]); + + integral_row[threadIdx.x % 4 + (threadIdx.x / 4) * 16] = output; + + /////// + + if (threadIdx.x % 4 == 2) + output = make_uint4(result[0], result[1], result[2], result[3]); + + if (threadIdx.x % 4 == 3) + output = make_uint4(result[4], result[5], result[6], result[7]); + + if (threadIdx.x % 4 == 0) + output = make_uint4(result[8], result[9], result[10], result[11]); + + if (threadIdx.x % 4 == 1) + output = make_uint4(result[12], result[13], result[14], result[15]); + + integral_row[(threadIdx.x + 2) % 4 + (threadIdx.x / 4) * 16 + 8] = output; + + // continuning from the above example, + // this use of __shfl_xor() places the y0..y3 and w0..w3 data + // in order. + + #pragma unroll + for (int i = 0; i < 16; ++i) + result[i] = __shfl_xor(result[i], 1, 32); + + if (threadIdx.x % 4 == 0) + output = make_uint4(result[0], result[1], result[2], result[3]); + + if (threadIdx.x % 4 == 1) + output = make_uint4(result[4], result[5], result[6], result[7]); + + if (threadIdx.x % 4 == 2) + output = make_uint4(result[8], result[9], result[10], result[11]); + + if (threadIdx.x % 4 == 3) + output = make_uint4(result[12], result[13], result[14], result[15]); + + integral_row[threadIdx.x % 4 + (threadIdx.x / 4) * 16 + 4] = output; + + /////// + + if (threadIdx.x % 4 == 2) + output = make_uint4(result[0], result[1], result[2], result[3]); + + if (threadIdx.x % 4 == 3) + output = make_uint4(result[4], result[5], result[6], result[7]); + + if (threadIdx.x % 4 == 0) + output = make_uint4(result[8], result[9], result[10], result[11]); + + if (threadIdx.x % 4 == 1) + output = make_uint4(result[12], result[13], result[14], result[15]); + + integral_row[(threadIdx.x + 2) % 4 + (threadIdx.x / 4) * 16 + 12] = output; + #endif + } + + // This kernel computes columnwise prefix sums. When the data input is + // the row sums from above, this completes the integral image. + // The approach here is to have each block compute a local set of sums. + // First , the data covered by the block is loaded into shared memory, + // then instead of performing a sum in shared memory using __syncthreads + // between stages, the data is reformatted so that the necessary sums + // occur inside warps and the shuffle scan operation is used. + // The final set of sums from the block is then propgated, with the block + // computing "down" the image and adding the running sum to the local + // block sums. + __global__ void shfl_integral_vertical(DevMem2D_ integral) + { + #if __CUDA_ARCH__ >= 300 + __shared__ unsigned int sums[32][9]; + + const int tidx = blockIdx.x * blockDim.x + threadIdx.x; + const int lane_id = tidx % 8; + + if (tidx >= integral.cols) + return; + + sums[threadIdx.x][threadIdx.y] = 0; + __syncthreads(); + + unsigned int stepSum = 0; + + for (int y = threadIdx.y; y < integral.rows; y += blockDim.y) + { + unsigned int* p = integral.ptr(y) + tidx; + + unsigned int sum = *p; + + sums[threadIdx.x][threadIdx.y] = sum; + __syncthreads(); + + // place into SMEM + // shfl scan reduce the SMEM, reformating so the column + // sums are computed in a warp + // then read out properly + const int j = threadIdx.x % 8; + const int k = threadIdx.x / 8 + threadIdx.y * 4; + + int partial_sum = sums[k][j]; + + for (int i = 1; i <= 8; i *= 2) + { + int n = __shfl_up(partial_sum, i, 32); + + if (lane_id >= i) + partial_sum += n; + } + + sums[k][j] = partial_sum; + __syncthreads(); + + if (threadIdx.y > 0) + sum += sums[threadIdx.x][threadIdx.y - 1]; + + sum += stepSum; + stepSum += sums[threadIdx.x][blockDim.y - 1]; + + __syncthreads(); + + *p = sum; + } + #endif + } + + void shfl_integral_gpu(DevMem2Db img, DevMem2D_ integral, cudaStream_t stream) + { + { + // each thread handles 16 values, use 1 block/row + const int block = img.cols / 16; + + // launch 1 block / row + const int grid = img.rows; + + cudaSafeCall( cudaFuncSetCacheConfig(shfl_integral_horizontal, cudaFuncCachePreferL1) ); + + shfl_integral_horizontal<<>>((DevMem2D_) img, (DevMem2D_) integral); + cudaSafeCall( cudaGetLastError() ); + } + + { + const dim3 block(32, 8); + const dim3 grid(divUp(integral.cols, block.x), 1); + + shfl_integral_vertical<<>>(integral); + cudaSafeCall( cudaGetLastError() ); + } + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + } +}}} diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index fe1ad7bd8..5b8fb9c05 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -223,7 +223,7 @@ void cv::gpu::reprojectImageTo3D(const GpuMat& disp, GpuMat& xyz, const Mat& Q, using namespace cv::gpu::device::imgproc; typedef void (*func_t)(const DevMem2Db disp, DevMem2Db xyz, const float* q, cudaStream_t stream); - static const func_t funcs[2][4] = + static const func_t funcs[2][4] = { {reprojectImageTo3D_gpu, 0, 0, reprojectImageTo3D_gpu}, {reprojectImageTo3D_gpu, 0, 0, reprojectImageTo3D_gpu} @@ -533,32 +533,86 @@ void cv::gpu::integral(const GpuMat& src, GpuMat& sum, Stream& s) integralBuffered(src, sum, buffer, s); } +namespace cv { namespace gpu { namespace device +{ + namespace imgproc + { + void shfl_integral_gpu(DevMem2Db img, DevMem2D_ integral, cudaStream_t stream); + } +}}} + void cv::gpu::integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer, Stream& s) { CV_Assert(src.type() == CV_8UC1); - if (sum.cols != src.cols + 1 && sum.rows != src.rows + 1) - sum.create(src.rows + 1, src.cols + 1, CV_32S); - - NcvSize32u roiSize; - roiSize.width = src.cols; - roiSize.height = src.rows; - - cudaDeviceProp prop; - cudaSafeCall( cudaGetDeviceProperties(&prop, cv::gpu::getDevice()) ); - - Ncv32u bufSize; - ncvSafeCall( nppiStIntegralGetSize_8u32u(roiSize, &bufSize, prop) ); - ensureSizeIsEnough(1, bufSize, CV_8UC1, buffer); cudaStream_t stream = StreamAccessor::getStream(s); - NppStStreamHandler h(stream); + DeviceInfo info; - ncvSafeCall( nppiStIntegral_8u32u_C1R(const_cast(src.ptr()), static_cast(src.step), - sum.ptr(), static_cast(sum.step), roiSize, buffer.ptr(), bufSize, prop) ); + if (info.supports(WARP_SHUFFLE_FUNCTIONS)) + { + GpuMat src16; - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); + if (src.cols % 16 == 0) + src16 = src; + else + { + ensureSizeIsEnough(src.rows, ((src.cols + 15) / 16) * 16, src.type(), buffer); + + GpuMat inner = buffer(Rect(0, 0, src.cols, src.rows)); + + if (s) + { + s.enqueueMemSet(buffer, Scalar::all(0)); + s.enqueueCopy(src, inner); + } + else + { + buffer.setTo(Scalar::all(0)); + src.copyTo(inner); + } + + src16 = buffer; + } + + sum.create(src16.rows + 1, src16.cols + 1, CV_32SC1); + + if (s) + s.enqueueMemSet(sum, Scalar::all(0)); + else + sum.setTo(Scalar::all(0)); + + GpuMat inner = sum(Rect(1, 1, src16.cols, src16.rows)); + + cv::gpu::device::imgproc::shfl_integral_gpu(src16, inner, stream); + + if (src16.cols != src.cols) + sum = sum(Rect(0, 0, src.cols + 1, src.rows + 1)); + } + else + { + sum.create(src.rows + 1, src.cols + 1, CV_32SC1); + + NcvSize32u roiSize; + roiSize.width = src.cols; + roiSize.height = src.rows; + + cudaDeviceProp prop; + cudaSafeCall( cudaGetDeviceProperties(&prop, cv::gpu::getDevice()) ); + + Ncv32u bufSize; + ncvSafeCall( nppiStIntegralGetSize_8u32u(roiSize, &bufSize, prop) ); + ensureSizeIsEnough(1, bufSize, CV_8UC1, buffer); + + + NppStStreamHandler h(stream); + + ncvSafeCall( nppiStIntegral_8u32u_C1R(const_cast(src.ptr()), static_cast(src.step), + sum.ptr(), static_cast(sum.step), roiSize, buffer.ptr(), bufSize, prop) ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } } ////////////////////////////////////////////////////////////////////////////// @@ -1340,7 +1394,7 @@ Size cv::gpu::ConvolveBuf::estimateBlockSize(Size result_size, Size /*templ_size int width = (result_size.width + 2) / 3; int height = (result_size.height + 2) / 3; width = std::min(width, result_size.width); - height = std::min(height, result_size.height); + height = std::min(height, result_size.height); return Size(width, height); } @@ -1380,7 +1434,7 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, cufftHandle planR2C, planC2R; cufftSafeCall(cufftPlan2d(&planC2R, dft_size.height, dft_size.width, CUFFT_C2R)); - cufftSafeCall(cufftPlan2d(&planR2C, dft_size.height, dft_size.width, CUFFT_R2C)); + cufftSafeCall(cufftPlan2d(&planR2C, dft_size.height, dft_size.width, CUFFT_R2C)); cufftSafeCall( cufftSetStream(planR2C, StreamAccessor::getStream(stream)) ); cufftSafeCall( cufftSetStream(planC2R, StreamAccessor::getStream(stream)) ); From e95bc7d502ce74748cde30c48bc54e360e039fd1 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 22 Aug 2012 13:33:13 +0400 Subject: [PATCH 39/40] fixed ios camera timing (patch by Eduard Feicho) --- .../highgui/include/opencv2/highgui/cap_ios.h | 5 +- modules/highgui/src/cap_ios_video_camera.mm | 149 +++++------------- 2 files changed, 43 insertions(+), 111 deletions(-) diff --git a/modules/highgui/include/opencv2/highgui/cap_ios.h b/modules/highgui/include/opencv2/highgui/cap_ios.h index cc6668ace..26a28c077 100644 --- a/modules/highgui/include/opencv2/highgui/cap_ios.h +++ b/modules/highgui/include/opencv2/highgui/cap_ios.h @@ -80,7 +80,6 @@ @property (nonatomic, retain) UIView* parentView; -- (void)pause; - (void)start; - (void)stop; - (void)switchCameras; @@ -120,6 +119,8 @@ AVAssetWriterInput* recordAssetWriterInput; AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor; AVAssetWriter* recordAssetWriter; + + CMTime lastSampleTime; } @@ -134,6 +135,8 @@ - (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; - (void)layoutPreviewLayer; - (void)saveVideo; +- (NSURL *)videoFileURL; + @end diff --git a/modules/highgui/src/cap_ios_video_camera.mm b/modules/highgui/src/cap_ios_video_camera.mm index 6f7bfa20f..0a162ebea 100644 --- a/modules/highgui/src/cap_ios_video_camera.mm +++ b/modules/highgui/src/cap_ios_video_camera.mm @@ -98,90 +98,29 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; { [super start]; - if (self.recordVideo == YES) { -// [self.videoFileOutput startRecordingToOutputFileURL:[self tempFileURL] recordingDelegate:self]; - + if (self.recordVideo == YES) { NSError* error; - if ([[NSFileManager defaultManager] fileExistsAtPath:[self tempFileString]]) [[NSFileManager defaultManager] removeItemAtPath:[self tempFileString] error:&error]; + if ([[NSFileManager defaultManager] fileExistsAtPath:[self videoFileString]]) { + [[NSFileManager defaultManager] removeItemAtPath:[self videoFileString] error:&error]; + } if (error == nil) { - NSLog(@"[Camera] Delete file %@", [self tempFileString]); - } - - - BOOL started = [self.recordAssetWriter startWriting]; - [self.recordAssetWriter startSessionAtSourceTime:kCMTimeZero]; - - NSLog(@"[Camera] Session started? %d", started); - - if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { - NSLog(@"AVAssetWriter status: unknown"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { - NSLog(@"AVAssetWriter status: writing"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { - NSLog(@"AVAssetWriter status: completed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { - NSLog(@"AVAssetWriter status: failed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { - NSLog(@"AVAssetWriter status: cancelled"); - } - - if (self.recordAssetWriter.status != AVAssetWriterStatusWriting) { - NSLog(@"[Camera] Recording Error: asset writer status is not writing: %@", self.recordAssetWriter.error); - } else { - NSLog(@"[Camera] Recording started"); + NSLog(@"[Camera] Delete file %@", [self videoFileString]); } } } -- (void)pause; -{ - [super pause]; - if (self.recordVideo == YES) { -// [self.videoFileOutput stopRecording]; - - - if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { - NSLog(@"AVAssetWriter status: unknown"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { - NSLog(@"AVAssetWriter status: writing"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { - NSLog(@"AVAssetWriter status: completed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { - NSLog(@"AVAssetWriter status: failed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { - NSLog(@"AVAssetWriter status: cancelled"); - } - - if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { - [self.recordAssetWriter finishWriting]; - NSLog(@"[Camera] recording stopped"); - } else { - NSLog(@"[Camera] Recording Error: asset writer status is not writing"); - } - } -} - - - (void)stop; { [super stop]; - if (self.recordVideo == YES) { - NSLog(@"recording stop"); - if (self.recordAssetWriter.status == AVAssetWriterStatusUnknown) { - NSLog(@"AVAssetWriter status: unknown"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { - NSLog(@"AVAssetWriter status: writing"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCompleted) { - NSLog(@"AVAssetWriter status: completed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusFailed) { - NSLog(@"AVAssetWriter status: failed"); - } else if (self.recordAssetWriter.status == AVAssetWriterStatusCancelled) { - NSLog(@"AVAssetWriter status: cancelled"); - } - + self.videoDataOutput = nil; + if (videoDataOutputQueue) { + dispatch_release(videoDataOutputQueue); + } + + if (self.recordVideo == YES) { if (self.recordAssetWriter.status == AVAssetWriterStatusWriting) { [self.recordAssetWriter finishWriting]; @@ -194,11 +133,6 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; self.recordAssetWriterInput = nil; self.recordPixelBufferAdaptor = nil; } - - self.videoDataOutput = nil; - if (videoDataOutputQueue) { - dispatch_release(videoDataOutputQueue); - } [self.customPreviewLayer removeFromSuperlayer]; self.customPreviewLayer = nil; @@ -405,15 +339,6 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; - (void)createVideoFileOutput; { - /* - if (self.recordVideo == YES) { - self.videoFileOutput = [[AVCaptureMovieFileOutput alloc] init]; - if ( [self.captureSession canAddOutput:self.videoFileOutput] ) { - [self.captureSession addOutput:self.videoFileOutput]; - } - } - */ - /* Video File Output in H.264, via AVAsserWriter */ NSLog(@"Create Video with dimensions %dx%d", self.imageWidth, self.imageHeight); @@ -426,21 +351,18 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; self.recordAssetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:outputSettings]; - - /* I'm going to push pixel buffers to it, so will need a - AVAssetWriterPixelBufferAdaptor, to expect the same 32BGRA input as I've - asked the AVCaptureVideDataOutput to supply */ + int pixelBufferFormat = (self.grayscaleMode == YES) ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange : kCVPixelFormatType_32BGRA; self.recordPixelBufferAdaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:self.recordAssetWriterInput - sourcePixelBufferAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:pixelBufferFormat], kCVPixelBufferPixelFormatTypeKey,nil]]; + sourcePixelBufferAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:pixelBufferFormat], kCVPixelBufferPixelFormatTypeKey, nil]]; NSError* error = nil; - NSLog(@"Create AVAssetWriter with url: %@", [self tempFileURL]); - self.recordAssetWriter = [AVAssetWriter assetWriterWithURL:[self tempFileURL] + NSLog(@"Create AVAssetWriter with url: %@", [self videoFileURL]); + self.recordAssetWriter = [AVAssetWriter assetWriterWithURL:[self videoFileURL] fileType:AVFileTypeMPEG4 error:&error]; if (error != nil) { @@ -448,10 +370,9 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; } [self.recordAssetWriter addInput:self.recordAssetWriterInput]; - self.recordAssetWriterInput.expectsMediaDataInRealTime = NO; + self.recordAssetWriterInput.expectsMediaDataInRealTime = YES; NSLog(@"[Camera] created AVAssetWriter"); - } @@ -580,8 +501,6 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; } - - // render buffer dispatch_sync(dispatch_get_main_queue(), ^{ self.customPreviewLayer.contents = (__bridge id)dstImage; @@ -589,16 +508,26 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; if (self.recordVideo == YES) { - // a very dense way to keep track of the time at which this frame - // occurs relative to the output stream, but it's just an example! - - // TODO reset frame number - static int64_t frameNumber = 0; - if (self.recordAssetWriterInput.readyForMoreMediaData) { - [self.recordPixelBufferAdaptor appendPixelBuffer:imageBuffer - withPresentationTime:CMTimeMake(frameNumber, self.defaultFPS)]; + lastSampleTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); +// CMTimeShow(lastSampleTime); + if (self.recordAssetWriter.status != AVAssetWriterStatusWriting) { + [self.recordAssetWriter startWriting]; + [self.recordAssetWriter startSessionAtSourceTime:lastSampleTime]; + if (self.recordAssetWriter.status != AVAssetWriterStatusWriting) { + NSLog(@"[Camera] Recording Error: asset writer status is not writing: %@", self.recordAssetWriter.error); + return; + } else { + NSLog(@"[Camera] Video recording started"); + } } - frameNumber++; + + if (self.recordAssetWriterInput.readyForMoreMediaData) { + if (! [self.recordPixelBufferAdaptor appendPixelBuffer:imageBuffer + withPresentationTime:lastSampleTime] ) { + NSLog(@"Video Writing Error"); + } + } + } @@ -627,14 +556,14 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; } ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; - if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[self tempFileURL]]) { - [library writeVideoAtPathToSavedPhotosAlbum:[self tempFileURL] + if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[self videoFileURL]]) { + [library writeVideoAtPathToSavedPhotosAlbum:[self videoFileURL] completionBlock:^(NSURL *assetURL, NSError *error){}]; } } -- (NSURL *)tempFileURL; +- (NSURL *)videoFileURL; { NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; NSURL *outputURL = [NSURL fileURLWithPath:outputPath]; @@ -647,7 +576,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; -- (NSString *)tempFileString; +- (NSString *)videoFileString; { NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; return outputPath; From bbf679267ae1ffdd4bdedb5497a8e03ed059678b Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 22 Aug 2012 15:48:57 +0400 Subject: [PATCH 40/40] modified facedetect to properly display very oblong objects and optionally flip image horizontally (for profile face detection). Added LBP cascades by Attila Novak for profile face detection and silverware detection (those are results of GSoC 2012) --- data/lbpcascades/lbpcascade_profileface.xml | 1275 ++++++++++++++++++ data/lbpcascades/lbpcascade_silverware.xml | 1279 +++++++++++++++++++ samples/c/facedetect.cpp | 90 +- 3 files changed, 2615 insertions(+), 29 deletions(-) create mode 100755 data/lbpcascades/lbpcascade_profileface.xml create mode 100755 data/lbpcascades/lbpcascade_silverware.xml diff --git a/data/lbpcascades/lbpcascade_profileface.xml b/data/lbpcascades/lbpcascade_profileface.xml new file mode 100755 index 000000000..a9e843730 --- /dev/null +++ b/data/lbpcascades/lbpcascade_profileface.xml @@ -0,0 +1,1275 @@ + + + + + BOOST + LBP + 34 + 20 + + GAB + 9.9500000476837158e-001 + 3.0000001192092896e-001 + 9.4999999999999996e-001 + 1 + 100 + + 256 + 1 + 16 + + + <_> + 4 + -5.9480339288711548e-001 + + <_> + + 0 -1 114 -2360321 -82228595 -771518211 -713436773 + -1060447799 -810385271 -2004135683 -2566104 + + -8.0942183732986450e-001 5.9530025720596313e-001 + <_> + + 0 -1 54 -649134608 -1060077114 1375916272 -719981432 + 1073801352 33024 281198795 -5246465 + + -7.7979278564453125e-001 5.4052764177322388e-001 + <_> + + 0 -1 12 -960266913 -495857599 -1068498864 -867970987 + 457398579 -1174173695 1749041235 1849162079 + + -8.0028575658798218e-001 5.0435048341751099e-001 + <_> + + 0 -1 120 -1228145793 -807247727 18059735 -138644520 + 998980043 -41250583 673112549 -1930366540 + + -7.7902388572692871e-001 4.9006074666976929e-001 + + <_> + 6 + -5.4879629611968994e-001 + + <_> + + 0 -1 6 -254346881 -746143606 -1039596583 1963430479 + -263790449 -1073545213 698505999 -1349357 + + -6.6315788030624390e-001 6.0000002384185791e-001 + <_> + + 0 -1 112 -134225985 -684228389 -988213089 -684716007 + -1966960899 -896630615 152815840 -864497420 + + -7.0195454359054565e-001 5.8843690156936646e-001 + <_> + + 0 -1 53 -35923461 520818827 -1862167847 856916291 68141197 + 2072530978 304306417 526079163 + + -6.4593964815139771e-001 5.7274609804153442e-001 + <_> + + 0 -1 101 -2097665 -1781432163 588321018 -1677405808 + -1968469982 -1450147831 -1467632684 -593693808 + + -7.2959578037261963e-001 4.9470889568328857e-001 + <_> + + 0 -1 79 -205847273 -1088716541 285266431 1393693056 + 293931101 -1634205688 -452263692 -111136684 + + -7.0331865549087524e-001 5.2564400434494019e-001 + <_> + + 0 -1 126 579801457 -670613495 -1065269989 -117095565 + -1295163359 -779534335 -1744220101 -1355860 + + -7.5121974945068359e-001 4.5217981934547424e-001 + + <_> + 4 + -4.3886357545852661e-001 + + <_> + + 0 -1 20 -346563793 1217040543 -1324639677 206303367 + -260894653 1165249072 1359168335 1652518863 + + -8.3054625988006592e-001 5.5417186021804810e-001 + <_> + + 0 -1 69 -925898078 -917290147 -2147368790 -1995968378 + 1203961890 1765910571 789128481 -4201473 + + -7.5220447778701782e-001 6.1290657520294189e-001 + <_> + + 0 -1 7 -425790473 -368916470 -1065172848 -1877712894 + -1067360254 -847191997 1342400518 -680037517 + + -7.8469508886337280e-001 5.9731280803680420e-001 + <_> + + 0 -1 5 -260315918 -1567751150 -805289977 1721229843 + 1644296976 1954742530 824530213 -8392601 + + -7.3686408996582031e-001 5.6347119808197021e-001 + + <_> + 6 + -4.6629825234413147e-001 + + <_> + + 0 -1 111 -67634177 -72175593 -246181185 -144772036 + -1465917455 -1426934837 -345249307 -539041852 + + -7.1692305803298950e-001 5.5034482479095459e-001 + <_> + + 0 -1 47 -1048705 -96415158 -1996126927 67301684 -659873481 + 1800863745 -402143413 1647570815 + + -7.6134461164474487e-001 4.7370144724845886e-001 + <_> + + 0 -1 119 1905247351 -1111526689 1426654203 -116427277 + 1731664419 -81052249 1051905317 -1628448513 + + -5.9460461139678955e-001 6.1952447891235352e-001 + <_> + + 0 -1 2 578486263 -2115313530 -788268733 -1122507629 + -343408719 2127242147 -85406399 -37295 + + -6.0801470279693604e-001 5.8719038963317871e-001 + <_> + + 0 -1 127 -1147176065 52139167 21156225 -540503783 -771529299 + -33325024 -671045243 -1913073360 + + -7.4383884668350220e-001 5.1643568277359009e-001 + <_> + + 0 -1 93 -319091633 -58633529 1166906391 1854443149 + 1267403009 -1198817246 1208634960 -35661669 + + -6.8595260381698608e-001 5.5931246280670166e-001 + + <_> + 8 + -6.0948312282562256e-001 + + <_> + + 0 -1 102 -747899393 -543522675 545333467 -34230241 + -1572626245 -17790840 -1182162691 -1078427420 + + -6.0826772451400757e-001 4.6491229534149170e-001 + <_> + + 0 -1 38 -103812609 503024467 -2121908081 722834075 + 1375757518 2022089353 197321677 2077719203 + + -6.2948691844940186e-001 4.8044654726982117e-001 + <_> + + 0 -1 19 -774429826 -607461158 1158791644 -971587409 + -1732167611 2015560010 -1278549257 -159911361 + + -5.9694272279739380e-001 4.7999730706214905e-001 + <_> + + 0 -1 122 735837495 -875325281 152208339 -741020481 + -1471817477 -1165246433 -1450830159 -1696546384 + + -6.4947181940078735e-001 4.2661586403846741e-001 + <_> + + 0 -1 104 -629063145 -49708711 50692231 1973945160 157637120 + 2056259593 1771350547 -78911181 + + -6.2496536970138550e-001 4.4524449110031128e-001 + <_> + + 0 -1 67 -74189973 -803307502 688005268 1600057378 -131870050 + -1600503318 571446250 -386668002 + + -5.5046343803405762e-001 5.6090569496154785e-001 + <_> + + 0 -1 81 586347861 -2071051852 -250078020 -1455374076 + 546287843 1216708619 -1853707673 -35130912 + + -6.3877129554748535e-001 4.7911971807479858e-001 + <_> + + 0 -1 22 -1436568057 1555188001 164315 2084672259 1809869105 + 1132626050 1223430266 -596124761 + + -6.4428490400314331e-001 4.7921949625015259e-001 + + <_> + 8 + -5.4387503862380981e-001 + + <_> + + 0 -1 44 -783680003 -771883143 -302055943 -5898247 -253370375 + -1996628131 1625947386 -2004157446 + + -5.2870607376098633e-001 5.9474670886993408e-001 + <_> + + 0 -1 49 -586034977 -41205679 352424062 -163145456 151126042 + -1171652503 1208036058 -9019322 + + -5.6763833761215210e-001 4.8789894580841064e-001 + <_> + + 0 -1 39 1402589836 1363509256 103583 823365787 -1861443377 + 412131360 539718283 1002160350 + + -5.9899079799652100e-001 4.9562713503837585e-001 + <_> + + 0 -1 113 -783429121 -1559215981 286355953 -794820602 + 461510679 -611662910 -2136237584 -96429424 + + -6.3842493295669556e-001 4.3330931663513184e-001 + <_> + + 0 -1 99 -1365839532 -1291265163 1091604493 965968977 + 147472779 -1466925055 -2013090821 -1410703205 + + -5.8633142709732056e-001 5.0152444839477539e-001 + <_> + + 0 -1 26 1846469631 -788479850 268796195 -754872317 + 1630603451 -896532480 1208092751 -72652777 + + -5.9243172407150269e-001 4.7917708754539490e-001 + <_> + + 0 -1 85 -715395062 -113037167 1342198133 -552594287 + 411123713 11059209 -2012512153 -877809205 + + -6.9079184532165527e-001 4.2610234022140503e-001 + <_> + + 0 -1 100 -526391817 -921022135 -1593630697 671093393 + -2004270453 -1962835840 -1870413655 -1597095644 + + -6.5030521154403687e-001 4.4748127460479736e-001 + + <_> + 8 + -6.3195121288299561e-001 + + <_> + + 0 -1 109 -674761315 -581726065 352407899 -83717423 + -660870145 -1165915966 -326837763 -927182608 + + -7.3185729980468750e-001 3.3258172869682312e-001 + <_> + + 0 -1 97 860755579 -707063662 1361264863 1065505299 + -1022866435 -1776123776 -1865661700 -1615196136 + + -6.1147916316986084e-001 3.7205791473388672e-001 + <_> + + 0 -1 15 -678435969 -106962866 268652561 -826396597 + -802066313 1931092070 1208025439 1211582847 + + -6.8679082393646240e-001 3.6285603046417236e-001 + <_> + + 0 -1 86 -1573074550 -2080337595 299991 110482176 268552379 + -310373944 596185787 -1428952165 + + -6.4654982089996338e-001 4.1456297039985657e-001 + <_> + + 0 -1 30 -72637790 -1258143612 1342937104 -544352374 + -1046875163 -121076606 -786059128 -71702400 + + -5.2772462368011475e-001 4.9787566065788269e-001 + <_> + + 0 -1 89 -683288417 -218031996 33734999 -16115386 -2013259561 + -2008907509 -1978533232 -352342880 + + -5.2718847990036011e-001 5.2839303016662598e-001 + <_> + + 0 -1 10 -268764033 -1078984772 -65537 -281182212 -524291 -1 + -8489090 -4227265 + + -5.0513482093811035e-001 5.8522778749465942e-001 + <_> + + 0 -1 82 -570445845 784662143 -268435661 -1292701712 + -436263043 -1367507075 -671091243 -751108132 + + -5.2438414096832275e-001 5.4709094762802124e-001 + + <_> + 8 + -5.9874147176742554e-001 + + <_> + + 0 -1 27 -721421649 -1001940437 2300046 -720004829 -792686333 + 1908900882 -160055232 -134763633 + + -5.7692307233810425e-001 3.7921348214149475e-001 + <_> + + 0 -1 78 -1764279809 -1755824061 1937871313 -42069793 + -1241158993 -1196293937 -1576828673 -70371296 + + -4.7039109468460083e-001 4.8607903718948364e-001 + <_> + + 0 -1 29 -795875130 432079111 285457049 -620658641 -780072971 + 1158283432 -226254016 1839935243 + + -6.2938809394836426e-001 4.1353255510330200e-001 + <_> + + 0 -1 33 -37236389 1654493543 202129823 1788182787 + -1186162321 1912913933 -122942838 1968176815 + + -5.9031385183334351e-001 4.1488575935363770e-001 + <_> + + 0 -1 88 1903888863 -286828472 -2125248034 -623115882 + -268301806 -894826357 -2046633148 -696873056 + + -6.3875061273574829e-001 4.0209171175956726e-001 + <_> + + 0 -1 123 -87223501 -1873424249 -1878929092 -586710990 + -643825151 -1039040192 -285122488 -264093 + + -5.4196298122406006e-001 4.5856228470802307e-001 + <_> + + 0 -1 52 -780030833 1363755203 -385150929 25502018 1214818435 + -1020786271 -1870036478 1200354241 + + -5.2826374769210815e-001 5.3351372480392456e-001 + <_> + + 0 -1 84 -1724706499 -184429355 620844509 -179010317 + -1610327896 -341801844 -1190328066 1755915264 + + -5.7672232389450073e-001 4.4138705730438232e-001 + + <_> + 9 + -5.4533123970031738e-001 + + <_> + + 0 -1 48 -254347649 -565919658 1079050328 1090502875 + 1895985446 2013437961 -916419445 -53481573 + + -5.8105266094207764e-001 3.3599999547004700e-001 + <_> + + 0 -1 65 2030928895 1438877010 1124143121 258207763 + 1361199276 1527410834 2072519624 1004267991 + + -5.9629368782043457e-001 3.6112698912620544e-001 + <_> + + 0 -1 45 -247204964 -242712316 54544644 892459288 1888023456 + -2138044280 -802615208 13199500 + + -6.5467655658721924e-001 3.0486112833023071e-001 + <_> + + 0 -1 3 -430509345 -1865653973 554091143 -1069121312 + 1091180718 50577994 -1031731181 -211321225 + + -5.8759629726409912e-001 3.9526104927062988e-001 + <_> + + 0 -1 106 -741412064 -255623164 1090945848 -1687760764 + 42428760 -1064762741 -1861683196 -81029101 + + -6.5875691175460815e-001 3.4154877066612244e-001 + <_> + + 0 -1 128 -464010241 762112 285299147 -589082223 1373135017 + -2138955645 1057005712 -526876236 + + -6.5968728065490723e-001 3.3614772558212280e-001 + <_> + + 0 -1 80 -666744719 -635780797 33637339 -887860848 + -1073532217 -108904320 440608996 -1100753973 + + -5.0520354509353638e-001 4.4810971617698669e-001 + <_> + + 0 -1 28 -1580738774 -1506653838 302055688 -721223615 + 1427604224 -1566332144 1078565791 -558431977 + + -5.5560898780822754e-001 4.3426483869552612e-001 + <_> + + 0 -1 103 957796629 538644536 352997725 80838797 453085387 + -1165492198 285346042 1487077737 + + -5.5915868282318115e-001 4.0778505802154541e-001 + + <_> + 9 + -6.7299038171768188e-001 + + <_> + + 0 -1 0 -882973185 -620584737 279035921 -673986422 + -1568464349 -2105466877 1468391879 -38825 + + -5.7544225454330444e-001 3.4235453605651855e-001 + <_> + + 0 -1 90 -1820101795 -1336770299 285245717 -57216724 + -502134548 -1425341984 -1475618680 -1195896480 + + -6.6810834407806396e-001 2.7653357386589050e-001 + <_> + + 0 -1 9 -100197449 -457893579 200991 1964749325 -754875920 + 1897044675 1669843618 -70792821 + + -4.9064287543296814e-001 4.3120625615119934e-001 + <_> + + 0 -1 117 -792114173 -544111547 537001999 2034569362 + -1065213888 1630052634 -1450583484 -532405661 + + -6.4218991994857788e-001 3.6113587021827698e-001 + <_> + + 0 -1 107 -1564241697 -1429683702 -2062974587 -1900539448 + -1040078205 -394262006 -188628336 -390485984 + + -5.9181970357894897e-001 3.5756480693817139e-001 + <_> + + 0 -1 4 1893434787 -1945108258 82458 -318734161 -939347837 + 684196040 1078496869 2133023515 + + -6.1955446004867554e-001 3.4674292802810669e-001 + <_> + + 0 -1 31 -196247204 1964277780 -1810886012 21827851 + -364280891 -1062338560 -536741128 -362562814 + + -5.2849757671356201e-001 4.1380330920219421e-001 + <_> + + 0 -1 61 -1929140897 353472529 -721412674 -1228123782 + -392951233 -1442693096 672800826 -232914898 + + -5.7934975624084473e-001 3.9208874106407166e-001 + <_> + + 0 -1 72 -1004361296 -1069243858 268710018 1393598601 + 213956864 417530145 -912735606 1327495627 + + -7.5585323572158813e-001 2.6728668808937073e-001 + + <_> + 9 + -7.1303337812423706e-001 + + <_> + + 0 -1 23 -557797393 1524138462 277074064 -737259367 + -1878818960 -81600384 -1740109301 -59267505 + + -6.7397260665893555e-001 1.9793814420700073e-001 + <_> + + 0 -1 42 -1222377543 960610456 -2013138684 -989277927 + -1010064731 -802979830 -645806439 -885143219 + + -4.5935314893722534e-001 4.1904711723327637e-001 + <_> + + 0 -1 124 -783292542 -728791016 1342570700 1481418249 + 1258825942 -1580563964 -1178136688 -272306640 + + -6.3012123107910156e-001 2.9463621973991394e-001 + <_> + + 0 -1 46 1369396573 -188563225 22085642 -1005861886 + 2023260232 -1123842045 -2146991925 1245170171 + + -5.2092707157135010e-001 3.9743596315383911e-001 + <_> + + 0 -1 64 1540188400 1976259599 -805025279 864127692 544944 + 1484935304 -2147056504 1002584738 + + -6.5315401554107666e-001 3.1758561730384827e-001 + <_> + + 0 -1 77 -188606981 -1873391210 16842830 -117157654 + -1576842600 -1454767992 -518835576 -1625272280 + + -5.8580338954925537e-001 3.4936144948005676e-001 + <_> + + 0 -1 18 -473497030 -477572088 16842905 -12164860 184698994 + 1350566019 -2143169323 1405313030 + + -6.0962837934494019e-001 3.0044576525688171e-001 + <_> + + 0 -1 92 -528022006 -611028904 1075937757 -577660920 + 1073809492 -1341620207 -1475846395 -162412743 + + -6.6547930240631104e-001 3.1993752717971802e-001 + <_> + + 0 -1 116 -2062347245 35311783 406966429 -640155632 + -1904205761 -2012610494 399245455 -937752211 + + -4.8515367507934570e-001 4.3642494082450867e-001 + + <_> + 10 + -1.1831332445144653e+000 + + <_> + + 0 -1 115 -912525479 -2146793066 247327 -554139184 320582141 + -1442774971 1552517769 -1464330096 + + -7.2892564535140991e-001 1.2876711785793304e-001 + <_> + + 0 -1 41 -182757566 -683667118 268566545 -540408959 + 1547915506 2014497074 1817806103 -549486525 + + -5.6024330854415894e-001 2.8734233975410461e-001 + <_> + + 0 -1 13 -1396013057 -175218480 536903951 -35946104 -92067077 + 956498056 -200474487 1331907188 + + -5.5237007141113281e-001 3.2844060659408569e-001 + <_> + + 0 -1 17 2110443855 1547702666 -1874853670 1083212172 + -2004008413 -498614008 572624451 1179093527 + + -7.2481799125671387e-001 2.6627025008201599e-001 + <_> + + 0 -1 43 -1751428966 -1626324992 -1073540847 -783806124 + -2146909454 -913440767 -2138941303 -558233160 + + -4.4304186105728149e-001 4.1505634784698486e-001 + <_> + + 0 -1 37 -576405461 -1625709950 1627439763 1116373274 + 1622902452 1107834529 975868423 2074176171 + + -5.6509882211685181e-001 3.5433205962181091e-001 + <_> + + 0 -1 118 1171205664 1426522307 49281 563122240 -791985520 + -930869245 -364148081 -590624140 + + -5.6250953674316406e-001 3.3341854810714722e-001 + <_> + + 0 -1 76 1162033968 1180991656 16859165 230787289 -2104786299 + -1819967351 1118240928 -343561865 + + -4.7331553697586060e-001 4.1576251387596130e-001 + <_> + + 0 -1 110 -2147085315 -1228897088 -2146839339 -1751314339 + -531605907 -393183232 1804153563 -1399324416 + + -5.8979070186614990e-001 3.7525305151939392e-001 + <_> + + 0 -1 55 1581887865 999817729 151311688 331546624 -991625824 + -938834941 1837335184 852075394 + + -5.4071021080017090e-001 4.0077716112136841e-001 + + <_> + 10 + -6.4480733871459961e-001 + + <_> + + 0 -1 16 -510660401 -884555766 272896026 -12189566 + -1685363509 -662568805 1073840823 -545105785 + + -5.3361344337463379e-001 2.7807486057281494e-001 + <_> + + 0 -1 48 -557408354 2115155922 -2130669353 1616707591 + 693193240 -1569554175 -1743918878 1983596555 + + -5.3364741802215576e-001 3.1411096453666687e-001 + <_> + + 0 -1 108 -413278733 83935516 536961502 1452278484 + -2004277212 -391683967 -1426466672 -85395040 + + -7.4530494213104248e-001 2.3025059700012207e-001 + <_> + + 0 -1 32 -938623022 1469386887 822151432 421593370 + -1433793568 -1602191360 -527916919 680112651 + + -4.6078306436538696e-001 4.0021440386772156e-001 + <_> + + 0 -1 50 1619785226 -1004367410 1417725137 126732357 + 148062614 -625983352 -712398335 -412918226 + + -4.9818846583366394e-001 3.6678382754325867e-001 + <_> + + 0 -1 24 -1064322531 1351938204 196691 -561840073 -1978859471 + -649944954 -2003664885 -1172094197 + + -4.7309580445289612e-001 4.2868506908416748e-001 + <_> + + 0 -1 96 -1878961904 1360035888 -1073721317 -1051487863 + -431841087 1628112896 -2112640640 -1829440828 + + -6.9250243902206421e-001 2.8783574700355530e-001 + <_> + + 0 -1 62 67496095 391741589 -2146154237 96245592 -893992548 + 982687872 571488264 278906307 + + -6.4613574743270874e-001 3.0145862698554993e-001 + <_> + + 0 -1 73 -415771792 1208487966 339825796 1792117580 + 1128517807 144965669 -536376816 732856538 + + -6.9449120759963989e-001 3.0338683724403381e-001 + <_> + + 0 -1 40 -1991530440 324215457 -2080275930 -1857940798 + 1342685625 721420800 1250592988 1493903457 + + -7.0043331384658813e-001 2.5916099548339844e-001 + + <_> + 10 + -6.0248321294784546e-001 + + <_> + + 0 -1 21 -16537745 2114438797 1409323561 1691064397 + -207434939 822260754 -384857461 2031088579 + + -6.1256545782089233e-001 1.7948718369007111e-001 + <_> + + 0 -1 1 -95427858 67117166 -1308426467 -1962693439 601886855 + 924320187 1661215701 2078945158 + + -6.8756872415542603e-001 2.2317354381084442e-001 + <_> + + 0 -1 121 -1853361185 -619857007 16793601 -184516476 + -1422775873 -488996831 1476610285 -926297672 + + -5.2260422706604004e-001 3.2479336857795715e-001 + <_> + + 0 -1 105 -267171326 1436635177 1937772829 -2092859315 + -769638067 -2122268534 1502103583 -18894227 + + -5.2588832378387451e-001 3.4061828255653381e-001 + <_> + + 0 -1 83 1880187281 -1862250368 303299 960921986 -2002701917 + -1593343958 -334888263 1058018448 + + -6.9037044048309326e-001 2.7262538671493530e-001 + <_> + + 0 -1 34 -2125487365 1347551377 -1861970752 1368654274 + -1064675233 436275211 327448684 2068015115 + + -5.3338903188705444e-001 3.2425448298454285e-001 + <_> + + 0 -1 36 1192659162 235536712 1078002258 428089414 + -2138651204 -1937242101 507742421 1932739127 + + -6.4654779434204102e-001 3.0722403526306152e-001 + <_> + + 0 -1 14 -805047416 -1962622822 -2013265442 2030239751 + 1082134810 1744963592 -1836871485 -249326965 + + -5.7250964641571045e-001 3.1499111652374268e-001 + <_> + + 0 -1 75 -650653297 170234379 -2063527695 448823424 + -2139088862 319586315 -2067685344 -1347692410 + + -5.4618871212005615e-001 3.8171616196632385e-001 + <_> + + 0 -1 56 -168821125 -1107300354 -536871052 -1125515426 + -1795721360 -1672085508 1845358040 -2114327569 + + -4.2669427394866943e-001 5.0532561540603638e-001 + + <_> + 11 + -1.1912760734558105e+000 + + <_> + + 0 -1 11 -1043414305 -1735900650 268517385 -1137929054 + -1048411462 -2011152253 -1957405841 -497557425 + + -5.7042253017425537e-001 2.1933962404727936e-001 + <_> + + 0 -1 71 -233469310 1360073157 376971 626087057 -1180588024 + -1191067261 -1474310132 830601690 + + -5.3927713632583618e-001 2.9026004672050476e-001 + <_> + + 0 -1 35 -1599643389 42074270 -1811918838 -949960625 + 1564707361 289538187 1204527649 -112006873 + + -6.0980087518692017e-001 2.8851604461669922e-001 + <_> + + 0 -1 59 585529126 -1100070936 -1342177537 833961983 + 1306961797 1986559992 -810088568 -1082149201 + + -3.2345715165138245e-001 5.5635309219360352e-001 + <_> + + 0 -1 95 1107806555 2030223765 17039707 -1224163308 + -1073053535 -1291837432 822618633 -121972608 + + -6.5054124593734741e-001 3.1912675499916077e-001 + <_> + + 0 -1 51 -171583461 -1660890605 268504396 453157697 + -1065215606 -1740602879 1824636801 1940062923 + + -4.7275745868682861e-001 4.2362514138221741e-001 + <_> + + 0 -1 87 -799546379 -2097769968 293605405 -21571376 285294733 + 136347650 -930405536 -69420863 + + -5.5549502372741699e-001 3.3842340111732483e-001 + <_> + + 0 -1 60 -594509036 -267114166 35413 -1052598126 545325639 + -1207959408 -1073643381 682827807 + + -5.4805672168731689e-001 3.7224516272544861e-001 + <_> + + 0 -1 63 1513710022 194882313 1109000450 28010496 -601835264 + -645791614 -1041880446 1561822180 + + -5.3384119272232056e-001 3.7635508179664612e-001 + <_> + + 0 -1 125 -754581391 -246595569 -2113336948 -1855323709 + 1090531337 -931133310 950984 -3971805 + + -5.2334308624267578e-001 4.0167775750160217e-001 + <_> + + 0 -1 58 -361268680 662383988 2147483638 -209756289 + -1375932428 -1895890954 -1744855042 -1142215109 + + -3.4343415498733521e-001 6.1590969562530518e-001 + + <_> + 10 + -7.7425497770309448e-001 + + <_> + + 0 -1 66 -716447302 -602037376 1090519043 -150261760 + 342934202 -2034138749 1141152394 -351301493 + + -4.8867926001548767e-001 3.4062498807907104e-001 + <_> + + 0 -1 98 -2071985592 -700120831 1078417460 672719121 + 1082264136 -209075063 -1438988203 -1465205245 + + -7.1539443731307983e-001 2.4058867990970612e-001 + <_> + + 0 -1 74 872558624 331821072 1610649929 -1181384552 + -2130081587 -92209146 -612134248 -1199562344 + + -4.4142067432403564e-001 3.7935256958007813e-001 + <_> + + 0 -1 68 -791554721 -737771072 2425605 740044819 1208549387 + 973897998 1124108962 802102203 + + -4.6558478474617004e-001 4.2193859815597534e-001 + <_> + + 0 -1 8 1893114270 -1013792636 360523 -586362838 -1073151001 + -2146917824 -2104934391 -875596965 + + -5.0676107406616211e-001 3.5864940285682678e-001 + <_> + + 0 -1 91 574816266 -2011773950 1476495634 580227538 + -2146781128 -2147448830 1901535891 -692616573 + + -6.1020326614379883e-001 3.0061775445938110e-001 + <_> + + 0 -1 70 2125429880 2080309246 -285282561 2142961407 + -1259516274 1073741823 754945025 867497448 + + -4.3854746222496033e-001 4.7815895080566406e-001 + <_> + + 0 -1 94 -1727736509 -1979678624 285229334 1115689064 + 537927788 -1207402368 1098914016 -91503488 + + -6.8697202205657959e-001 3.5183742642402649e-001 + <_> + + 0 -1 57 -528465144 -707035113 -1048575869 1372127361 8651416 + -526909310 -1845360374 -1451016182 + + -4.5901125669479370e-001 4.5875525474548340e-001 + <_> + + 0 -1 25 -2076984798 -533130869 -1060954112 1639977472 + 828440586 1792508680 -1693988801 -13285232 + + -4.8493441939353943e-001 4.3403539061546326e-001 + + <_> + + 0 1 1 9 + <_> + + 0 1 4 7 + <_> + + 0 2 2 6 + <_> + + 0 2 2 10 + <_> + + 0 2 3 4 + <_> + + 0 3 3 8 + <_> + + 0 4 1 8 + <_> + + 0 5 2 9 + <_> + + 0 7 1 8 + <_> + + 0 7 5 7 + <_> + + 0 9 1 5 + <_> + + 0 9 2 6 + <_> + + 0 10 3 7 + <_> + + 0 11 1 3 + <_> + + 0 12 2 1 + <_> + + 0 13 3 7 + <_> + + 0 14 1 1 + <_> + + 0 14 3 4 + <_> + + 0 16 1 1 + <_> + + 0 19 3 5 + <_> + + 0 20 3 4 + <_> + + 0 21 3 4 + <_> + + 0 22 2 4 + <_> + + 0 25 3 3 + <_> + + 0 25 4 3 + <_> + + 1 0 5 10 + <_> + + 1 2 1 9 + <_> + + 1 4 4 8 + <_> + + 1 4 5 9 + <_> + + 1 6 3 5 + <_> + + 1 9 2 3 + <_> + + 1 11 2 4 + <_> + + 1 15 3 2 + <_> + + 1 20 3 3 + <_> + + 1 28 2 2 + <_> + + 2 0 2 3 + <_> + + 2 0 3 5 + <_> + + 2 0 4 8 + <_> + + 2 3 4 5 + <_> + + 2 4 5 5 + <_> + + 2 5 2 5 + <_> + + 2 7 5 9 + <_> + + 2 8 1 3 + <_> + + 2 12 1 2 + <_> + + 2 13 3 3 + <_> + + 2 14 2 2 + <_> + + 2 16 3 5 + <_> + + 2 18 3 5 + <_> + + 2 22 2 4 + <_> + + 2 31 3 1 + <_> + + 3 0 2 3 + <_> + + 3 1 3 5 + <_> + + 3 1 3 8 + <_> + + 3 2 3 6 + <_> + + 3 8 4 6 + <_> + + 3 10 2 4 + <_> + + 3 14 2 2 + <_> + + 3 16 1 1 + <_> + + 3 18 1 1 + <_> + + 3 19 1 1 + <_> + + 3 19 1 2 + <_> + + 3 31 2 1 + <_> + + 4 4 4 4 + <_> + + 4 5 2 7 + <_> + + 4 6 2 4 + <_> + + 4 6 3 4 + <_> + + 4 7 2 8 + <_> + + 4 12 3 5 + <_> + + 4 19 2 3 + <_> + + 5 0 5 7 + <_> + + 5 3 4 4 + <_> + + 5 3 5 4 + <_> + + 5 5 2 8 + <_> + + 5 12 4 4 + <_> + + 5 22 1 1 + <_> + + 6 21 3 3 + <_> + + 6 26 2 2 + <_> + + 6 30 1 1 + <_> + + 6 31 1 1 + <_> + + 6 31 2 1 + <_> + + 7 0 2 3 + <_> + + 7 9 3 7 + <_> + + 7 17 1 1 + <_> + + 7 31 1 1 + <_> + + 7 31 2 1 + <_> + + 8 0 4 1 + <_> + + 8 5 2 4 + <_> + + 8 10 3 6 + <_> + + 8 16 2 1 + <_> + + 8 25 3 2 + <_> + + 8 30 1 1 + <_> + + 9 0 1 1 + <_> + + 9 0 3 2 + <_> + + 9 0 3 4 + <_> + + 9 15 2 1 + <_> + + 9 24 3 3 + <_> + + 9 29 1 1 + <_> + + 9 31 1 1 + <_> + + 10 4 2 2 + <_> + + 10 8 1 3 + <_> + + 10 15 1 3 + <_> + + 10 26 2 1 + <_> + + 10 30 1 1 + <_> + + 10 31 3 1 + <_> + + 11 0 3 2 + <_> + + 11 1 3 4 + <_> + + 11 5 3 8 + <_> + + 11 14 1 1 + <_> + + 11 23 2 2 + <_> + + 11 27 2 2 + <_> + + 11 31 1 1 + <_> + + 12 22 2 3 + <_> + + 12 29 1 1 + <_> + + 13 23 2 1 + <_> + + 13 24 1 3 + <_> + + 13 29 1 1 + <_> + + 13 31 2 1 + <_> + + 14 1 2 2 + <_> + + 14 1 2 6 + <_> + + 14 2 2 1 + <_> + + 14 24 2 2 + <_> + + 14 26 2 2 + <_> + + 14 28 1 1 + <_> + + 15 4 1 1 + <_> + + 15 24 1 1 + <_> + + 17 0 1 3 + <_> + + 17 3 1 4 + <_> + + 17 23 1 2 + <_> + + 17 27 1 1 + diff --git a/data/lbpcascades/lbpcascade_silverware.xml b/data/lbpcascades/lbpcascade_silverware.xml new file mode 100755 index 000000000..33aa443c2 --- /dev/null +++ b/data/lbpcascades/lbpcascade_silverware.xml @@ -0,0 +1,1279 @@ + + + + + BOOST + LBP + 80 + 12 + + GAB + 9.9500000476837158e-001 + 3.0000001192092896e-001 + 9.4999999999999996e-001 + 1 + 100 + + 256 + 1 + 16 + + + <_> + 4 + -8.2867860794067383e-002 + + <_> + + 0 -1 99 -268435521 -486543361 -258 1659633406 -134217857 + 1702887279 -134217929 -184549377 + + -7.5000000000000000e-001 8.6380833387374878e-001 + <_> + + 0 -1 39 -540541017 -1060113913 -781245688 -477121697 + -1818664155 1105186857 -505961467 -152575569 + + -7.9976779222488403e-001 7.5056612491607666e-001 + <_> + + 0 -1 101 -479208497 -353380921 -855254781 -1566689761 + -454302869 1893310787 -271591561 -134222965 + + -7.1062028408050537e-001 7.7380746603012085e-001 + <_> + + 0 -1 41 -338958865 -925383977 -1438297681 -981777969 + -882901177 1913369038 -135286729 1995959223 + + -7.8616768121719360e-001 6.9309240579605103e-001 + + <_> + 5 + -7.7058833837509155e-001 + + <_> + + 0 -1 14 -34089161 -2245 1878980471 -8687769 -134316045 + 1744797563 -8388737 1795146607 + + -6.1089491844177246e-001 7.3594772815704346e-001 + <_> + + 0 -1 32 -707274321 1896302609 1132560802 -183140351 17019099 + 830472347 -1993621429 1440074510 + + -6.4869755506515503e-001 5.6941097974777222e-001 + <_> + + 0 -1 4 -1055898237 -104492975 -1795141251 1464975384 + -1602043461 -914358144 1111543953 -2067496448 + + -6.0432785749435425e-001 5.5685383081436157e-001 + <_> + + 0 -1 96 -520160401 2063466495 -65665 -134217729 -50462805 + 1761476478 1693969709 1910503031 + + -5.6237226724624634e-001 6.2263637781143188e-001 + <_> + + 0 -1 6 -1479564374 -954482597 16859161 -799804534 268468874 + 713187329 1108033665 -714619755 + + -6.9048601388931274e-001 5.3264212608337402e-001 + + <_> + 5 + -7.1249550580978394e-001 + + <_> + + 0 -1 21 -34638473 -553976197 -134217865 -159715533 + -142901385 -272629761 -8421377 -956303361 + + -6.4170038700103760e-001 7.0683228969573975e-001 + <_> + + 0 -1 100 -8389777 -185860353 -277 -2097152001 -161 + -209780865 -1 -529006609 + + -5.5270516872406006e-001 6.9983023405075073e-001 + <_> + + 0 -1 118 -545259537 -276857217 -1258291302 1652358910 + -134236308 1735819126 -16812809 -221249673 + + -5.6243920326232910e-001 6.2150186300277710e-001 + <_> + + 0 -1 19 -342885713 -1369882213 -2079215310 -765214587 + -2113207945 1074365452 1393631959 1409022707 + + -6.8943935632705688e-001 5.3469669818878174e-001 + <_> + + 0 -1 23 -506991005 1360417115 -1844809365 -821575604 + 21178499 986120459 1347943419 -969541850 + + -6.7428857088088989e-001 5.5008578300476074e-001 + + <_> + 6 + -3.0183684825897217e-001 + + <_> + + 0 -1 31 -144703505 -143130625 -17 -134381841 -143130625 + 2012741567 -134218802 -134217841 + + -5.3079712390899658e-001 7.5616836547851563e-001 + <_> + + 0 -1 35 -137887809 -1924805943 1363218446 -817782134 + 1099022547 1082327168 -1279204784 1128784467 + + -6.4090979099273682e-001 5.3444361686706543e-001 + <_> + + 0 -1 15 -786433589 -515129128 277173650 -132673121 + -884037451 1137229866 1938662135 -676336865 + + -5.2920126914978027e-001 5.9623366594314575e-001 + <_> + + 0 -1 92 -1897400451 -1627924747 -335548553 -1 1257762559 + -2113929417 -419433067 -235309193 + + -5.5294114351272583e-001 5.8814722299575806e-001 + <_> + + 0 -1 112 -187176146 1743897116 -1878957040 542033563 + 1372582934 823282242 -158609727 -779295046 + + -6.8665105104446411e-001 4.4378995895385742e-001 + <_> + + 0 -1 9 1676637640 1887961346 16875658 1977614736 1682145753 + 813744265 -842338550 1930548135 + + -7.5830078125000000e-001 3.9562159776687622e-001 + + <_> + 8 + -3.9228534698486328e-001 + + <_> + + 0 -1 25 -167774345 -6689161 -2097153 -4194541 -282329093 -1 + -1 -352323601 + + -4.7727271914482117e-001 7.4114018678665161e-001 + <_> + + 0 -1 2 -1051598753 -1005571964 1900827102 2065404120 + -1207262247 -120553331 -1725955392 -494812414 + + -5.2365595102310181e-001 5.3981113433837891e-001 + <_> + + 0 -1 116 -2142770433 -1601462143 16842760 -804892128 1032369 + 268763273 1091011104 -1142957585 + + -4.7790464758872986e-001 5.4881525039672852e-001 + <_> + + 0 -1 87 -532155537 1351188929 1073823759 -1253637875 + -721321497 -662691837 -955278809 1623500836 + + -6.8072116374969482e-001 3.7135115265846252e-001 + <_> + + 0 -1 113 -1996457508 -2146282492 -1728016135 -578347007 + -1609004859 193626505 1153570968 -1920333632 + + -5.7289212942123413e-001 4.6210876107215881e-001 + <_> + + 0 -1 56 -972008109 -691003372 -2147413749 2098355010 + 143009971 -1744174583 -1073051430 617488921 + + -5.9549087285995483e-001 4.8842963576316833e-001 + <_> + + 0 -1 48 26 1971388449 419479901 2080931848 -1140292918 + -1719074813 -2130476842 -268398592 + + -5.8355164527893066e-001 4.7890499234199524e-001 + <_> + + 0 -1 57 -1052266874 167813132 -2130690045 -703061621 + -131874777 -662142838 -1064730555 1119947703 + + -6.9379311800003052e-001 3.9936643838882446e-001 + + <_> + 9 + -6.6581231355667114e-001 + + <_> + + 0 -1 29 2080314175 -112910205 805323551 1024016674 + 1073891387 -2137847805 1653140111 -7676933 + + -5.5957448482513428e-001 5.4044550657272339e-001 + <_> + + 0 -1 94 -1358956801 -100880986 -1887436809 1073741823 + -1896350220 -838860811 268434686 -1912602633 + + -4.3124794960021973e-001 5.6135851144790649e-001 + <_> + + 0 -1 76 -26230993 1357905647 -1358958674 -135266305 -524434 + -176291841 -142622837 -1005125829 + + -4.6799373626708984e-001 5.1660954952239990e-001 + <_> + + 0 -1 30 -313836176 -742240245 16818511 -1391787262 + 1632363443 -156630911 -83631445 248984215 + + -6.2023061513900757e-001 3.9792594313621521e-001 + <_> + + 0 -1 91 -612895966 591778561 1073812490 369347088 + -1870223303 556335107 553910792 1907094058 + + -6.2148678302764893e-001 4.1758581995964050e-001 + <_> + + 0 -1 46 -1430257749 -672663689 -218104082 -135266322 + -1493174275 -873463809 -276826113 -690006715 + + -5.1617449522018433e-001 5.2012032270431519e-001 + <_> + + 0 -1 123 1088746207 1489289603 16781456 -443461355 + -762795606 -670564192 -1465814774 -101527550 + + -5.0202989578247070e-001 5.0987190008163452e-001 + <_> + + 0 -1 53 -1001679641 -955695103 25248080 -738078457 671123502 + 193003713 -1836523327 -216026117 + + -5.2692401409149170e-001 5.3243070840835571e-001 + <_> + + 0 -1 89 2147417937 -1048642 -1039 -1766457361 -134236382 + -1922646177 -16777473 -1534591162 + + -4.6150138974189758e-001 5.6634509563446045e-001 + + <_> + 8 + -1.2349532842636108e+000 + + <_> + + 0 -1 67 -142902409 -67142273 1878982639 -1182802113 -75841 + -274219146 -88604929 -31817921 + + -4.5625588297843933e-001 5.7534247636795044e-001 + <_> + + 0 -1 128 -808330661 1390004234 1107406871 -2098932967 + -767440829 1208655939 -1971196977 1351600587 + + -5.7236993312835693e-001 4.1942635178565979e-001 + <_> + + 0 -1 0 -805307409 -1052697 -65684 -4233 -134217745 -4194453 + -696778831 -708062879 + + -4.5485407114028931e-001 5.5909335613250732e-001 + <_> + + 0 -1 119 -169888509 1150652435 1074791064 541757442 + -645182635 989929472 1262741126 1963976639 + + -6.4869618415832520e-001 3.9796143770217896e-001 + <_> + + 0 -1 38 -912524801 811171970 33644801 -717151469 -2108956437 + 294158344 1109713681 1900266000 + + -5.0387507677078247e-001 5.1329559087753296e-001 + <_> + + 0 -1 20 -746687625 -200802301 1073872962 285491202 + 1208512717 -2138664446 -1837102693 1174835902 + + -5.9465301036834717e-001 4.4057011604309082e-001 + <_> + + 0 -1 16 -442903927 -988184502 -717209211 1443168395 + -1465793521 1252524168 1107337938 -1050414557 + + -5.9043467044830322e-001 4.3687704205513000e-001 + <_> + + 0 -1 104 -1692667790 -612286452 -1056931520 437452806 + -2136309078 -401536992 -1987928929 -1033981310 + + -5.0495445728302002e-001 4.9910807609558105e-001 + + <_> + 9 + -5.4583048820495605e-001 + + <_> + + 0 -1 97 -419954689 -570949699 2147417599 -1 -872415749 + -301989897 -872433670 -268443689 + + -4.0734556317329407e-001 7.1092438697814941e-001 + <_> + + 0 -1 3 -1062674253 1929486475 197402 1841550219 135268235 + -1165491808 956369290 1258896162 + + -5.4886269569396973e-001 4.1644170880317688e-001 + <_> + + 0 -1 37 -620271105 -901300206 1359008346 -603537150 + 1355455189 596312193 -247999129 -728767550 + + -5.1914668083190918e-001 3.9419922232627869e-001 + <_> + + 0 -1 17 -1072700149 546031429 12798103 1881656595 35238042 + 682232321 176931799 1148695251 + + -5.4100900888442993e-001 4.0588796138763428e-001 + <_> + + 0 -1 71 -522857685 1350893957 17339597 1999601732 -779974469 + -359071607 1879296642 -1236927697 + + -4.9249285459518433e-001 4.4877073168754578e-001 + <_> + + 0 -1 93 2037497904 492944831 -2013291075 -754983169 + 1837104414 -671812233 -1660989976 -973105033 + + -4.6483671665191650e-001 4.8267844319343567e-001 + <_> + + 0 -1 33 -553943182 -100663369 -1327169 -181207174 -805896236 + -16777225 -32770 -344459717 + + -3.9679497480392456e-001 5.6408804655075073e-001 + <_> + + 0 -1 44 -8439301 -9502850 2147412095 2134171367 1467968283 + -555876513 1719612907 -959121 + + -3.7275579571723938e-001 6.2219065427780151e-001 + <_> + + 0 -1 62 -2086686357 -2143072184 1073745988 -1878839231 + 1221503177 -2113732606 1133091218 1470880455 + + -5.5160778760910034e-001 4.4197219610214233e-001 + + <_> + 8 + -4.9482953548431396e-001 + + <_> + + 0 -1 124 803987455 -1207959557 -1073747969 -3 -1879048193 + -1720221705 -1073744641 -1212159499 + + -4.2883211374282837e-001 5.8106172084808350e-001 + <_> + + 0 -1 1 -1520569905 -125497088 1360134399 -49444069 + -1065189105 -612134877 -1497194288 -1006112575 + + -4.8296096920967102e-001 4.3431344628334045e-001 + <_> + + 0 -1 108 -67112229 -797503462 268623881 1083056391 + -1874187198 1879638016 -804355463 1985162053 + + -6.1597704887390137e-001 3.4508374333381653e-001 + <_> + + 0 -1 26 -686760009 1468434576 1140918535 -880733942 12599987 + -1304752000 -1593784081 115557220 + + -5.7973521947860718e-001 4.0324980020523071e-001 + <_> + + 0 -1 115 -753405796 4259842 -872415136 85172613 154534824 + 8454145 -2147292968 1094185899 + + -4.7171372175216675e-001 4.6018373966217041e-001 + <_> + + 0 -1 64 -737160572 2107229470 1478238399 386729999 46739708 + -1717532540 134302191 1502456202 + + -4.7625115513801575e-001 4.6307522058486938e-001 + <_> + + 0 -1 63 574973114 1079378118 151608 -1089433600 683881170 + 1234370560 25761968 1305471639 + + -5.4804503917694092e-001 4.2817059159278870e-001 + <_> + + 0 -1 126 -913048353 -1333444591 303141015 1107341569 + -1727960821 1644167297 -1190753878 1418524891 + + -6.3843786716461182e-001 3.2018747925758362e-001 + + <_> + 10 + -4.7552201151847839e-001 + + <_> + + 0 -1 54 -17825929 -8718489 -34111631 -135004289 -1358954497 + -16814213 -151556225 -285220369 + + -4.1965106129646301e-001 5.5681818723678589e-001 + <_> + + 0 -1 88 -1856526326 -645691871 337711324 1464176998 + -1602581814 -1710751608 168420078 -1341468062 + + -4.0517404675483704e-001 4.9981650710105896e-001 + <_> + + 0 -1 45 -741223945 -1627185101 822169913 407916675 + -897447857 589300224 540099855 -1156899883 + + -4.4794428348541260e-001 4.3524059653282166e-001 + <_> + + 0 -1 66 258608606 -1120993285 -419517441 -578240642 + -1879056401 -1101037569 -13383 -28301584 + + -3.9371734857559204e-001 5.2872020006179810e-001 + <_> + + 0 -1 117 -350280689 -829730738 -1073461695 38377489 + -645158785 839057410 -1249137694 1882566387 + + -5.7474929094314575e-001 3.8859930634498596e-001 + <_> + + 0 -1 34 1536523031 -952168281 -1855975139 -854621937 + -939095838 -1744699368 -796270511 1582955555 + + -5.4318642616271973e-001 4.1631007194519043e-001 + <_> + + 0 -1 51 1393782562 319525363 8471383 1368384004 889651722 + 1921550554 -1836930098 1660195204 + + -7.2387772798538208e-001 2.8236424922943115e-001 + <_> + + 0 -1 78 1675075922 637567168 -2130116204 -1890844654 + 34255055 167907336 1091555477 -2142773065 + + -5.3113341331481934e-001 3.7920853495597839e-001 + <_> + + 0 -1 7 1164149387 1433912608 16876979 1595080980 1275865262 + -1446313974 1241665562 173580528 + + -5.0643980503082275e-001 4.4159597158432007e-001 + <_> + + 0 -1 129 -111949961 -783789413 268583504 -923765997 + -1073657336 -1340440574 -394149886 1216081042 + + -5.0880813598632813e-001 4.1170257329940796e-001 + + <_> + 11 + -6.9445723295211792e-001 + + <_> + + 0 -1 106 -487588613 -118095873 -1 2109472735 -1258291202 + -101712129 -33832963 -67652237 + + -4.0311419963836670e-001 6.2951332330703735e-001 + <_> + + 0 -1 49 -268435473 -353372166 2138045906 -4121 -276824105 + 1317007308 -41945099 -134484017 + + -3.5493713617324829e-001 5.5815106630325317e-001 + <_> + + 0 -1 5 1460877355 -15613689 558207061 -1623109371 + -1926723379 244908044 -113047169 1414649856 + + -5.8201593160629272e-001 3.5618588328361511e-001 + <_> + + 0 -1 103 -669296387 189940185 -1860046723 -1760460773 + -1740078915 -931100536 276828352 -1917868015 + + -4.2647001147270203e-001 4.6035429835319519e-001 + <_> + + 0 -1 107 -2109233498 -602287230 -1054785005 1360101827 + 1099137177 -318504822 -1341497202 232232049 + + -4.9850422143936157e-001 4.4256457686424255e-001 + <_> + + 0 -1 40 -54286241 -1608934766 286327519 -1270398764 + 1267376258 1636335746 542720627 1966594122 + + -5.5573022365570068e-001 3.9825862646102905e-001 + <_> + + 0 -1 18 -904213325 1133543618 67508251 -714997735 1094779186 + 160088201 872654991 -903019733 + + -5.2738076448440552e-001 3.8662704825401306e-001 + <_> + + 0 -1 70 1275766299 1347454976 150995380 -217382907 + 1661501627 -788494333 1259046051 -1006600122 + + -4.6260216832160950e-001 4.6852749586105347e-001 + <_> + + 0 -1 121 -367803633 420562962 36765796 -502050533 1380984391 + 268601345 536897573 -995624251 + + -5.2821987867355347e-001 4.4226339459419250e-001 + <_> + + 0 -1 68 -470086117 1069514507 -268472471 1936420849 + -1904232854 1475346303 -160432647 -258802070 + + -4.5063796639442444e-001 5.2728754281997681e-001 + <_> + + 0 -1 85 -698610339 -1504477166 1267372697 822280328 + -909606742 -561903583 -1658732533 962675013 + + -5.5067950487136841e-001 3.9346820116043091e-001 + + <_> + 9 + -7.5511032342910767e-001 + + <_> + + 0 -1 27 -485801045 -1031585761 285212749 -1013038975 + 427848842 -1006632832 -1039468406 -162905189 + + -4.8945146799087524e-001 4.7218933701515198e-001 + <_> + + 0 -1 114 -962887670 1547862275 -1827077881 1140871689 + -536829941 -763363328 -264142181 1112595267 + + -6.1379230022430420e-001 3.4447920322418213e-001 + <_> + + 0 -1 111 -784109321 320069633 1073811463 1074292770 + -2138957664 -2130001880 -2147252214 315289683 + + -5.6861025094985962e-001 3.7049382925033569e-001 + <_> + + 0 -1 80 -679857295 -17928596 -328961 991442748 1064728144 + -357040523 -1082493190 -1368229638 + + -3.9095887541770935e-001 6.0248941183090210e-001 + <_> + + 0 -1 82 175736687 -17072405 2130705262 -218107907 + -1358978530 1692925804 787824558 -672137257 + + -4.0445902943611145e-001 6.0857713222503662e-001 + <_> + + 0 -1 47 -985116365 -553647839 420626839 1968635918 + -1576924981 -360119808 142606465 -795508656 + + -4.8094493150711060e-001 5.1770961284637451e-001 + <_> + + 0 -1 50 -1459109750 33792144 21514342 1343230978 1124110539 + 50364672 441024643 -202393597 + + -5.2261912822723389e-001 4.6680617332458496e-001 + <_> + + 0 -1 98 -259008926 1378975745 -1476362162 1888485505 + 1082744897 571146241 1367392642 -1073229683 + + -6.1712646484375000e-001 3.8970091938972473e-001 + <_> + + 0 -1 125 34318799 1090695442 25199491 1342177299 -2060943181 + 143360000 -2097010032 -907873592 + + -5.3400212526321411e-001 4.4268184900283813e-001 + + <_> + 10 + -4.8388049006462097e-001 + + <_> + + 0 -1 120 -1477443585 -1140940929 -1342185476 1308588029 + -1376256001 218070525 1073741181 -41951875 + + -5.0602412223815918e-001 5.5081558227539063e-001 + <_> + + 0 -1 36 -73936261 -2137816955 -1073659749 -553533419 + -1073706765 -30799693 -972443088 1998113303 + + -4.8420175909996033e-001 4.5527526736259460e-001 + <_> + + 0 -1 77 454566983 420696071 16777221 -2130608117 -1719576352 + -644874174 -2111166071 577795078 + + -6.1467814445495605e-001 3.4610831737518311e-001 + <_> + + 0 -1 60 -1592753970 -251404269 570458176 486621571 + -2130476982 -1207431030 25803086 -2029039551 + + -5.2004736661911011e-001 4.5498979091644287e-001 + <_> + + 0 -1 72 694105913 1907355278 -37129 821280759 931135417 + -923336907 1073716718 -68419540 + + -4.1492795944213867e-001 5.7309722900390625e-001 + <_> + + 0 -1 79 1393265851 -1032732526 264196 -920530793 754211 + 169623560 1149456611 1135983235 + + -5.1638025045394897e-001 4.7242832183837891e-001 + <_> + + 0 -1 73 706130001 -1708251305 1056944760 1006373626 + -1303178409 -813991949 -1183128387 -604048669 + + -4.1649991273880005e-001 5.9589266777038574e-001 + <_> + + 0 -1 95 -904859491 -134017015 1090589192 -587038719 + -167673709 -897449815 152141841 886696449 + + -6.4827072620391846e-001 3.5843926668167114e-001 + <_> + + 0 -1 90 -717057392 690163912 822149263 65803 -1706982525 + -1736400884 534537 -1630082545 + + -5.0309199094772339e-001 5.1634097099304199e-001 + <_> + + 0 -1 12 -1366843350 -2126376671 1041 -566034432 142770176 + 12583104 51712 1116198165 + + -7.9860860109329224e-001 3.1541401147842407e-001 + + <_> + 10 + -5.6616169214248657e-001 + + <_> + + 0 -1 28 -143395977 2004844407 -32897 1840447419 -852257 + -4097 -272630497 -1165502065 + + -4.4186046719551086e-001 5.1379764080047607e-001 + <_> + + 0 -1 8 -519577109 -427718635 -1862262703 -65943231 9163380 + 1112064264 553714225 1157599521 + + -6.9529622793197632e-001 2.9373377561569214e-001 + <_> + + 0 -1 109 990036221 -1392408495 85 -1455423472 537079956 + -1451032448 -2121658180 -1917118335 + + -4.6548900008201599e-001 4.4904062151908875e-001 + <_> + + 0 -1 83 -307263958 1726969598 602799716 -587284627 + -2110304757 -1500547078 1400237979 -194002951 + + -4.4492045044898987e-001 5.2867370843887329e-001 + <_> + + 0 -1 84 -696132137 331497536 -1868546039 -1859480056 + 1753940107 -1029504896 -1341584891 937520647 + + -4.9129620194435120e-001 4.4696673750877380e-001 + <_> + + 0 -1 61 -1056718371 -912911872 67113021 1498447874 134777514 + -1412955989 -2138406733 1082270464 + + -5.8106380701065063e-001 4.1291686892509460e-001 + <_> + + 0 -1 43 -648808770 -703963135 -2147401712 -1858043831 + 1073823883 1074266248 159924795 1879588907 + + -5.2166140079498291e-001 4.6159252524375916e-001 + <_> + + 0 -1 65 538123210 285607041 -2122121208 -1651965941 + -1047953261 1661077920 591915 1689841382 + + -7.4180144071578979e-001 3.0022916197776794e-001 + <_> + + 0 -1 55 805390529 407044123 285213203 211421255 -1702852378 + -1919942528 -2134294375 2066729839 + + -4.8658525943756104e-001 5.4231238365173340e-001 + <_> + + 0 -1 69 -490280822 -1274937328 268439820 1359003776 + -931126870 1220674050 268681287 1997226373 + + -5.6268626451492310e-001 4.5061412453651428e-001 + + <_> + 10 + -9.9649858474731445e-001 + + <_> + + 0 -1 122 -1745100805 -1209164803 -1073770531 -436207891 + -1090560009 234354687 -1610664449 -1082138881 + + -4.0143370628356934e-001 5.6573116779327393e-001 + <_> + + 0 -1 11 -644493203 -1021149047 16847288 -804977263 + 1074438223 1375879170 1099505907 -233072125 + + -4.9022576212882996e-001 4.1356840729713440e-001 + <_> + + 0 -1 110 -1092637138 -1127253650 -604013462 309325799 + 511047567 -562074754 -700452946 -763371997 + + -4.2038223147392273e-001 5.0647193193435669e-001 + <_> + + 0 -1 24 1223739637 -1419051417 1043595135 -215335105 + 376670206 -167870465 -4194306 -222771398 + + -4.0432786941528320e-001 5.9335744380950928e-001 + <_> + + 0 -1 75 -1761937577 -1076383745 -286361737 -9060559 + 2013197781 2013265783 -98370 -1002109842 + + -4.4517979025840759e-001 5.2503407001495361e-001 + <_> + + 0 -1 102 1359075611 -233766656 65681 -1878048735 -1610570746 + 1379991688 -1073689784 -221669373 + + -4.9918147921562195e-001 4.6203434467315674e-001 + <_> + + 0 -1 52 1186053495 -36241670 -268451888 519745529 175382495 + 788381687 2147319804 1327036346 + + -4.6265572309494019e-001 5.1841813325881958e-001 + <_> + + 0 -1 59 -1040035797 1946189894 50247 -1862266624 1090519113 + 268961800 679544907 757613389 + + -5.5006593465805054e-001 4.4656375050544739e-001 + <_> + + 0 -1 10 1610993732 -939524096 1073877397 -267910919 + 151167146 537427968 -769096510 -181428117 + + -5.6329357624053955e-001 4.2267900705337524e-001 + <_> + + 0 -1 86 -1596021624 2047393801 -2130673584 -1856700352 + 327207619 272728192 -2004808112 491069440 + + -6.3942277431488037e-001 3.8081073760986328e-001 + + <_> + 8 + -5.5261385440826416e-001 + + <_> + + 0 -1 13 -648185009 -1315897313 -2139077632 1367998985 + 1744840211 -1005502457 -935198613 -74777841 + + -5.3191488981246948e-001 4.0654698014259338e-001 + <_> + + 0 -1 105 1699432742 -1890377581 1343232064 -1039957887 + -2142687167 637566976 -2122282989 -460871217 + + -5.4315727949142456e-001 3.6683899164199829e-001 + <_> + + 0 -1 81 -67160267 2105388843 -1619001345 1937768302 + -1359003974 -1098989786 -805322771 -1874678652 + + -3.9974156022071838e-001 5.5645257234573364e-001 + <_> + + 0 -1 58 -1072656189 1095241792 16777487 -352059374 4718723 + 1109393544 1074438486 -1848987381 + + -5.0869542360305786e-001 4.9633875489234924e-001 + <_> + + 0 -1 22 226493774 -1911816127 1091108968 26214662 26222970 + -1123287032 -1987040599 -882898875 + + -6.0312920808792114e-001 3.5752627253532410e-001 + <_> + + 0 -1 127 -259153461 -805273578 50364730 -1060208632 + -1708161014 947912705 -2147450710 80388754 + + -6.9576680660247803e-001 3.3376914262771606e-001 + <_> + + 0 -1 42 -800800303 1368954882 75795 2031108096 -2013069281 + 212336778 538680 2064105488 + + -5.6596046686172485e-001 4.3809539079666138e-001 + <_> + + 0 -1 74 -2108215089 1260109955 -1207926768 268812673 + -2146893693 167788680 55189712 -140564306 + + -5.1393473148345947e-001 4.8148322105407715e-001 + + <_> + + 0 0 1 2 + <_> + + 0 0 1 3 + <_> + + 0 0 2 1 + <_> + + 0 0 2 11 + <_> + + 0 0 3 1 + <_> + + 0 0 4 4 + <_> + + 0 1 1 3 + <_> + + 0 1 3 5 + <_> + + 0 2 1 2 + <_> + + 0 2 4 17 + <_> + + 0 3 1 1 + <_> + + 0 4 1 1 + <_> + + 0 4 1 4 + <_> + + 0 4 1 18 + <_> + + 0 4 2 21 + <_> + + 0 5 1 1 + <_> + + 0 5 1 2 + <_> + + 0 5 1 4 + <_> + + 0 5 2 11 + <_> + + 0 6 1 2 + <_> + + 0 7 1 15 + <_> + + 0 7 2 18 + <_> + + 0 13 3 3 + <_> + + 0 13 3 19 + <_> + + 0 14 2 5 + <_> + + 0 14 2 14 + <_> + + 0 16 3 17 + <_> + + 0 17 1 6 + <_> + + 0 17 2 9 + <_> + + 0 18 1 6 + <_> + + 0 19 2 17 + <_> + + 0 21 4 13 + <_> + + 0 21 4 16 + <_> + + 0 22 2 8 + <_> + + 0 36 1 5 + <_> + + 0 40 2 12 + <_> + + 0 43 1 7 + <_> + + 0 46 2 10 + <_> + + 0 48 1 9 + <_> + + 0 48 2 4 + <_> + + 0 50 1 2 + <_> + + 0 56 2 3 + <_> + + 0 71 1 3 + <_> + + 0 74 1 2 + <_> + + 0 77 1 1 + <_> + + 0 77 2 1 + <_> + + 1 0 1 3 + <_> + + 1 0 2 1 + <_> + + 1 0 3 1 + <_> + + 1 2 1 1 + <_> + + 1 4 1 2 + <_> + + 1 4 3 23 + <_> + + 1 5 2 7 + <_> + + 1 9 1 1 + <_> + + 1 10 2 15 + <_> + + 1 12 2 7 + <_> + + 1 14 2 9 + <_> + + 1 25 2 18 + <_> + + 1 39 2 10 + <_> + + 1 71 1 3 + <_> + + 2 0 1 3 + <_> + + 2 0 2 1 + <_> + + 2 3 1 2 + <_> + + 2 4 1 5 + <_> + + 2 16 3 8 + <_> + + 2 18 3 14 + <_> + + 2 21 2 2 + <_> + + 2 22 1 4 + <_> + + 2 24 1 2 + <_> + + 2 64 1 5 + <_> + + 3 0 2 1 + <_> + + 3 1 3 25 + <_> + + 3 2 3 6 + <_> + + 3 3 2 11 + <_> + + 3 6 1 3 + <_> + + 3 17 1 11 + <_> + + 3 22 3 17 + <_> + + 3 23 1 4 + <_> + + 3 42 1 10 + <_> + + 3 52 1 6 + <_> + + 3 77 1 1 + <_> + + 4 0 2 2 + <_> + + 4 1 1 2 + <_> + + 4 2 1 1 + <_> + + 5 7 2 20 + <_> + + 5 12 2 19 + <_> + + 5 14 1 3 + <_> + + 5 19 2 15 + <_> + + 6 0 1 1 + <_> + + 6 0 2 1 + <_> + + 6 1 2 13 + <_> + + 6 5 2 5 + <_> + + 6 7 2 17 + <_> + + 6 10 2 7 + <_> + + 6 13 2 10 + <_> + + 6 14 2 13 + <_> + + 6 16 2 14 + <_> + + 6 19 2 7 + <_> + + 6 36 1 8 + <_> + + 6 39 2 7 + <_> + + 6 41 2 9 + <_> + + 6 44 2 2 + <_> + + 6 51 2 6 + <_> + + 6 77 2 1 + <_> + + 7 0 1 1 + <_> + + 7 9 1 2 + <_> + + 7 20 1 9 + <_> + + 7 23 1 4 + <_> + + 7 45 1 7 + <_> + + 7 77 1 1 + <_> + + 8 0 1 1 + <_> + + 8 47 1 11 + <_> + + 8 53 1 4 + <_> + + 8 77 1 1 + <_> + + 9 0 1 2 + <_> + + 9 0 1 15 + <_> + + 9 0 1 20 + <_> + + 9 2 1 3 + <_> + + 9 3 1 2 + <_> + + 9 6 1 3 + <_> + + 9 9 1 13 + <_> + + 9 13 1 2 + <_> + + 9 13 1 8 + <_> + + 9 19 1 16 + <_> + + 9 20 1 4 + <_> + + 9 25 1 4 + <_> + + 9 43 1 5 + <_> + + 9 48 1 4 + <_> + + 9 59 1 3 + <_> + + 9 61 1 5 + diff --git a/samples/c/facedetect.cpp b/samples/c/facedetect.cpp index a641a74a8..69b9e9983 100644 --- a/samples/c/facedetect.cpp +++ b/samples/c/facedetect.cpp @@ -3,6 +3,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include +#include #include using namespace std; @@ -11,36 +12,41 @@ using namespace cv; static void help() { cout << "\nThis program demonstrates the cascade recognizer. Now you can use Haar or LBP features.\n" - "This classifier can recognize many ~rigid objects, it's most known use is for faces.\n" + "This classifier can recognize many kinds of rigid objects, once the appropriate classifier is trained.\n" + "It's most known use is for faces.\n" "Usage:\n" "./facedetect [--cascade= this is the primary trained classifier such as frontal face]\n" " [--nested-cascade[=nested_cascade_path this an optional secondary classifier such as eyes]]\n" - " [--scale=\n" + " [--scale=]\n" + " [--try-flip]\n" " [filename|camera_index]\n\n" "see facedetect.cmd for one call:\n" - "./facedetect --cascade=\"../../data/haarcascades/haarcascade_frontalface_alt.xml\" --nested-cascade=\"../../data/haarcascades/haarcascade_eye.xml\" --scale=1.3 \n" - "Hit any key to quit.\n" - "Using OpenCV version " << CV_VERSION << "\n" << endl; + "./facedetect --cascade=\"../../data/haarcascades/haarcascade_frontalface_alt.xml\" --nested-cascade=\"../../data/haarcascades/haarcascade_eye.xml\" --scale=1.3\n\n" + "During execution:\n\tHit any key to quit.\n" + "\tUsing OpenCV version " << CV_VERSION << "\n" << endl; } -void detectAndDraw( Mat& img, - CascadeClassifier& cascade, CascadeClassifier& nestedCascade, - double scale); +void detectAndDraw( Mat& img, CascadeClassifier& cascade, + CascadeClassifier& nestedCascade, + double scale, bool tryflip ); -String cascadeName = "../../data/haarcascades/haarcascade_frontalface_alt.xml"; -String nestedCascadeName = "../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml"; +string cascadeName = "../../data/haarcascades/haarcascade_frontalface_alt.xml"; +string nestedCascadeName = "../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml"; int main( int argc, const char** argv ) { CvCapture* capture = 0; Mat frame, frameCopy, image; - const String scaleOpt = "--scale="; + const string scaleOpt = "--scale="; size_t scaleOptLen = scaleOpt.length(); - const String cascadeOpt = "--cascade="; + const string cascadeOpt = "--cascade="; size_t cascadeOptLen = cascadeOpt.length(); - const String nestedCascadeOpt = "--nested-cascade"; + const string nestedCascadeOpt = "--nested-cascade"; size_t nestedCascadeOptLen = nestedCascadeOpt.length(); - String inputName; + const string tryFlipOpt = "--try-flip"; + size_t tryFlipOptLen = tryFlipOpt.length(); + string inputName; + bool tryflip = false; help(); @@ -68,6 +74,11 @@ int main( int argc, const char** argv ) scale = 1; cout << " from which we read scale = " << scale << endl; } + else if( tryFlipOpt.compare( 0, tryFlipOptLen, argv[i], tryFlipOptLen ) == 0 ) + { + tryflip = true; + cout << " will try to flip image horizontally to detect assymetric objects\n"; + } else if( argv[i][0] == '-' ) { cerr << "WARNING: Unknown option %s" << argv[i] << endl; @@ -79,10 +90,7 @@ int main( int argc, const char** argv ) if( !cascade.load( cascadeName ) ) { cerr << "ERROR: Could not load classifier cascade" << endl; - cerr << "Usage: facedetect [--cascade=]\n" - " [--nested-cascade[=nested_cascade_path]]\n" - " [--scale[=\n" - " [filename|camera_index]\n" << endl ; + help(); return -1; } @@ -123,7 +131,7 @@ int main( int argc, const char** argv ) else flip( frame, frameCopy, 0 ); - detectAndDraw( frameCopy, cascade, nestedCascade, scale ); + detectAndDraw( frameCopy, cascade, nestedCascade, scale, tryflip ); if( waitKey( 10 ) >= 0 ) goto _cleanup_; @@ -139,7 +147,7 @@ _cleanup_: cout << "In image read" << endl; if( !image.empty() ) { - detectAndDraw( image, cascade, nestedCascade, scale ); + detectAndDraw( image, cascade, nestedCascade, scale, tryflip ); waitKey(0); } else if( !inputName.empty() ) @@ -160,7 +168,7 @@ _cleanup_: image = imread( buf, 1 ); if( !image.empty() ) { - detectAndDraw( image, cascade, nestedCascade, scale ); + detectAndDraw( image, cascade, nestedCascade, scale, tryflip ); c = waitKey(0); if( c == 27 || c == 'q' || c == 'Q' ) break; @@ -180,13 +188,13 @@ _cleanup_: return 0; } -void detectAndDraw( Mat& img, - CascadeClassifier& cascade, CascadeClassifier& nestedCascade, - double scale) +void detectAndDraw( Mat& img, CascadeClassifier& cascade, + CascadeClassifier& nestedCascade, + double scale, bool tryflip ) { int i = 0; double t = 0; - vector faces; + vector faces, faces2; const static Scalar colors[] = { CV_RGB(0,0,255), CV_RGB(0,128,255), CV_RGB(0,255,255), @@ -209,6 +217,21 @@ void detectAndDraw( Mat& img, |CV_HAAR_SCALE_IMAGE , Size(30, 30) ); + if( tryflip ) + { + flip(smallImg, smallImg, 1); + cascade.detectMultiScale( smallImg, faces2, + 1.1, 2, 0 + //|CV_HAAR_FIND_BIGGEST_OBJECT + //|CV_HAAR_DO_ROUGH_SEARCH + |CV_HAAR_SCALE_IMAGE + , + Size(30, 30) ); + for( vector::const_iterator r = faces2.begin(); r != faces2.end(); r++ ) + { + faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height)); + } + } t = (double)cvGetTickCount() - t; printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) ); for( vector::const_iterator r = faces.begin(); r != faces.end(); r++, i++ ) @@ -218,10 +241,19 @@ void detectAndDraw( Mat& img, Point center; Scalar color = colors[i%8]; int radius; - center.x = cvRound((r->x + r->width*0.5)*scale); - center.y = cvRound((r->y + r->height*0.5)*scale); - radius = cvRound((r->width + r->height)*0.25*scale); - circle( img, center, radius, color, 3, 8, 0 ); + + double aspect_ratio = (double)r->width/r->height; + if( 0.75 < aspect_ratio && aspect_ratio < 1.3 ) + { + center.x = cvRound((r->x + r->width*0.5)*scale); + center.y = cvRound((r->y + r->height*0.5)*scale); + radius = cvRound((r->width + r->height)*0.25*scale); + circle( img, center, radius, color, 3, 8, 0 ); + } + else + rectangle( img, cvPoint(cvRound(r->x*scale), cvRound(r->y*scale)), + cvPoint(cvRound((r->x + r->width-1)*scale), cvRound((r->y + r->height-1)*scale)), + color, 3, 8, 0); if( nestedCascade.empty() ) continue; smallImgROI = smallImg(*r);