From: Roman Donchenko Date: Mon, 30 Dec 2013 13:30:59 +0000 (+0400) Subject: Merge commit '05b9c991dd' into merge-2.4 X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~748^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cdc10defa34ea7ba0edda7d4a3fa0701d451912a;p=profile%2Fivi%2Fopencv.git Merge commit '05b9c991dd' into merge-2.4 Conflicts: modules/cuda/test/test_objdetect.cpp modules/gpu/perf/perf_core.cpp modules/gpu/perf/perf_video.cpp modules/gpu/test/test_core.cpp --- cdc10defa34ea7ba0edda7d4a3fa0701d451912a diff --cc modules/cuda/test/test_gpumat.cpp index 9a13259,0000000..2076352 mode 100644,000000..100644 --- a/modules/cuda/test/test_gpumat.cpp +++ b/modules/cuda/test/test_gpumat.cpp @@@ -1,361 -1,0 +1,361 @@@ +/*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" + +#ifdef HAVE_CUDA + +using namespace cvtest; + +//////////////////////////////////////////////////////////////////////////////// +// SetTo + +PARAM_TEST_CASE(SetTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int type; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + type = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(SetTo, Zero) +{ + cv::Scalar zero = cv::Scalar::all(0); + + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(zero); + + EXPECT_MAT_NEAR(cv::Mat::zeros(size, type), mat, 0.0); +} + +CUDA_TEST_P(SetTo, SameVal) +{ + cv::Scalar val = cv::Scalar::all(randomDouble(0.0, 255.0)); + + if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(val); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(val); + + EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0); + } +} + +CUDA_TEST_P(SetTo, DifferentVal) +{ + cv::Scalar val = randomScalar(0.0, 255.0); + + if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(val); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(val); + + EXPECT_MAT_NEAR(cv::Mat(size, type, val), mat, 0.0); + } +} + +CUDA_TEST_P(SetTo, Masked) +{ + cv::Scalar val = randomScalar(0.0, 255.0); + cv::Mat mat_gold = randomMat(size, type); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat mat = createMat(size, type, useRoi); + mat.setTo(val, loadMat(mask)); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat mat = loadMat(mat_gold, useRoi); + mat.setTo(val, loadMat(mask, useRoi)); + + mat_gold.setTo(val, mask); + + EXPECT_MAT_NEAR(mat_gold, mat, 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, SetTo, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_TYPES, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// CopyTo + +PARAM_TEST_CASE(CopyTo, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int type; + bool useRoi; + + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + type = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(CopyTo, WithOutMask) +{ + cv::Mat src = randomMat(size, type); + + cv::cuda::GpuMat d_src = loadMat(src, useRoi); + cv::cuda::GpuMat dst = createMat(size, type, useRoi); + d_src.copyTo(dst); + + EXPECT_MAT_NEAR(src, dst, 0.0); +} + +CUDA_TEST_P(CopyTo, Masked) +{ + cv::Mat src = randomMat(size, type); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if (CV_MAT_DEPTH(type) == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat d_src = loadMat(src); + cv::cuda::GpuMat dst; + d_src.copyTo(dst, loadMat(mask, useRoi)); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat d_src = loadMat(src, useRoi); + cv::cuda::GpuMat dst = loadMat(cv::Mat::zeros(size, type), useRoi); + d_src.copyTo(dst, loadMat(mask, useRoi)); + + cv::Mat dst_gold = cv::Mat::zeros(size, type); + src.copyTo(dst_gold, mask); + + EXPECT_MAT_NEAR(dst_gold, dst, 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, CopyTo, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_TYPES, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// ConvertTo + +PARAM_TEST_CASE(ConvertTo, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth1; + int depth2; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth1 = GET_PARAM(2); + depth2 = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(ConvertTo, WithOutScaling) +{ + cv::Mat src = randomMat(size, depth1); + + if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat d_src = loadMat(src); + cv::cuda::GpuMat dst; + d_src.convertTo(dst, depth2); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat d_src = loadMat(src, useRoi); + cv::cuda::GpuMat dst = createMat(size, depth2, useRoi); + d_src.convertTo(dst, depth2); + + cv::Mat dst_gold; + src.convertTo(dst_gold, depth2); + - EXPECT_MAT_NEAR(dst_gold, dst, 0.0); ++ EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + } +} + +CUDA_TEST_P(ConvertTo, WithScaling) +{ + cv::Mat src = randomMat(size, depth1); + double a = randomDouble(0.0, 1.0); + double b = randomDouble(-10.0, 10.0); + + if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat d_src = loadMat(src); + cv::cuda::GpuMat dst; + d_src.convertTo(dst, depth2, a, b); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat d_src = loadMat(src, useRoi); + cv::cuda::GpuMat dst = createMat(size, depth2, useRoi); + d_src.convertTo(dst, depth2, a, b); + + cv::Mat dst_gold; + src.convertTo(dst_gold, depth2, a, b); + + EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, ConvertTo, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_DEPTH, + ALL_DEPTH, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// ensureSizeIsEnough + +struct EnsureSizeIsEnough : testing::TestWithParam +{ + virtual void SetUp() + { + cv::cuda::DeviceInfo devInfo = GetParam(); + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(EnsureSizeIsEnough, BufferReuse) +{ + cv::cuda::GpuMat buffer(100, 100, CV_8U); + cv::cuda::GpuMat old = buffer; + + // don't reallocate memory + cv::cuda::ensureSizeIsEnough(10, 20, CV_8U, buffer); + EXPECT_EQ(10, buffer.rows); + EXPECT_EQ(20, buffer.cols); + EXPECT_EQ(CV_8UC1, buffer.type()); + EXPECT_EQ(reinterpret_cast(old.data), reinterpret_cast(buffer.data)); + + // don't reallocate memory + cv::cuda::ensureSizeIsEnough(20, 30, CV_8U, buffer); + EXPECT_EQ(20, buffer.rows); + EXPECT_EQ(30, buffer.cols); + EXPECT_EQ(CV_8UC1, buffer.type()); + EXPECT_EQ(reinterpret_cast(old.data), reinterpret_cast(buffer.data)); +} + +INSTANTIATE_TEST_CASE_P(CUDA_GpuMat, EnsureSizeIsEnough, ALL_DEVICES); + +#endif // HAVE_CUDA diff --cc modules/cuda/test/test_objdetect.cpp index 658508f,0000000..8c7b5ec mode 100644,000000..100644 --- a/modules/cuda/test/test_objdetect.cpp +++ b/modules/cuda/test/test_objdetect.cpp @@@ -1,427 -1,0 +1,427 @@@ +/*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" + +#ifdef HAVE_CUDA + +using namespace cvtest; + +//#define DUMP + +struct HOG : testing::TestWithParam, cv::cuda::HOGDescriptor +{ + cv::cuda::DeviceInfo devInfo; + +#ifdef DUMP + std::ofstream f; +#else + std::ifstream f; +#endif + + int wins_per_img_x; + int wins_per_img_y; + int blocks_per_win_x; + int blocks_per_win_y; + int block_hist_size; + + virtual void SetUp() + { + devInfo = GetParam(); + + cv::cuda::setDevice(devInfo.deviceID()); + } + +#ifdef DUMP + void dump(const cv::Mat& blockHists, const std::vector& locations) + { + f.write((char*)&blockHists.rows, sizeof(blockHists.rows)); + f.write((char*)&blockHists.cols, sizeof(blockHists.cols)); + + for (int i = 0; i < blockHists.rows; ++i) + { + for (int j = 0; j < blockHists.cols; ++j) + { + float val = blockHists.at(i, j); + f.write((char*)&val, sizeof(val)); + } + } + + int nlocations = locations.size(); + f.write((char*)&nlocations, sizeof(nlocations)); + + for (int i = 0; i < locations.size(); ++i) + f.write((char*)&locations[i], sizeof(locations[i])); + } +#else + void compare(const cv::Mat& blockHists, const std::vector& locations) + { + int rows, cols; + f.read((char*)&rows, sizeof(rows)); + f.read((char*)&cols, sizeof(cols)); + ASSERT_EQ(rows, blockHists.rows); + ASSERT_EQ(cols, blockHists.cols); + + for (int i = 0; i < blockHists.rows; ++i) + { + for (int j = 0; j < blockHists.cols; ++j) + { + float val; + f.read((char*)&val, sizeof(val)); + ASSERT_NEAR(val, blockHists.at(i, j), 1e-3); + } + } + + int nlocations; + f.read((char*)&nlocations, sizeof(nlocations)); + ASSERT_EQ(nlocations, static_cast(locations.size())); + + for (int i = 0; i < nlocations; ++i) + { + cv::Point location; + f.read((char*)&location, sizeof(location)); + ASSERT_EQ(location, locations[i]); + } + } +#endif + + void testDetect(const cv::Mat& img) + { + gamma_correction = false; + setSVMDetector(cv::cuda::HOGDescriptor::getDefaultPeopleDetector()); + + std::vector locations; + + // Test detect + detect(loadMat(img), locations, 0); + +#ifdef DUMP + dump(cv::Mat(block_hists), locations); +#else + compare(cv::Mat(block_hists), locations); +#endif + + // Test detect on smaller image + cv::Mat img2; + cv::resize(img, img2, cv::Size(img.cols / 2, img.rows / 2)); + detect(loadMat(img2), locations, 0); + +#ifdef DUMP + dump(cv::Mat(block_hists), locations); +#else + compare(cv::Mat(block_hists), locations); +#endif + + // Test detect on greater image + cv::resize(img, img2, cv::Size(img.cols * 2, img.rows * 2)); + detect(loadMat(img2), locations, 0); + +#ifdef DUMP + dump(cv::Mat(block_hists), locations); +#else + compare(cv::Mat(block_hists), locations); +#endif + } + + // Does not compare border value, as interpolation leads to delta + void compare_inner_parts(cv::Mat d1, cv::Mat d2) + { + for (int i = 1; i < blocks_per_win_y - 1; ++i) + for (int j = 1; j < blocks_per_win_x - 1; ++j) + for (int k = 0; k < block_hist_size; ++k) + { + float a = d1.at(0, (i * blocks_per_win_x + j) * block_hist_size); + float b = d2.at(0, (i * blocks_per_win_x + j) * block_hist_size); + ASSERT_FLOAT_EQ(a, b); + } + } +}; + +// desabled while resize does not fixed - CUDA_TEST_P(HOG, Detect) ++CUDA_TEST_P(HOG, DISABLED_Detect) +{ + cv::Mat img_rgb = readImage("hog/road.png"); + ASSERT_FALSE(img_rgb.empty()); + +#ifdef DUMP + f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary); + ASSERT_TRUE(f.is_open()); +#else + f.open((std::string(cvtest::TS::ptr()->get_data_path()) + "hog/expected_output.bin").c_str(), std::ios_base::binary); + ASSERT_TRUE(f.is_open()); +#endif + + // Test on color image + cv::Mat img; + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + testDetect(img); + + // Test on gray image + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2GRAY); + testDetect(img); + + f.close(); +} + +CUDA_TEST_P(HOG, GetDescriptors) +{ + // Load image (e.g. train data, composed from windows) + cv::Mat img_rgb = readImage("hog/train_data.png"); + ASSERT_FALSE(img_rgb.empty()); + + // Convert to C4 + cv::Mat img; + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + + cv::cuda::GpuMat d_img(img); + + // Convert train images into feature vectors (train table) + cv::cuda::GpuMat descriptors, descriptors_by_cols; + getDescriptors(d_img, win_size, descriptors, DESCR_FORMAT_ROW_BY_ROW); + getDescriptors(d_img, win_size, descriptors_by_cols, DESCR_FORMAT_COL_BY_COL); + + // Check size of the result train table + wins_per_img_x = 3; + wins_per_img_y = 2; + blocks_per_win_x = 7; + blocks_per_win_y = 15; + block_hist_size = 36; + cv::Size descr_size_expected = cv::Size(blocks_per_win_x * blocks_per_win_y * block_hist_size, + wins_per_img_x * wins_per_img_y); + ASSERT_EQ(descr_size_expected, descriptors.size()); + + // Check both formats of output descriptors are handled correctly + cv::Mat dr(descriptors); + cv::Mat dc(descriptors_by_cols); + for (int i = 0; i < wins_per_img_x * wins_per_img_y; ++i) + { + const float* l = dr.rowRange(i, i + 1).ptr(); + const float* r = dc.rowRange(i, i + 1).ptr(); + for (int y = 0; y < blocks_per_win_y; ++y) + for (int x = 0; x < blocks_per_win_x; ++x) + for (int k = 0; k < block_hist_size; ++k) + ASSERT_EQ(l[(y * blocks_per_win_x + x) * block_hist_size + k], + r[(x * blocks_per_win_y + y) * block_hist_size + k]); + } + + /* Now we want to extract the same feature vectors, but from single images. NOTE: results will + be defferent, due to border values interpolation. Using of many small images is slower, however we + wont't call getDescriptors and will use computeBlockHistograms instead of. computeBlockHistograms + works good, it can be checked in the gpu_hog sample */ + + img_rgb = readImage("hog/positive1.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + // Everything is fine with interpolation for left top subimage + ASSERT_EQ(0.0, cv::norm((cv::Mat)block_hists, (cv::Mat)descriptors.rowRange(0, 1))); + + img_rgb = readImage("hog/positive2.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(1, 2))); + + img_rgb = readImage("hog/negative1.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(2, 3))); + + img_rgb = readImage("hog/negative2.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(3, 4))); + + img_rgb = readImage("hog/positive3.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(4, 5))); + + img_rgb = readImage("hog/negative3.png"); + ASSERT_TRUE(!img_rgb.empty()); + cv::cvtColor(img_rgb, img, cv::COLOR_BGR2BGRA); + computeBlockHistograms(cv::cuda::GpuMat(img)); + compare_inner_parts(cv::Mat(block_hists), cv::Mat(descriptors.rowRange(5, 6))); +} + +INSTANTIATE_TEST_CASE_P(CUDA_ObjDetect, HOG, ALL_DEVICES); + +//============== caltech hog tests =====================// + +struct CalTech : public ::testing::TestWithParam > +{ + cv::cuda::DeviceInfo devInfo; + cv::Mat img; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + cv::cuda::setDevice(devInfo.deviceID()); + + img = readImage(GET_PARAM(1), cv::IMREAD_GRAYSCALE); + ASSERT_FALSE(img.empty()); + } +}; + +CUDA_TEST_P(CalTech, HOG) +{ + cv::cuda::GpuMat d_img(img); + cv::Mat markedImage(img.clone()); + + cv::cuda::HOGDescriptor d_hog; + d_hog.setSVMDetector(cv::cuda::HOGDescriptor::getDefaultPeopleDetector()); + d_hog.nlevels = d_hog.nlevels + 32; + + std::vector found_locations; + d_hog.detectMultiScale(d_img, found_locations); + +#if defined (LOG_CASCADE_STATISTIC) + for (int i = 0; i < (int)found_locations.size(); i++) + { + cv::Rect r = found_locations[i]; + + std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; + cv::rectangle(markedImage, r , CV_RGB(255, 0, 0)); + } + + cv::imshow("Res", markedImage); cv::waitKey(); +#endif +} + +INSTANTIATE_TEST_CASE_P(detect, CalTech, testing::Combine(ALL_DEVICES, + ::testing::Values("caltech/image_00000009_0.png", "caltech/image_00000032_0.png", + "caltech/image_00000165_0.png", "caltech/image_00000261_0.png", "caltech/image_00000469_0.png", + "caltech/image_00000527_0.png", "caltech/image_00000574_0.png"))); + + + + +////////////////////////////////////////////////////////////////////////////////////////// +/// LBP classifier + +PARAM_TEST_CASE(LBP_Read_classifier, cv::cuda::DeviceInfo, int) +{ + cv::cuda::DeviceInfo devInfo; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(LBP_Read_classifier, Accuracy) +{ + cv::cuda::CascadeClassifier_CUDA 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(CUDA_ObjDetect, LBP_Read_classifier, + testing::Combine(ALL_DEVICES, testing::Values(0))); + + +PARAM_TEST_CASE(LBP_classify, cv::cuda::DeviceInfo, int) +{ + cv::cuda::DeviceInfo devInfo; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(LBP_classify, Accuracy) +{ + std::string classifierXmlPath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/lbpcascade_frontalface.xml"; + std::string imagePath = std::string(cvtest::TS::ptr()->get_data_path()) + "lbpcascade/er.png"; + + cv::CascadeClassifier cpuClassifier(classifierXmlPath); + ASSERT_FALSE(cpuClassifier.empty()); + + cv::Mat image = cv::imread(imagePath); + image = image.colRange(0, image.cols/2); + cv::Mat grey; + cvtColor(image, grey, cv::COLOR_BGR2GRAY); + ASSERT_FALSE(image.empty()); + + std::vector rects; + cpuClassifier.detectMultiScale(grey, rects); + cv::Mat markedImage = image.clone(); + + std::vector::iterator it = rects.begin(); + for (; it != rects.end(); ++it) + cv::rectangle(markedImage, *it, cv::Scalar(255, 0, 0)); + + cv::cuda::CascadeClassifier_CUDA gpuClassifier; + ASSERT_TRUE(gpuClassifier.load(classifierXmlPath)); + + cv::cuda::GpuMat gpu_rects; + cv::cuda::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(); + for (int i = 0; i < count; i++) + { + cv::Rect r = faces[i]; + + std::cout << r.x << " " << r.y << " " << r.width << " " << r.height << std::endl; + cv::rectangle(markedImage, r , CV_RGB(255, 0, 0)); + } +#endif + +#if defined (LOG_CASCADE_STATISTIC) + cv::imshow("Res", markedImage); cv::waitKey(); +#endif + (void)count; +} + +INSTANTIATE_TEST_CASE_P(CUDA_ObjDetect, LBP_classify, + testing::Combine(ALL_DEVICES, testing::Values(0))); + +#endif // HAVE_CUDA diff --cc modules/cudaarithm/perf/perf_arithm.cpp index 9004155,0000000..42dd772 mode 100644,000000..100644 --- a/modules/cudaarithm/perf/perf_arithm.cpp +++ b/modules/cudaarithm/perf/perf_arithm.cpp @@@ -1,250 -1,0 +1,254 @@@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "perf_precomp.hpp" + +using namespace std; +using namespace testing; +using namespace perf; + +////////////////////////////////////////////////////////////////////// +// GEMM + ++#ifdef HAVE_CUBLAS ++ +CV_FLAGS(GemmFlags, 0, cv::GEMM_1_T, cv::GEMM_2_T, cv::GEMM_3_T) +#define ALL_GEMM_FLAGS 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)) + +DEF_PARAM_TEST(Sz_Type_Flags, cv::Size, MatType, GemmFlags); + +PERF_TEST_P(Sz_Type_Flags, GEMM, + Combine(Values(cv::Size(512, 512), cv::Size(1024, 1024)), + Values(CV_32FC1, CV_32FC2, CV_64FC1), + ALL_GEMM_FLAGS)) +{ + const cv::Size size = GET_PARAM(0); + const int type = GET_PARAM(1); + const int flags = GET_PARAM(2); + + cv::Mat src1(size, type); + declare.in(src1, WARMUP_RNG); + + cv::Mat src2(size, type); + declare.in(src2, WARMUP_RNG); + + cv::Mat src3(size, type); + declare.in(src3, WARMUP_RNG); + + if (PERF_RUN_CUDA()) + { + declare.time(5.0); + + const cv::cuda::GpuMat d_src1(src1); + const cv::cuda::GpuMat d_src2(src2); + const cv::cuda::GpuMat d_src3(src3); + cv::cuda::GpuMat dst; + + TEST_CYCLE() cv::cuda::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, dst, flags); + + CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); + } + else + { + declare.time(50.0); + + cv::Mat dst; + + TEST_CYCLE() cv::gemm(src1, src2, 1.0, src3, 1.0, dst, flags); + + CPU_SANITY_CHECK(dst); + } +} + ++#endif ++ +////////////////////////////////////////////////////////////////////// +// MulSpectrums + +CV_FLAGS(DftFlags, 0, cv::DFT_INVERSE, cv::DFT_SCALE, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT, cv::DFT_REAL_OUTPUT) + +DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags); + +PERF_TEST_P(Sz_Flags, MulSpectrums, + Combine(CUDA_TYPICAL_MAT_SIZES, + Values(0, DftFlags(cv::DFT_ROWS)))) +{ + const cv::Size size = GET_PARAM(0); + const int flag = GET_PARAM(1); + + cv::Mat a(size, CV_32FC2); + cv::Mat b(size, CV_32FC2); + declare.in(a, b, WARMUP_RNG); + + if (PERF_RUN_CUDA()) + { + const cv::cuda::GpuMat d_a(a); + const cv::cuda::GpuMat d_b(b); + cv::cuda::GpuMat dst; + + TEST_CYCLE() cv::cuda::mulSpectrums(d_a, d_b, dst, flag); + + CUDA_SANITY_CHECK(dst); + } + else + { + cv::Mat dst; + + TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag); + + CPU_SANITY_CHECK(dst); + } +} + +////////////////////////////////////////////////////////////////////// +// MulAndScaleSpectrums + +PERF_TEST_P(Sz, MulAndScaleSpectrums, + CUDA_TYPICAL_MAT_SIZES) +{ + const cv::Size size = GetParam(); + + const float scale = 1.f / size.area(); + + cv::Mat src1(size, CV_32FC2); + cv::Mat src2(size, CV_32FC2); + declare.in(src1,src2, WARMUP_RNG); + + if (PERF_RUN_CUDA()) + { + const cv::cuda::GpuMat d_src1(src1); + const cv::cuda::GpuMat d_src2(src2); + cv::cuda::GpuMat dst; + + TEST_CYCLE() cv::cuda::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false); + + CUDA_SANITY_CHECK(dst); + } + else + { + FAIL_NO_CPU(); + } +} + +////////////////////////////////////////////////////////////////////// +// Dft + +PERF_TEST_P(Sz_Flags, Dft, + Combine(CUDA_TYPICAL_MAT_SIZES, + Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE)))) +{ + declare.time(10.0); + + const cv::Size size = GET_PARAM(0); + const int flag = GET_PARAM(1); + + cv::Mat src(size, CV_32FC2); + declare.in(src, WARMUP_RNG); + + if (PERF_RUN_CUDA()) + { + const cv::cuda::GpuMat d_src(src); + cv::cuda::GpuMat dst; + + TEST_CYCLE() cv::cuda::dft(d_src, dst, size, flag); + + CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); + } + else + { + cv::Mat dst; + + TEST_CYCLE() cv::dft(src, dst, flag); + + CPU_SANITY_CHECK(dst); + } +} + +////////////////////////////////////////////////////////////////////// +// Convolve + +DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool); + +PERF_TEST_P(Sz_KernelSz_Ccorr, Convolve, + Combine(CUDA_TYPICAL_MAT_SIZES, + Values(17, 27, 32, 64), + Bool())) +{ + declare.time(10.0); + + const cv::Size size = GET_PARAM(0); + const int templ_size = GET_PARAM(1); + const bool ccorr = GET_PARAM(2); + + const cv::Mat image(size, CV_32FC1); + const cv::Mat templ(templ_size, templ_size, CV_32FC1); + declare.in(image, templ, WARMUP_RNG); + + if (PERF_RUN_CUDA()) + { + cv::cuda::GpuMat d_image = cv::cuda::createContinuous(size, CV_32FC1); + d_image.upload(image); + + cv::cuda::GpuMat d_templ = cv::cuda::createContinuous(templ_size, templ_size, CV_32FC1); + d_templ.upload(templ); + + cv::Ptr convolution = cv::cuda::createConvolution(); + + cv::cuda::GpuMat dst; + + TEST_CYCLE() convolution->convolve(d_image, d_templ, dst, ccorr); + + CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); + } + else + { + if (ccorr) + FAIL_NO_CPU(); + + cv::Mat dst; + + TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ); + + CPU_SANITY_CHECK(dst); + } +} diff --cc modules/cudaarithm/test/test_element_operations.cpp index 8069d28,0000000..4a43d9d mode 100644,000000..100644 --- a/modules/cudaarithm/test/test_element_operations.cpp +++ b/modules/cudaarithm/test/test_element_operations.cpp @@@ -1,2795 -1,0 +1,2795 @@@ +/*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" + +#ifdef HAVE_CUDA + +using namespace cvtest; + +//////////////////////////////////////////////////////////////////////////////// +// Add_Array + +PARAM_TEST_CASE(Add_Array, cv::cuda::DeviceInfo, cv::Size, std::pair, Channels, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + int channels; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + channels = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, channels); + dtype = CV_MAKE_TYPE(depth.second, channels); + } +}; + +CUDA_TEST_P(Add_Array, Accuracy) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(loadMat(mat1), loadMat(mat2), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, dtype, cv::Scalar::all(0)); + cv::add(mat1, mat2, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Add_Array, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + ALL_CHANNELS, + WHOLE_SUBMAT)); + +PARAM_TEST_CASE(Add_Array_Mask, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, 1); + dtype = CV_MAKE_TYPE(depth.second, 1); + } +}; + +CUDA_TEST_P(Add_Array_Mask, Accuracy) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + cv::Mat mask = randomMat(size, CV_8UC1, 0, 2); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(loadMat(mat1), loadMat(mat2), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, dtype, cv::Scalar::all(0)); + cv::add(mat1, mat2, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Add_Array_Mask, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Add_Scalar + +PARAM_TEST_CASE(Add_Scalar, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Add_Scalar, WithOutMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(loadMat(mat), val, dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(loadMat(mat, useRoi), val, dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::add(mat, val, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +CUDA_TEST_P(Add_Scalar, WithMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(loadMat(mat), val, dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(loadMat(mat, useRoi), val, dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::add(mat, val, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Add_Scalar, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Add_Scalar_First + +PARAM_TEST_CASE(Add_Scalar_First, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Add_Scalar_First, WithOutMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(val, loadMat(mat), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(val, loadMat(mat, useRoi), dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::add(val, mat, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +CUDA_TEST_P(Add_Scalar_First, WithMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::add(val, loadMat(mat), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::add(val, loadMat(mat, useRoi), dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::add(val, mat, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Add_Scalar_First, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Subtract_Array + +PARAM_TEST_CASE(Subtract_Array, cv::cuda::DeviceInfo, cv::Size, std::pair, Channels, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + int channels; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + channels = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, channels); + dtype = CV_MAKE_TYPE(depth.second, channels); + } +}; + +CUDA_TEST_P(Subtract_Array, Accuracy) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(loadMat(mat1), loadMat(mat2), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, dtype, cv::Scalar::all(0)); + cv::subtract(mat1, mat2, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Subtract_Array, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + ALL_CHANNELS, + WHOLE_SUBMAT)); + +PARAM_TEST_CASE(Subtract_Array_Mask, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, 1); + dtype = CV_MAKE_TYPE(depth.second, 1); + } +}; + +CUDA_TEST_P(Subtract_Array_Mask, Accuracy) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(loadMat(mat1), loadMat(mat2), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, dtype, cv::Scalar::all(0)); + cv::subtract(mat1, mat2, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Subtract_Array_Mask, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Subtract_Scalar + +PARAM_TEST_CASE(Subtract_Scalar, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Subtract_Scalar, WithOutMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(loadMat(mat), val, dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(loadMat(mat, useRoi), val, dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::subtract(mat, val, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +CUDA_TEST_P(Subtract_Scalar, WithMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(loadMat(mat), val, dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(loadMat(mat, useRoi), val, dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::subtract(mat, val, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Subtract_Scalar, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Subtract_Scalar_First + +PARAM_TEST_CASE(Subtract_Scalar_First, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Subtract_Scalar_First, WithOutMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(val, loadMat(mat), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(val, loadMat(mat, useRoi), dst, cv::cuda::GpuMat(), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::subtract(val, mat, dst_gold, cv::noArray(), depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +CUDA_TEST_P(Subtract_Scalar_First, WithMask) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::subtract(val, loadMat(mat), dst, cv::cuda::GpuMat(), depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + dst.setTo(cv::Scalar::all(0)); + cv::cuda::subtract(val, loadMat(mat, useRoi), dst, loadMat(mask, useRoi), depth.second); + + cv::Mat dst_gold(size, depth.second, cv::Scalar::all(0)); + cv::subtract(val, mat, dst_gold, mask, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Subtract_Scalar_First, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Multiply_Array + +PARAM_TEST_CASE(Multiply_Array, cv::cuda::DeviceInfo, cv::Size, std::pair, Channels, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + int channels; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + channels = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, channels); + dtype = CV_MAKE_TYPE(depth.second, channels); + } +}; + +CUDA_TEST_P(Multiply_Array, WithOutScale) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(loadMat(mat1), loadMat(mat2), dst, 1, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + cv::cuda::multiply(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, 1, depth.second); + + cv::Mat dst_gold; + cv::multiply(mat1, mat2, dst_gold, 1, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-2 : 0.0); + } +} + +CUDA_TEST_P(Multiply_Array, WithScale) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype); + double scale = randomDouble(0.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(loadMat(mat1), loadMat(mat2), dst, scale, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + cv::cuda::multiply(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, scale, depth.second); + + cv::Mat dst_gold; + cv::multiply(mat1, mat2, dst_gold, scale, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, 2.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Multiply_Array, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + ALL_CHANNELS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Multiply_Array_Special + +PARAM_TEST_CASE(Multiply_Array_Special, cv::cuda::DeviceInfo, cv::Size, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + useRoi = GET_PARAM(2); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Multiply_Array_Special, Case_8UC4x_32FC1) +{ + cv::Mat mat1 = randomMat(size, CV_8UC4); + cv::Mat mat2 = randomMat(size, CV_32FC1); + + cv::cuda::GpuMat dst = createMat(size, CV_8UC4, useRoi); + cv::cuda::multiply(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst); + + cv::Mat h_dst(dst); + + for (int y = 0; y < h_dst.rows; ++y) + { + const cv::Vec4b* mat1_row = mat1.ptr(y); + const float* mat2_row = mat2.ptr(y); + const cv::Vec4b* dst_row = h_dst.ptr(y); + + for (int x = 0; x < h_dst.cols; ++x) + { + cv::Vec4b val1 = mat1_row[x]; + float val2 = mat2_row[x]; + cv::Vec4b actual = dst_row[x]; + + cv::Vec4b gold; + + gold[0] = cv::saturate_cast(val1[0] * val2); + gold[1] = cv::saturate_cast(val1[1] * val2); + gold[2] = cv::saturate_cast(val1[2] * val2); + gold[3] = cv::saturate_cast(val1[3] * val2); + + ASSERT_LE(std::abs(gold[0] - actual[0]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + } + } +} + +CUDA_TEST_P(Multiply_Array_Special, Case_16SC4x_32FC1) +{ + cv::Mat mat1 = randomMat(size, CV_16SC4); + cv::Mat mat2 = randomMat(size, CV_32FC1); + + cv::cuda::GpuMat dst = createMat(size, CV_16SC4, useRoi); + cv::cuda::multiply(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst); + + cv::Mat h_dst(dst); + + for (int y = 0; y < h_dst.rows; ++y) + { + const cv::Vec4s* mat1_row = mat1.ptr(y); + const float* mat2_row = mat2.ptr(y); + const cv::Vec4s* dst_row = h_dst.ptr(y); + + for (int x = 0; x < h_dst.cols; ++x) + { + cv::Vec4s val1 = mat1_row[x]; + float val2 = mat2_row[x]; + cv::Vec4s actual = dst_row[x]; + + cv::Vec4s gold; + + gold[0] = cv::saturate_cast(val1[0] * val2); + gold[1] = cv::saturate_cast(val1[1] * val2); + gold[2] = cv::saturate_cast(val1[2] * val2); + gold[3] = cv::saturate_cast(val1[3] * val2); + + ASSERT_LE(std::abs(gold[0] - actual[0]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + } + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Multiply_Array_Special, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Multiply_Scalar + +PARAM_TEST_CASE(Multiply_Scalar, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Multiply_Scalar, WithOutScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(loadMat(mat), val, dst, 1, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::multiply(loadMat(mat, useRoi), val, dst, 1, depth.second); + + cv::Mat dst_gold; + cv::multiply(mat, val, dst_gold, 1, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + } +} + + +CUDA_TEST_P(Multiply_Scalar, WithScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + double scale = randomDouble(0.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(loadMat(mat), val, dst, scale, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::multiply(loadMat(mat, useRoi), val, dst, scale, depth.second); + + cv::Mat dst_gold; + cv::multiply(mat, val, dst_gold, scale, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Multiply_Scalar, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Multiply_Scalar_First + +PARAM_TEST_CASE(Multiply_Scalar_First, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Multiply_Scalar_First, WithOutScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(val, loadMat(mat), dst, 1, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::multiply(val, loadMat(mat, useRoi), dst, 1, depth.second); + + cv::Mat dst_gold; + cv::multiply(val, mat, dst_gold, 1, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + } +} + + +CUDA_TEST_P(Multiply_Scalar_First, WithScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(0, 255); + double scale = randomDouble(0.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::multiply(val, loadMat(mat), dst, scale, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::multiply(val, loadMat(mat, useRoi), dst, scale, depth.second); + + cv::Mat dst_gold; + cv::multiply(val, mat, dst_gold, scale, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Multiply_Scalar_First, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Divide_Array + +PARAM_TEST_CASE(Divide_Array, cv::cuda::DeviceInfo, cv::Size, std::pair, Channels, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + int channels; + bool useRoi; + + int stype; + int dtype; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + channels = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + + stype = CV_MAKE_TYPE(depth.first, channels); + dtype = CV_MAKE_TYPE(depth.second, channels); + } +}; + +CUDA_TEST_P(Divide_Array, WithOutScale) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype, 1.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::divide(loadMat(mat1), loadMat(mat2), dst, 1, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + cv::cuda::divide(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, 1, depth.second); + + cv::Mat dst_gold; + cv::divide(mat1, mat2, dst_gold, 1, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +CUDA_TEST_P(Divide_Array, WithScale) +{ + cv::Mat mat1 = randomMat(size, stype); + cv::Mat mat2 = randomMat(size, stype, 1.0, 255.0); + double scale = randomDouble(0.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::divide(loadMat(mat1), loadMat(mat2), dst, scale, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, dtype, useRoi); + cv::cuda::divide(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst, scale, depth.second); + + cv::Mat dst_gold; + cv::divide(mat1, mat2, dst_gold, scale, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-2 : 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Divide_Array, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + ALL_CHANNELS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Divide_Array_Special + +PARAM_TEST_CASE(Divide_Array_Special, cv::cuda::DeviceInfo, cv::Size, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + useRoi = GET_PARAM(2); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Divide_Array_Special, Case_8UC4x_32FC1) +{ + cv::Mat mat1 = randomMat(size, CV_8UC4); + cv::Mat mat2 = randomMat(size, CV_32FC1, 1.0, 255.0); + + cv::cuda::GpuMat dst = createMat(size, CV_8UC4, useRoi); + cv::cuda::divide(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst); + + cv::Mat h_dst(dst); + + for (int y = 0; y < h_dst.rows; ++y) + { + const cv::Vec4b* mat1_row = mat1.ptr(y); + const float* mat2_row = mat2.ptr(y); + const cv::Vec4b* dst_row = h_dst.ptr(y); + + for (int x = 0; x < h_dst.cols; ++x) + { + cv::Vec4b val1 = mat1_row[x]; + float val2 = mat2_row[x]; + cv::Vec4b actual = dst_row[x]; + + cv::Vec4b gold; + + gold[0] = cv::saturate_cast(val1[0] / val2); + gold[1] = cv::saturate_cast(val1[1] / val2); + gold[2] = cv::saturate_cast(val1[2] / val2); + gold[3] = cv::saturate_cast(val1[3] / val2); + + ASSERT_LE(std::abs(gold[0] - actual[0]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + } + } +} + +CUDA_TEST_P(Divide_Array_Special, Case_16SC4x_32FC1) +{ + cv::Mat mat1 = randomMat(size, CV_16SC4); + cv::Mat mat2 = randomMat(size, CV_32FC1, 1.0, 255.0); + + cv::cuda::GpuMat dst = createMat(size, CV_16SC4, useRoi); + cv::cuda::divide(loadMat(mat1, useRoi), loadMat(mat2, useRoi), dst); + + cv::Mat h_dst(dst); + + for (int y = 0; y < h_dst.rows; ++y) + { + const cv::Vec4s* mat1_row = mat1.ptr(y); + const float* mat2_row = mat2.ptr(y); + const cv::Vec4s* dst_row = h_dst.ptr(y); + + for (int x = 0; x < h_dst.cols; ++x) + { + cv::Vec4s val1 = mat1_row[x]; + float val2 = mat2_row[x]; + cv::Vec4s actual = dst_row[x]; + + cv::Vec4s gold; + + gold[0] = cv::saturate_cast(val1[0] / val2); + gold[1] = cv::saturate_cast(val1[1] / val2); + gold[2] = cv::saturate_cast(val1[2] / val2); + gold[3] = cv::saturate_cast(val1[3] / val2); + + ASSERT_LE(std::abs(gold[0] - actual[0]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + ASSERT_LE(std::abs(gold[1] - actual[1]), 1.0); + } + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Divide_Array_Special, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Divide_Scalar + +PARAM_TEST_CASE(Divide_Scalar, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Divide_Scalar, WithOutScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(1.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::divide(loadMat(mat), val, dst, 1, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::divide(loadMat(mat, useRoi), val, dst, 1, depth.second); + + cv::Mat dst_gold; + cv::divide(mat, val, dst_gold, 1, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +CUDA_TEST_P(Divide_Scalar, WithScale) +{ + cv::Mat mat = randomMat(size, depth.first); + cv::Scalar val = randomScalar(1.0, 255.0); + double scale = randomDouble(0.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::divide(loadMat(mat), val, dst, scale, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::divide(loadMat(mat, useRoi), val, dst, scale, depth.second); + + cv::Mat dst_gold; + cv::divide(mat, val, dst_gold, scale, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-2 : 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Divide_Scalar, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Divide_Scalar_First + +PARAM_TEST_CASE(Divide_Scalar_First, cv::cuda::DeviceInfo, cv::Size, std::pair, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + std::pair depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Divide_Scalar_First, Accuracy) +{ + double scale = randomDouble(0.0, 255.0); + cv::Mat mat = randomMat(size, depth.first, 1.0, 255.0); + + if ((depth.first == CV_64F || depth.second == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::divide(scale, loadMat(mat), dst, depth.second); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth.second, useRoi); + cv::cuda::divide(scale, loadMat(mat, useRoi), dst, depth.second); + + cv::Mat dst_gold; + cv::divide(scale, mat, dst_gold, depth.second); + + EXPECT_MAT_NEAR(dst_gold, dst, depth.first >= CV_32F || depth.second >= CV_32F ? 1e-4 : 1.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Divide_Scalar_First, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + DEPTH_PAIRS, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// AbsDiff + +PARAM_TEST_CASE(AbsDiff, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(AbsDiff, Array) +{ + cv::Mat src1 = randomMat(size, depth); + cv::Mat src2 = randomMat(size, depth); + + if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::absdiff(loadMat(src1), loadMat(src2), dst); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::absdiff(loadMat(src1, useRoi), loadMat(src2, useRoi), dst); + + cv::Mat dst_gold; + cv::absdiff(src1, src2, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, 0.0); + } +} + +CUDA_TEST_P(AbsDiff, Scalar) +{ + cv::Mat src = randomMat(size, depth); + cv::Scalar val = randomScalar(0.0, 255.0); + + if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::absdiff(loadMat(src), val, dst); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::absdiff(loadMat(src, useRoi), val, dst); + + cv::Mat dst_gold; + cv::absdiff(src, val, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth <= CV_32F ? 1.0 : 1e-5); + } +} + +CUDA_TEST_P(AbsDiff, Scalar_First) +{ + cv::Mat src = randomMat(size, depth); + cv::Scalar val = randomScalar(0.0, 255.0); + + if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::absdiff(val, loadMat(src), dst); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::absdiff(val, loadMat(src, useRoi), dst); + + cv::Mat dst_gold; + cv::absdiff(val, src, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth <= CV_32F ? 1.0 : 1e-5); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, AbsDiff, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_DEPTH, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Abs + +PARAM_TEST_CASE(Abs, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Abs, Accuracy) +{ + cv::Mat src = randomMat(size, depth); + + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::abs(loadMat(src, useRoi), dst); + + cv::Mat dst_gold = cv::abs(src); + + EXPECT_MAT_NEAR(dst_gold, dst, 0.0); +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Abs, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + testing::Values(MatDepth(CV_16S), MatDepth(CV_32F)), + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Sqr + +PARAM_TEST_CASE(Sqr, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Sqr, Accuracy) +{ + cv::Mat src = randomMat(size, depth, 0, depth == CV_8U ? 16 : 255); + + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::sqr(loadMat(src, useRoi), dst); + + cv::Mat dst_gold; + cv::multiply(src, src, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, 0.0); +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Sqr, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + testing::Values(MatDepth(CV_8U), + MatDepth(CV_16U), + MatDepth(CV_16S), + MatDepth(CV_32F)), + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Sqrt + +namespace +{ + template void sqrtImpl(const cv::Mat& src, cv::Mat& dst) + { + dst.create(src.size(), src.type()); + + for (int y = 0; y < src.rows; ++y) + { + for (int x = 0; x < src.cols; ++x) + dst.at(y, x) = static_cast(std::sqrt(static_cast(src.at(y, x)))); + } + } + + void sqrtGold(const cv::Mat& src, cv::Mat& dst) + { + typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); + + const func_t funcs[] = + { + sqrtImpl, sqrtImpl, sqrtImpl, sqrtImpl, + sqrtImpl, sqrtImpl + }; + + funcs[src.depth()](src, dst); + } +} + +PARAM_TEST_CASE(Sqrt, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Sqrt, Accuracy) +{ + cv::Mat src = randomMat(size, depth); + + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::sqrt(loadMat(src, useRoi), dst); + + cv::Mat dst_gold; + sqrtGold(src, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-5); +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Sqrt, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + testing::Values(MatDepth(CV_8U), + MatDepth(CV_16U), + MatDepth(CV_16S), + MatDepth(CV_32F)), + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Log + +namespace +{ + template void logImpl(const cv::Mat& src, cv::Mat& dst) + { + dst.create(src.size(), src.type()); + + for (int y = 0; y < src.rows; ++y) + { + for (int x = 0; x < src.cols; ++x) + dst.at(y, x) = static_cast(std::log(static_cast(src.at(y, x)))); + } + } + + void logGold(const cv::Mat& src, cv::Mat& dst) + { + typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); + + const func_t funcs[] = + { + logImpl, logImpl, logImpl, logImpl, + logImpl, logImpl + }; + + funcs[src.depth()](src, dst); + } +} + +PARAM_TEST_CASE(Log, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Log, Accuracy) +{ + cv::Mat src = randomMat(size, depth, 1.0, 255.0); + + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::log(loadMat(src, useRoi), dst); + + cv::Mat dst_gold; + logGold(src, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-6); +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Log, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + testing::Values(MatDepth(CV_8U), + MatDepth(CV_16U), + MatDepth(CV_16S), + MatDepth(CV_32F)), + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Exp + +namespace +{ + template void expImpl(const cv::Mat& src, cv::Mat& dst) + { + dst.create(src.size(), src.type()); + + for (int y = 0; y < src.rows; ++y) + { + for (int x = 0; x < src.cols; ++x) + dst.at(y, x) = cv::saturate_cast(static_cast(std::exp(static_cast(src.at(y, x))))); + } + } + void expImpl_float(const cv::Mat& src, cv::Mat& dst) + { + dst.create(src.size(), src.type()); + + for (int y = 0; y < src.rows; ++y) + { + for (int x = 0; x < src.cols; ++x) + dst.at(y, x) = std::exp(static_cast(src.at(y, x))); + } + } + + void expGold(const cv::Mat& src, cv::Mat& dst) + { + typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst); + + const func_t funcs[] = + { + expImpl, expImpl, expImpl, expImpl, + expImpl, expImpl_float + }; + + funcs[src.depth()](src, dst); + } +} + +PARAM_TEST_CASE(Exp, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Exp, Accuracy) +{ + cv::Mat src = randomMat(size, depth, 0.0, 10.0); + + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::exp(loadMat(src, useRoi), dst); + + cv::Mat dst_gold; + expGold(src, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-2); +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Exp, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + testing::Values(MatDepth(CV_8U), + MatDepth(CV_16U), + MatDepth(CV_16S), + MatDepth(CV_32F)), + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Pow + +PARAM_TEST_CASE(Pow, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + useRoi = GET_PARAM(3); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Pow, Accuracy) +{ + cv::Mat src = randomMat(size, depth, 0.0, 10.0); + double power = randomDouble(2.0, 4.0); + + if (src.depth() < CV_32F) + power = static_cast(power); + + if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::pow(loadMat(src), power, dst); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, depth, useRoi); + cv::cuda::pow(loadMat(src, useRoi), power, dst); + + cv::Mat dst_gold; + cv::pow(src, power, dst_gold); + + EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 0.0 : 1e-1); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Pow, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_DEPTH, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Compare_Array + +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)) + +PARAM_TEST_CASE(Compare_Array, cv::cuda::DeviceInfo, cv::Size, MatDepth, CmpCode, UseRoi) +{ + cv::cuda::DeviceInfo devInfo; + cv::Size size; + int depth; + int cmp_code; + bool useRoi; + + virtual void SetUp() + { + devInfo = GET_PARAM(0); + size = GET_PARAM(1); + depth = GET_PARAM(2); + cmp_code = GET_PARAM(3); + useRoi = GET_PARAM(4); + + cv::cuda::setDevice(devInfo.deviceID()); + } +}; + +CUDA_TEST_P(Compare_Array, Accuracy) +{ + cv::Mat src1 = randomMat(size, depth); + cv::Mat src2 = randomMat(size, depth); + + if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat dst; + cv::cuda::compare(loadMat(src1), loadMat(src2), dst, cmp_code); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat dst = createMat(size, CV_8UC1, useRoi); + cv::cuda::compare(loadMat(src1, useRoi), loadMat(src2, useRoi), dst, cmp_code); + + cv::Mat dst_gold; + cv::compare(src1, src2, dst_gold, cmp_code); + + EXPECT_MAT_NEAR(dst_gold, dst, 0.0); + } +} + +INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Compare_Array, testing::Combine( + ALL_DEVICES, + DIFFERENT_SIZES, + ALL_DEPTH, + ALL_CMP_CODES, + WHOLE_SUBMAT)); + +//////////////////////////////////////////////////////////////////////////////// +// Compare_Scalar + +namespace +{ + template