12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
- /*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
- namespace opencv_test { namespace {
- ////////////////////////////////////////////////////////////////////////////////
- // Norm
- PARAM_TEST_CASE(Norm, cv::cuda::DeviceInfo, cv::Size, MatDepth, NormCode, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int normCode;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- depth = GET_PARAM(2);
- normCode = GET_PARAM(3);
- useRoi = GET_PARAM(4);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(Norm, Accuracy)
- {
- cv::Mat src = randomMat(size, depth);
- cv::Mat mask = randomMat(size, CV_8UC1, 0, 2);
- double val = cv::cuda::norm(loadMat(src, useRoi), normCode, loadMat(mask, useRoi));
- double val_gold = cv::norm(src, normCode, mask);
- EXPECT_NEAR(val_gold, val, depth < CV_32F ? 0.0 : 1.0);
- }
- CUDA_TEST_P(Norm, Async)
- {
- cv::Mat src = randomMat(size, depth);
- cv::Mat mask = randomMat(size, CV_8UC1, 0, 2);
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::calcNorm(loadMat(src, useRoi), dst, normCode, loadMat(mask, useRoi), stream);
- stream.waitForCompletion();
- double val;
- dst.createMatHeader().convertTo(cv::Mat(1, 1, CV_64FC1, &val), CV_64F);
- double val_gold = cv::norm(src, normCode, mask);
- EXPECT_NEAR(val_gold, val, depth < CV_32F ? 0.0 : 1.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Norm, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U),
- MatDepth(CV_8S),
- MatDepth(CV_16U),
- MatDepth(CV_16S),
- MatDepth(CV_32S),
- MatDepth(CV_32F)),
- testing::Values(NormCode(cv::NORM_L1), NormCode(cv::NORM_L2), NormCode(cv::NORM_INF)),
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // normDiff
- PARAM_TEST_CASE(NormDiff, cv::cuda::DeviceInfo, cv::Size, NormCode, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int normCode;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- normCode = GET_PARAM(2);
- useRoi = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(NormDiff, Accuracy)
- {
- cv::Mat src1 = randomMat(size, CV_8UC1);
- cv::Mat src2 = randomMat(size, CV_8UC1);
- double val = cv::cuda::norm(loadMat(src1, useRoi), loadMat(src2, useRoi), normCode);
- double val_gold = cv::norm(src1, src2, normCode);
- EXPECT_NEAR(val_gold, val, 0.0);
- }
- CUDA_TEST_P(NormDiff, Async)
- {
- cv::Mat src1 = randomMat(size, CV_8UC1);
- cv::Mat src2 = randomMat(size, CV_8UC1);
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::calcNormDiff(loadMat(src1, useRoi), loadMat(src2, useRoi), dst, normCode, stream);
- stream.waitForCompletion();
- double val;
- const cv::Mat val_mat(1, 1, CV_64FC1, &val);
- dst.createMatHeader().convertTo(val_mat, CV_64F);
- double val_gold = cv::norm(src1, src2, normCode);
- EXPECT_NEAR(val_gold, val, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, NormDiff, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(NormCode(cv::NORM_L1), NormCode(cv::NORM_L2), NormCode(cv::NORM_INF)),
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Sum
- namespace
- {
- template <typename T>
- cv::Scalar absSumImpl(const cv::Mat& src)
- {
- const int cn = src.channels();
- cv::Scalar sum = cv::Scalar::all(0);
- for (int y = 0; y < src.rows; ++y)
- {
- for (int x = 0; x < src.cols; ++x)
- {
- for (int c = 0; c < cn; ++c)
- sum[c] += std::abs(src.at<T>(y, x * cn + c));
- }
- }
- return sum;
- }
- cv::Scalar absSumGold(const cv::Mat& src)
- {
- typedef cv::Scalar (*func_t)(const cv::Mat& src);
- static const func_t funcs[] =
- {
- absSumImpl<uchar>,
- absSumImpl<schar>,
- absSumImpl<ushort>,
- absSumImpl<short>,
- absSumImpl<int>,
- absSumImpl<float>,
- absSumImpl<double>
- };
- return funcs[src.depth()](src);
- }
- template <typename T>
- cv::Scalar sqrSumImpl(const cv::Mat& src)
- {
- const int cn = src.channels();
- cv::Scalar sum = cv::Scalar::all(0);
- for (int y = 0; y < src.rows; ++y)
- {
- for (int x = 0; x < src.cols; ++x)
- {
- for (int c = 0; c < cn; ++c)
- {
- const T val = src.at<T>(y, x * cn + c);
- sum[c] += val * val;
- }
- }
- }
- return sum;
- }
- cv::Scalar sqrSumGold(const cv::Mat& src)
- {
- typedef cv::Scalar (*func_t)(const cv::Mat& src);
- static const func_t funcs[] =
- {
- sqrSumImpl<uchar>,
- sqrSumImpl<schar>,
- sqrSumImpl<ushort>,
- sqrSumImpl<short>,
- sqrSumImpl<int>,
- sqrSumImpl<float>,
- sqrSumImpl<double>
- };
- return funcs[src.depth()](src);
- }
- }
- PARAM_TEST_CASE(Sum, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- bool useRoi;
- cv::Mat src;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- useRoi = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- src = randomMat(size, type, -128.0, 128.0);
- }
- };
- CUDA_TEST_P(Sum, Simple)
- {
- cv::Scalar val = cv::cuda::sum(loadMat(src, useRoi));
- cv::Scalar val_gold = cv::sum(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- CUDA_TEST_P(Sum, Simple_Async)
- {
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::calcSum(loadMat(src, useRoi), dst, cv::noArray(), stream);
- stream.waitForCompletion();
- cv::Scalar val;
- cv::Mat val_mat(dst.size(), CV_64FC(dst.channels()), val.val);
- dst.createMatHeader().convertTo(val_mat, CV_64F);
- cv::Scalar val_gold = cv::sum(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- CUDA_TEST_P(Sum, Abs)
- {
- cv::Scalar val = cv::cuda::absSum(loadMat(src, useRoi));
- cv::Scalar val_gold = absSumGold(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- CUDA_TEST_P(Sum, Abs_Async)
- {
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::calcAbsSum(loadMat(src, useRoi), dst, cv::noArray(), stream);
- stream.waitForCompletion();
- cv::Scalar val;
- cv::Mat val_mat(dst.size(), CV_64FC(dst.channels()), val.val);
- dst.createMatHeader().convertTo(val_mat, CV_64F);
- cv::Scalar val_gold = absSumGold(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- CUDA_TEST_P(Sum, Sqr)
- {
- cv::Scalar val = cv::cuda::sqrSum(loadMat(src, useRoi));
- cv::Scalar val_gold = sqrSumGold(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- CUDA_TEST_P(Sum, Sqr_Async)
- {
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::calcSqrSum(loadMat(src, useRoi), dst, cv::noArray(), stream);
- stream.waitForCompletion();
- cv::Scalar val;
- cv::Mat val_mat(dst.size(), CV_64FC(dst.channels()), val.val);
- dst.createMatHeader().convertTo(val_mat, CV_64F);
- cv::Scalar val_gold = sqrSumGold(src);
- EXPECT_SCALAR_NEAR(val_gold, val, CV_MAT_DEPTH(type) < CV_32F ? 0.0 : 0.5);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Sum, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- TYPES(CV_8U, CV_64F, 1, 4),
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // MinMax
- PARAM_TEST_CASE(MinMax, 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(MinMax, WithoutMask)
- {
- cv::Mat src = randomMat(size, depth);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src), &minVal, &maxVal);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src, useRoi), &minVal, &maxVal);
- double minVal_gold, maxVal_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- }
- }
- CUDA_TEST_P(MinMax, Async)
- {
- cv::Mat src = randomMat(size, depth);
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::findMinMax(loadMat(src, useRoi), dst, cv::noArray(), stream);
- stream.waitForCompletion();
- double vals[2];
- const cv::Mat vals_mat(1, 2, CV_64FC1, &vals[0]);
- dst.createMatHeader().convertTo(vals_mat, CV_64F);
- double minVal_gold, maxVal_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, vals[0]);
- EXPECT_DOUBLE_EQ(maxVal_gold, vals[1]);
- }
- CUDA_TEST_P(MinMax, WithMask)
- {
- cv::Mat src = randomMat(size, depth);
- cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src), &minVal, &maxVal, loadMat(mask));
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src, useRoi), &minVal, &maxVal, loadMat(mask, useRoi));
- double minVal_gold, maxVal_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, 0, 0, mask);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- }
- }
- CUDA_TEST_P(MinMax, NullPtr)
- {
- cv::Mat src = randomMat(size, depth);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src), &minVal, 0);
- cv::cuda::minMax(loadMat(src), 0, &maxVal);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::cuda::minMax(loadMat(src, useRoi), &minVal, 0);
- cv::cuda::minMax(loadMat(src, useRoi), 0, &maxVal);
- double minVal_gold, maxVal_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, 0, 0);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, MinMax, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // MinMaxLoc
- namespace
- {
- template <typename T>
- void expectEqualImpl(const cv::Mat& src, cv::Point loc_gold, cv::Point loc)
- {
- EXPECT_EQ(src.at<T>(loc_gold.y, loc_gold.x), src.at<T>(loc.y, loc.x));
- }
- void expectEqual(const cv::Mat& src, cv::Point loc_gold, cv::Point loc)
- {
- typedef void (*func_t)(const cv::Mat& src, cv::Point loc_gold, cv::Point loc);
- static const func_t funcs[] =
- {
- expectEqualImpl<uchar>,
- expectEqualImpl<schar>,
- expectEqualImpl<ushort>,
- expectEqualImpl<short>,
- expectEqualImpl<int>,
- expectEqualImpl<float>,
- expectEqualImpl<double>
- };
- funcs[src.depth()](src, loc_gold, loc);
- }
- }
- PARAM_TEST_CASE(MinMaxLoc, 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(MinMaxLoc, WithoutMask)
- {
- cv::Mat src = randomMat(size, depth);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src), &minVal, &maxVal, &minLoc, &maxLoc);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, &maxVal, &minLoc, &maxLoc);
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- expectEqual(src, minLoc_gold, minLoc);
- expectEqual(src, maxLoc_gold, maxLoc);
- }
- }
- CUDA_TEST_P(MinMaxLoc, OneRowMat)
- {
- cv::Mat src = randomMat(cv::Size(size.width, 1), depth);
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, &maxVal, &minLoc, &maxLoc);
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- expectEqual(src, minLoc_gold, minLoc);
- expectEqual(src, maxLoc_gold, maxLoc);
- }
- CUDA_TEST_P(MinMaxLoc, OneColumnMat)
- {
- cv::Mat src = randomMat(cv::Size(1, size.height), depth);
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, &maxVal, &minLoc, &maxLoc);
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- expectEqual(src, minLoc_gold, minLoc);
- expectEqual(src, maxLoc_gold, maxLoc);
- }
- CUDA_TEST_P(MinMaxLoc, Async)
- {
- cv::Mat src = randomMat(size, depth);
- cv::cuda::Stream stream;
- cv::cuda::HostMem minMaxVals, locVals;
- cv::cuda::findMinMaxLoc(loadMat(src, useRoi), minMaxVals, locVals, cv::noArray(), stream);
- stream.waitForCompletion();
- double vals[2];
- const cv::Mat vals_mat(2, 1, CV_64FC1, &vals[0]);
- minMaxVals.createMatHeader().convertTo(vals_mat, CV_64F);
- int locs[2];
- const cv::Mat locs_mat(2, 1, CV_32SC1, &locs[0]);
- locVals.createMatHeader().copyTo(locs_mat);
- cv::Point locs2D[] = {
- cv::Point(locs[0] % src.cols, locs[0] / src.cols),
- cv::Point(locs[1] % src.cols, locs[1] / src.cols),
- };
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, vals[0]);
- EXPECT_DOUBLE_EQ(maxVal_gold, vals[1]);
- expectEqual(src, minLoc_gold, locs2D[0]);
- expectEqual(src, maxLoc_gold, locs2D[1]);
- }
- CUDA_TEST_P(MinMaxLoc, WithMask)
- {
- cv::Mat src = randomMat(size, depth);
- cv::Mat mask = randomMat(size, CV_8UC1, 0.0, 2.0);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src), &minVal, &maxVal, &minLoc, &maxLoc, loadMat(mask));
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, &maxVal, &minLoc, &maxLoc, loadMat(mask, useRoi));
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold, mask);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- expectEqual(src, minLoc_gold, minLoc);
- expectEqual(src, maxLoc_gold, maxLoc);
- }
- }
- CUDA_TEST_P(MinMaxLoc, NullPtr)
- {
- cv::Mat src = randomMat(size, depth);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, 0, 0, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, &maxVal, 0, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, 0, &minLoc, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, 0, 0, &maxLoc);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- double minVal, maxVal;
- cv::Point minLoc, maxLoc;
- cv::cuda::minMaxLoc(loadMat(src, useRoi), &minVal, 0, 0, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, &maxVal, 0, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, 0, &minLoc, 0);
- cv::cuda::minMaxLoc(loadMat(src, useRoi), 0, 0, 0, &maxLoc);
- double minVal_gold, maxVal_gold;
- cv::Point minLoc_gold, maxLoc_gold;
- minMaxLocGold(src, &minVal_gold, &maxVal_gold, &minLoc_gold, &maxLoc_gold);
- EXPECT_DOUBLE_EQ(minVal_gold, minVal);
- EXPECT_DOUBLE_EQ(maxVal_gold, maxVal);
- expectEqual(src, minLoc_gold, minLoc);
- expectEqual(src, maxLoc_gold, maxLoc);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, MinMaxLoc, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////
- // CountNonZero
- PARAM_TEST_CASE(CountNonZero, cv::cuda::DeviceInfo, cv::Size, MatDepth, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- bool useRoi;
- cv::Mat src;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- depth = GET_PARAM(2);
- useRoi = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- cv::Mat srcBase = randomMat(size, CV_8U, 0.0, 1.5);
- srcBase.convertTo(src, depth);
- }
- };
- CUDA_TEST_P(CountNonZero, Accuracy)
- {
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- cv::cuda::countNonZero(loadMat(src));
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- int val = cv::cuda::countNonZero(loadMat(src, useRoi));
- int val_gold = cv::countNonZero(src);
- ASSERT_EQ(val_gold, val);
- }
- }
- CUDA_TEST_P(CountNonZero, Async)
- {
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::countNonZero(loadMat(src, useRoi), dst, stream);
- stream.waitForCompletion();
- int val;
- const cv::Mat val_mat(1, 1, CV_32SC1, &val);
- dst.createMatHeader().copyTo(val_mat);
- int val_gold = cv::countNonZero(src);
- ASSERT_EQ(val_gold, val);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, CountNonZero, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Reduce
- CV_ENUM(ReduceCode, cv::REDUCE_SUM, cv::REDUCE_AVG, cv::REDUCE_MAX, cv::REDUCE_MIN)
- #define ALL_REDUCE_CODES testing::Values(ReduceCode(cv::REDUCE_SUM), ReduceCode(cv::REDUCE_AVG), ReduceCode(cv::REDUCE_MAX), ReduceCode(cv::REDUCE_MIN))
- PARAM_TEST_CASE(Reduce, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, ReduceCode, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int channels;
- int reduceOp;
- bool useRoi;
- int type;
- int dst_depth;
- int dst_type;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- depth = GET_PARAM(2);
- channels = GET_PARAM(3);
- reduceOp = GET_PARAM(4);
- useRoi = GET_PARAM(5);
- cv::cuda::setDevice(devInfo.deviceID());
- type = CV_MAKE_TYPE(depth, channels);
- if (reduceOp == cv::REDUCE_MAX || reduceOp == cv::REDUCE_MIN)
- dst_depth = depth;
- else if (reduceOp == cv::REDUCE_SUM)
- dst_depth = depth == CV_8U ? CV_32S : depth < CV_64F ? CV_32F : depth;
- else
- dst_depth = depth < CV_32F ? CV_32F : depth;
- dst_type = CV_MAKE_TYPE(dst_depth, channels);
- }
- };
- CUDA_TEST_P(Reduce, Rows)
- {
- cv::Mat src = randomMat(size, type);
- cv::cuda::GpuMat dst = createMat(cv::Size(src.cols, 1), dst_type, useRoi);
- cv::cuda::reduce(loadMat(src, useRoi), dst, 0, reduceOp, dst_depth);
- cv::Mat dst_gold;
- cv::reduce(src, dst_gold, 0, reduceOp, dst_depth);
- EXPECT_MAT_NEAR(dst_gold, dst, dst_depth < CV_32F ? 0.0 : 0.02);
- }
- CUDA_TEST_P(Reduce, Cols)
- {
- cv::Mat src = randomMat(size, type);
- cv::cuda::GpuMat dst;
- cv::cuda::reduce(loadMat(src, useRoi), dst, 1, reduceOp, dst_depth);
- cv::Mat dst_gold;
- cv::reduce(src, dst_gold, 1, reduceOp, dst_depth);
- EXPECT_MAT_NEAR(dst_gold, dst, dst_depth < CV_32F ? 0.0 : 0.02);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Reduce, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U),
- MatDepth(CV_16U),
- MatDepth(CV_16S),
- MatDepth(CV_32F),
- MatDepth(CV_64F)),
- ALL_CHANNELS,
- ALL_REDUCE_CODES,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Normalize
- PARAM_TEST_CASE(Normalize, cv::cuda::DeviceInfo, cv::Size, MatDepth, NormCode, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- int norm_type;
- bool useRoi;
- double alpha;
- double beta;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- norm_type = GET_PARAM(3);
- useRoi = GET_PARAM(4);
- cv::cuda::setDevice(devInfo.deviceID());
- alpha = 1;
- beta = 0;
- }
- };
- CUDA_TEST_P(Normalize, WithOutMask)
- {
- cv::Mat src = randomMat(size, type);
- cv::cuda::GpuMat dst = createMat(size, type, useRoi);
- cv::cuda::normalize(loadMat(src, useRoi), dst, alpha, beta, norm_type, type);
- cv::Mat dst_gold;
- cv::normalize(src, dst_gold, alpha, beta, norm_type, type);
- EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4);
- }
- CUDA_TEST_P(Normalize, WithMask)
- {
- cv::Mat src = randomMat(size, type);
- cv::Mat mask = randomMat(size, CV_8UC1, 0, 2);
- cv::cuda::GpuMat dst = createMat(size, type, useRoi);
- dst.setTo(cv::Scalar::all(0));
- cv::cuda::normalize(loadMat(src, useRoi), dst, alpha, beta, norm_type, -1, loadMat(mask, useRoi));
- cv::Mat dst_gold(size, type);
- dst_gold.setTo(cv::Scalar::all(0));
- cv::normalize(src, dst_gold, alpha, beta, norm_type, -1, mask);
- EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Normalize, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- testing::Values(NormCode(cv::NORM_L1), NormCode(cv::NORM_L2), NormCode(cv::NORM_INF), NormCode(cv::NORM_MINMAX)),
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // MeanStdDev
- PARAM_TEST_CASE(MeanStdDev, 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(MeanStdDev, Accuracy)
- {
- cv::Mat src = randomMat(size, CV_8UC1);
- if (!supportFeature(devInfo, cv::cuda::FEATURE_SET_COMPUTE_13))
- {
- try
- {
- cv::Scalar mean;
- cv::Scalar stddev;
- cv::cuda::meanStdDev(loadMat(src, useRoi), mean, stddev);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsNotImplemented, e.code);
- }
- }
- else
- {
- cv::Scalar mean;
- cv::Scalar stddev;
- cv::cuda::meanStdDev(loadMat(src, useRoi), mean, stddev);
- cv::Scalar mean_gold;
- cv::Scalar stddev_gold;
- cv::meanStdDev(src, mean_gold, stddev_gold);
- EXPECT_SCALAR_NEAR(mean_gold, mean, 1e-5);
- EXPECT_SCALAR_NEAR(stddev_gold, stddev, 1e-5);
- }
- }
- CUDA_TEST_P(MeanStdDev, Async)
- {
- cv::Mat src = randomMat(size, CV_8UC1);
- cv::cuda::Stream stream;
- cv::cuda::HostMem dst;
- cv::cuda::meanStdDev(loadMat(src, useRoi), dst, stream);
- stream.waitForCompletion();
- double vals[2];
- dst.createMatHeader().copyTo(cv::Mat(1, 2, CV_64FC1, &vals[0]));
- cv::Scalar mean_gold;
- cv::Scalar stddev_gold;
- cv::meanStdDev(src, mean_gold, stddev_gold);
- EXPECT_SCALAR_NEAR(mean_gold, cv::Scalar(vals[0]), 1e-5);
- EXPECT_SCALAR_NEAR(stddev_gold, cv::Scalar(vals[1]), 1e-5);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, MeanStdDev, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- WHOLE_SUBMAT));
- ///////////////////////////////////////////////////////////////////////////////////////////////////////
- // Integral
- PARAM_TEST_CASE(Integral, 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(Integral, Accuracy)
- {
- cv::Mat src = randomMat(size, CV_8UC1);
- cv::cuda::GpuMat dst = createMat(cv::Size(src.cols + 1, src.rows + 1), CV_32SC1, useRoi);
- cv::cuda::integral(loadMat(src, useRoi), dst);
- cv::Mat dst_gold;
- cv::integral(src, dst_gold, CV_32S);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Integral, testing::Combine(
- ALL_DEVICES,
- testing::Values(cv::Size(16, 16), cv::Size(128, 128), cv::Size(113, 113), cv::Size(768, 1066)),
- WHOLE_SUBMAT));
- ///////////////////////////////////////////////////////////////////////////////////////////////////////
- // IntegralSqr
- PARAM_TEST_CASE(IntegralSqr, 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(IntegralSqr, Accuracy)
- {
- cv::Mat src = randomMat(size, CV_8UC1);
- cv::cuda::GpuMat dst = createMat(cv::Size(src.cols + 1, src.rows + 1), CV_64FC1, useRoi);
- cv::cuda::sqrIntegral(loadMat(src, useRoi), dst);
- cv::Mat dst_gold, temp;
- cv::integral(src, temp, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, IntegralSqr, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- WHOLE_SUBMAT));
- }} // namespace
- #endif // HAVE_CUDA
|