12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861 |
- /*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 {
- ////////////////////////////////////////////////////////////////////////////////
- // Add_Array
- PARAM_TEST_CASE(Add_Array, cv::cuda::DeviceInfo, cv::Size, std::pair<MatDepth, MatDepth>, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<cv::Vec4b>(y);
- const float* mat2_row = mat2.ptr<float>(y);
- const cv::Vec4b* dst_row = h_dst.ptr<cv::Vec4b>(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<uchar>(val1[0] * val2);
- gold[1] = cv::saturate_cast<uchar>(val1[1] * val2);
- gold[2] = cv::saturate_cast<uchar>(val1[2] * val2);
- gold[3] = cv::saturate_cast<uchar>(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<cv::Vec4s>(y);
- const float* mat2_row = mat2.ptr<float>(y);
- const cv::Vec4s* dst_row = h_dst.ptr<cv::Vec4s>(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<short>(val1[0] * val2);
- gold[1] = cv::saturate_cast<short>(val1[1] * val2);
- gold[2] = cv::saturate_cast<short>(val1[2] * val2);
- gold[3] = cv::saturate_cast<short>(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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<cv::Vec4b>(y);
- const float* mat2_row = mat2.ptr<float>(y);
- const cv::Vec4b* dst_row = h_dst.ptr<cv::Vec4b>(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<uchar>(val1[0] / val2);
- gold[1] = cv::saturate_cast<uchar>(val1[1] / val2);
- gold[2] = cv::saturate_cast<uchar>(val1[2] / val2);
- gold[3] = cv::saturate_cast<uchar>(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<cv::Vec4s>(y);
- const float* mat2_row = mat2.ptr<float>(y);
- const cv::Vec4s* dst_row = h_dst.ptr<cv::Vec4s>(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<short>(val1[0] / val2);
- gold[1] = cv::saturate_cast<short>(val1[1] / val2);
- gold[2] = cv::saturate_cast<short>(val1[2] / val2);
- gold[3] = cv::saturate_cast<short>(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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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<MatDepth, MatDepth>, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- std::pair<MatDepth, MatDepth> 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, 1.0, 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, 1.0, 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 <typename T> 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<T>(y, x) = static_cast<T>(std::sqrt(static_cast<float>(src.at<T>(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<uchar>, sqrtImpl<schar>, sqrtImpl<ushort>, sqrtImpl<short>,
- sqrtImpl<int>, sqrtImpl<float>
- };
- 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 <typename T> 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<T>(y, x) = static_cast<T>(std::log(static_cast<float>(src.at<T>(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<uchar>, logImpl<schar>, logImpl<ushort>, logImpl<short>,
- logImpl<int>, logImpl<float>
- };
- 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 <typename T> 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<T>(y, x) = cv::saturate_cast<T>(static_cast<int>(std::exp(static_cast<float>(src.at<T>(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<float>(y, x) = std::exp(static_cast<float>(src.at<float>(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<uchar>, expImpl<schar>, expImpl<ushort>, expImpl<short>,
- expImpl<int>, 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<int>(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 <template <typename> class Op, typename T>
- void compareScalarImpl(const cv::Mat& src, cv::Scalar sc, cv::Mat& dst)
- {
- Op<T> op;
- const int cn = src.channels();
- dst.create(src.size(), CV_MAKE_TYPE(CV_8U, cn));
- for (int y = 0; y < src.rows; ++y)
- {
- for (int x = 0; x < src.cols; ++x)
- {
- for (int c = 0; c < cn; ++c)
- {
- T src_val = src.at<T>(y, x * cn + c);
- T sc_val = cv::saturate_cast<T>(sc.val[c]);
- dst.at<uchar>(y, x * cn + c) = static_cast<uchar>(static_cast<int>(op(src_val, sc_val)) * 255);
- }
- }
- }
- }
- void compareScalarGold(const cv::Mat& src, cv::Scalar sc, cv::Mat& dst, int cmpop)
- {
- typedef void (*func_t)(const cv::Mat& src, cv::Scalar sc, cv::Mat& dst);
- static const func_t funcs[7][6] =
- {
- {compareScalarImpl<std::equal_to, unsigned char> , compareScalarImpl<std::greater, unsigned char> , compareScalarImpl<std::greater_equal, unsigned char> , compareScalarImpl<std::less, unsigned char> , compareScalarImpl<std::less_equal, unsigned char> , compareScalarImpl<std::not_equal_to, unsigned char> },
- {compareScalarImpl<std::equal_to, signed char> , compareScalarImpl<std::greater, signed char> , compareScalarImpl<std::greater_equal, signed char> , compareScalarImpl<std::less, signed char> , compareScalarImpl<std::less_equal, signed char> , compareScalarImpl<std::not_equal_to, signed char> },
- {compareScalarImpl<std::equal_to, unsigned short>, compareScalarImpl<std::greater, unsigned short>, compareScalarImpl<std::greater_equal, unsigned short>, compareScalarImpl<std::less, unsigned short>, compareScalarImpl<std::less_equal, unsigned short>, compareScalarImpl<std::not_equal_to, unsigned short>},
- {compareScalarImpl<std::equal_to, short> , compareScalarImpl<std::greater, short> , compareScalarImpl<std::greater_equal, short> , compareScalarImpl<std::less, short> , compareScalarImpl<std::less_equal, short> , compareScalarImpl<std::not_equal_to, short> },
- {compareScalarImpl<std::equal_to, int> , compareScalarImpl<std::greater, int> , compareScalarImpl<std::greater_equal, int> , compareScalarImpl<std::less, int> , compareScalarImpl<std::less_equal, int> , compareScalarImpl<std::not_equal_to, int> },
- {compareScalarImpl<std::equal_to, float> , compareScalarImpl<std::greater, float> , compareScalarImpl<std::greater_equal, float> , compareScalarImpl<std::less, float> , compareScalarImpl<std::less_equal, float> , compareScalarImpl<std::not_equal_to, float> },
- {compareScalarImpl<std::equal_to, double> , compareScalarImpl<std::greater, double> , compareScalarImpl<std::greater_equal, double> , compareScalarImpl<std::less, double> , compareScalarImpl<std::less_equal, double> , compareScalarImpl<std::not_equal_to, double> }
- };
- funcs[src.depth()][cmpop](src, sc, dst);
- }
- }
- PARAM_TEST_CASE(Compare_Scalar, cv::cuda::DeviceInfo, cv::Size, MatType, CmpCode, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- int cmp_code;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- cmp_code = GET_PARAM(3);
- useRoi = GET_PARAM(4);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(Compare_Scalar, Accuracy)
- {
- cv::Mat src = randomMat(size, type);
- cv::Scalar sc = randomScalar(0.0, 255.0);
- if (src.depth() < CV_32F)
- {
- sc.val[0] = cvRound(sc.val[0]);
- sc.val[1] = cvRound(sc.val[1]);
- sc.val[2] = cvRound(sc.val[2]);
- sc.val[3] = cvRound(sc.val[3]);
- }
- if (src.depth() == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- cv::cuda::GpuMat dst;
- cv::cuda::compare(loadMat(src), sc, dst, cmp_code);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- cv::cuda::GpuMat dst = createMat(size, CV_MAKE_TYPE(CV_8U, src.channels()), useRoi);
- cv::cuda::compare(loadMat(src, useRoi), sc, dst, cmp_code);
- cv::Mat dst_gold;
- compareScalarGold(src, sc, dst_gold, cmp_code);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Compare_Scalar, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- TYPES(CV_8U, CV_64F, 1, 4),
- ALL_CMP_CODES,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Bitwise_Array
- PARAM_TEST_CASE(Bitwise_Array, cv::cuda::DeviceInfo, cv::Size, MatType)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- cv::Mat src1;
- cv::Mat src2;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- cv::cuda::setDevice(devInfo.deviceID());
- src1 = randomMat(size, type, 0.0, std::numeric_limits<int>::max());
- src2 = randomMat(size, type, 0.0, std::numeric_limits<int>::max());
- }
- };
- CUDA_TEST_P(Bitwise_Array, Not)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_not(loadMat(src1), dst);
- cv::Mat dst_gold = ~src1;
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- CUDA_TEST_P(Bitwise_Array, Or)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_or(loadMat(src1), loadMat(src2), dst);
- cv::Mat dst_gold = src1 | src2;
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- CUDA_TEST_P(Bitwise_Array, And)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_and(loadMat(src1), loadMat(src2), dst);
- cv::Mat dst_gold = src1 & src2;
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- CUDA_TEST_P(Bitwise_Array, Xor)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_xor(loadMat(src1), loadMat(src2), dst);
- cv::Mat dst_gold = src1 ^ src2;
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Bitwise_Array, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- TYPES(CV_8U, CV_32S, 1, 4)));
- //////////////////////////////////////////////////////////////////////////////
- // Bitwise_Scalar
- PARAM_TEST_CASE(Bitwise_Scalar, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int channels;
- cv::Mat src;
- cv::Scalar val;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- depth = GET_PARAM(2);
- channels = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- src = randomMat(size, CV_MAKE_TYPE(depth, channels));
- cv::Scalar_<int> ival = randomScalar(0.0, std::numeric_limits<int>::max());
- val = ival;
- }
- };
- CUDA_TEST_P(Bitwise_Scalar, Or)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_or(loadMat(src), val, dst);
- cv::Mat dst_gold;
- cv::bitwise_or(src, val, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- CUDA_TEST_P(Bitwise_Scalar, And)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_and(loadMat(src), val, dst);
- cv::Mat dst_gold;
- cv::bitwise_and(src, val, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- CUDA_TEST_P(Bitwise_Scalar, Xor)
- {
- cv::cuda::GpuMat dst;
- cv::cuda::bitwise_xor(loadMat(src), val, dst);
- cv::Mat dst_gold;
- cv::bitwise_xor(src, val, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Bitwise_Scalar, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)),
- IMAGE_CHANNELS));
- //////////////////////////////////////////////////////////////////////////////
- // RShift
- namespace
- {
- template <typename T> void rhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
- {
- const int cn = src.channels();
- dst.create(src.size(), src.type());
- for (int y = 0; y < src.rows; ++y)
- {
- for (int x = 0; x < src.cols; ++x)
- {
- for (int c = 0; c < cn; ++c)
- dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) >> val.val[c];
- }
- }
- }
- void rhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
- {
- typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst);
- const func_t funcs[] =
- {
- rhiftImpl<uchar>, rhiftImpl<schar>, rhiftImpl<ushort>, rhiftImpl<short>, rhiftImpl<int>
- };
- funcs[src.depth()](src, val, dst);
- }
- }
- PARAM_TEST_CASE(RShift, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int channels;
- bool useRoi;
- 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());
- }
- };
- CUDA_TEST_P(RShift, Accuracy)
- {
- int type = CV_MAKE_TYPE(depth, channels);
- cv::Mat src = randomMat(size, type);
- cv::Scalar_<int> val = randomScalar(0.0, 8.0);
- cv::cuda::GpuMat dst = createMat(size, type, useRoi);
- cv::cuda::rshift(loadMat(src, useRoi), val, dst);
- cv::Mat dst_gold;
- rhiftGold(src, val, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, RShift, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U),
- MatDepth(CV_8S),
- MatDepth(CV_16U),
- MatDepth(CV_16S),
- MatDepth(CV_32S)),
- IMAGE_CHANNELS,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // LShift
- namespace
- {
- template <typename T> void lhiftImpl(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
- {
- const int cn = src.channels();
- dst.create(src.size(), src.type());
- for (int y = 0; y < src.rows; ++y)
- {
- for (int x = 0; x < src.cols; ++x)
- {
- for (int c = 0; c < cn; ++c)
- dst.at<T>(y, x * cn + c) = src.at<T>(y, x * cn + c) << val.val[c];
- }
- }
- }
- void lhiftGold(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst)
- {
- typedef void (*func_t)(const cv::Mat& src, cv::Scalar_<int> val, cv::Mat& dst);
- const func_t funcs[] =
- {
- lhiftImpl<uchar>, lhiftImpl<schar>, lhiftImpl<ushort>, lhiftImpl<short>, lhiftImpl<int>
- };
- funcs[src.depth()](src, val, dst);
- }
- }
- PARAM_TEST_CASE(LShift, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int channels;
- bool useRoi;
- 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());
- }
- };
- CUDA_TEST_P(LShift, Accuracy)
- {
- int type = CV_MAKE_TYPE(depth, channels);
- cv::Mat src = randomMat(size, type);
- cv::Scalar_<int> val = randomScalar(0.0, 8.0);
- cv::cuda::GpuMat dst = createMat(size, type, useRoi);
- cv::cuda::lshift(loadMat(src, useRoi), val, dst);
- cv::Mat dst_gold;
- lhiftGold(src, val, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, LShift, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32S)),
- IMAGE_CHANNELS,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Min
- PARAM_TEST_CASE(Min, 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(Min, 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::min(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::min(loadMat(src1, useRoi), loadMat(src2, useRoi), dst);
- cv::Mat dst_gold = cv::min(src1, src2);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- }
- CUDA_TEST_P(Min, Scalar)
- {
- cv::Mat src = randomMat(size, depth);
- double val = randomDouble(0.0, 255.0);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- cv::cuda::GpuMat dst;
- cv::cuda::min(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::min(loadMat(src, useRoi), val, dst);
- cv::Mat dst_gold = cv::min(src, val);
- EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-5);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Min, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // Max
- PARAM_TEST_CASE(Max, 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(Max, 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::max(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::max(loadMat(src1, useRoi), loadMat(src2, useRoi), dst);
- cv::Mat dst_gold = cv::max(src1, src2);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- }
- CUDA_TEST_P(Max, Scalar)
- {
- cv::Mat src = randomMat(size, depth);
- double val = randomDouble(0.0, 255.0);
- if (depth == CV_64F && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- cv::cuda::GpuMat dst;
- cv::cuda::max(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::max(loadMat(src, useRoi), val, dst);
- cv::Mat dst_gold = cv::max(src, val);
- EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-5);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Max, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- //////////////////////////////////////////////////////////////////////////////
- // AddWeighted
- PARAM_TEST_CASE(AddWeighted, cv::cuda::DeviceInfo, cv::Size, MatDepth, MatDepth, MatDepth, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth1;
- int depth2;
- int dst_depth;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- depth1 = GET_PARAM(2);
- depth2 = GET_PARAM(3);
- dst_depth = GET_PARAM(4);
- useRoi = GET_PARAM(5);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(AddWeighted, Accuracy)
- {
- cv::Mat src1 = randomMat(size, depth1);
- cv::Mat src2 = randomMat(size, depth2);
- double alpha = randomDouble(-10.0, 10.0);
- double beta = randomDouble(-10.0, 10.0);
- double gamma = randomDouble(-10.0, 10.0);
- if ((depth1 == CV_64F || depth2 == CV_64F || dst_depth == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE))
- {
- try
- {
- cv::cuda::GpuMat dst;
- cv::cuda::addWeighted(loadMat(src1), alpha, loadMat(src2), beta, gamma, dst, dst_depth);
- }
- catch (const cv::Exception& e)
- {
- ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code);
- }
- }
- else
- {
- cv::cuda::GpuMat dst = createMat(size, dst_depth, useRoi);
- cv::cuda::addWeighted(loadMat(src1, useRoi), alpha, loadMat(src2, useRoi), beta, gamma, dst, dst_depth);
- cv::Mat dst_gold;
- cv::addWeighted(src1, alpha, src2, beta, gamma, dst_gold, dst_depth);
- EXPECT_MAT_NEAR(dst_gold, dst, dst_depth < CV_32F ? 2.0 : 1e-3);
- }
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, AddWeighted, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- ALL_DEPTH,
- ALL_DEPTH,
- WHOLE_SUBMAT));
- ///////////////////////////////////////////////////////////////////////////////////////////////////////
- // Threshold
- CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV)
- #define ALL_THRESH_OPS testing::Values(ThreshOp(cv::THRESH_BINARY), ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC), ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV))
- PARAM_TEST_CASE(Threshold, cv::cuda::DeviceInfo, cv::Size, MatType, Channels, ThreshOp, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- int channel;
- int threshOp;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- channel = GET_PARAM(3);
- threshOp = GET_PARAM(4);
- useRoi = GET_PARAM(5);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(Threshold, Accuracy)
- {
- cv::Mat src = randomMat(size, CV_MAKE_TYPE(type, channel));
- double maxVal = randomDouble(20.0, 127.0);
- double thresh = randomDouble(0.0, maxVal);
- cv::cuda::GpuMat dst = createMat(src.size(), src.type(), useRoi);
- cv::cuda::threshold(loadMat(src, useRoi), dst, thresh, maxVal, threshOp);
- cv::Mat dst_gold;
- cv::threshold(src, dst_gold, thresh, maxVal, threshOp);
- EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Threshold, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(MatDepth(CV_8U), MatDepth(CV_16S), MatDepth(CV_32F)),
- ALL_CHANNELS,
- ALL_THRESH_OPS,
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // InRange
- PARAM_TEST_CASE(InRange, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int depth;
- int channels;
- bool useRoi;
- 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());
- }
- };
- CUDA_TEST_P(InRange, Accuracy)
- {
- // Set max value to 127 for signed char
- const int max_bound = (depth == CV_8S) ? 127 : 255;
- // Create lower and upper bound scalars, and make sure lowerb[i] <=
- // upperb[i]
- const cv::Scalar bound1 = randomScalar(0, max_bound);
- const cv::Scalar bound2 = randomScalar(0, max_bound);
- cv::Scalar lowerb, upperb;
- for (int i = 0; i < 4; i++) {
- lowerb[i] = std::min(bound1[i], bound2[i]);
- upperb[i] = std::max(bound1[i], bound2[i]);
- }
- // Create mats and run CPU and GPU versions
- const cv::Mat src = randomMat(size, CV_MAKE_TYPE(depth, channels));
- cv::cuda::GpuMat dst;
- cv::cuda::inRange(loadMat(src, useRoi), lowerb, upperb, dst);
- cv::Mat dst_gold;
- cv::inRange(src, lowerb, upperb, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 0);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, InRange, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- ALL_DEPTH,
- ALL_CHANNELS,
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // Magnitude
- PARAM_TEST_CASE(Magnitude, 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(Magnitude, NPP)
- {
- cv::Mat src = randomMat(size, CV_32FC2);
- cv::cuda::GpuMat dst = createMat(size, CV_32FC1, useRoi);
- cv::cuda::magnitude(loadMat(src, useRoi), dst);
- cv::Mat arr[2];
- cv::split(src, arr);
- cv::Mat dst_gold;
- cv::magnitude(arr[0], arr[1], dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
- }
- CUDA_TEST_P(Magnitude, Sqr_NPP)
- {
- cv::Mat src = randomMat(size, CV_32FC2);
- cv::cuda::GpuMat dst = createMat(size, CV_32FC1, useRoi);
- cv::cuda::magnitudeSqr(loadMat(src, useRoi), dst);
- cv::Mat arr[2];
- cv::split(src, arr);
- cv::Mat dst_gold;
- cv::magnitude(arr[0], arr[1], dst_gold);
- cv::multiply(dst_gold, dst_gold, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 1e-1);
- }
- CUDA_TEST_P(Magnitude, Accuracy)
- {
- cv::Mat x = randomMat(size, CV_32FC1);
- cv::Mat y = randomMat(size, CV_32FC1);
- cv::cuda::GpuMat dst = createMat(size, CV_32FC1, useRoi);
- cv::cuda::magnitude(loadMat(x, useRoi), loadMat(y, useRoi), dst);
- cv::Mat dst_gold;
- cv::magnitude(x, y, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 1e-4);
- }
- CUDA_TEST_P(Magnitude, Sqr_Accuracy)
- {
- cv::Mat x = randomMat(size, CV_32FC1);
- cv::Mat y = randomMat(size, CV_32FC1);
- cv::cuda::GpuMat dst = createMat(size, CV_32FC1, useRoi);
- cv::cuda::magnitudeSqr(loadMat(x, useRoi), loadMat(y, useRoi), dst);
- cv::Mat dst_gold;
- cv::magnitude(x, y, dst_gold);
- cv::multiply(dst_gold, dst_gold, dst_gold);
- EXPECT_MAT_NEAR(dst_gold, dst, 1e-1);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Magnitude, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // Phase
- namespace
- {
- IMPLEMENT_PARAM_CLASS(AngleInDegrees, bool)
- }
- PARAM_TEST_CASE(Phase, cv::cuda::DeviceInfo, cv::Size, AngleInDegrees, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- bool angleInDegrees;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- angleInDegrees = GET_PARAM(2);
- useRoi = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(Phase, Accuracy)
- {
- cv::Mat x = randomMat(size, CV_32FC1);
- cv::Mat y = randomMat(size, CV_32FC1);
- cv::cuda::GpuMat dst = createMat(size, CV_32FC1, useRoi);
- cv::cuda::phase(loadMat(x, useRoi), loadMat(y, useRoi), dst, angleInDegrees);
- cv::Mat dst_gold;
- cv::phase(x, y, dst_gold, angleInDegrees);
- EXPECT_MAT_NEAR(dst_gold, dst, angleInDegrees ? 1e-2 : 1e-3);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, Phase, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // CartToPolar
- PARAM_TEST_CASE(CartToPolar, cv::cuda::DeviceInfo, cv::Size, AngleInDegrees, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- bool angleInDegrees;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- angleInDegrees = GET_PARAM(2);
- useRoi = GET_PARAM(3);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(CartToPolar, Accuracy)
- {
- cv::Mat x = randomMat(size, CV_32FC1);
- cv::Mat y = randomMat(size, CV_32FC1);
- cv::cuda::GpuMat mag = createMat(size, CV_32FC1, useRoi);
- cv::cuda::GpuMat angle = createMat(size, CV_32FC1, useRoi);
- cv::cuda::cartToPolar(loadMat(x, useRoi), loadMat(y, useRoi), mag, angle, angleInDegrees);
- cv::Mat mag_gold;
- cv::Mat angle_gold;
- cv::cartToPolar(x, y, mag_gold, angle_gold, angleInDegrees);
- EXPECT_MAT_NEAR(mag_gold, mag, 1e-4);
- EXPECT_MAT_NEAR(angle_gold, angle, angleInDegrees ? 1e-2 : 1e-3);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, CartToPolar, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
- WHOLE_SUBMAT));
- ////////////////////////////////////////////////////////////////////////////////
- // polarToCart
- PARAM_TEST_CASE(PolarToCart, cv::cuda::DeviceInfo, cv::Size, MatType, AngleInDegrees, UseRoi)
- {
- cv::cuda::DeviceInfo devInfo;
- cv::Size size;
- int type;
- bool angleInDegrees;
- bool useRoi;
- virtual void SetUp()
- {
- devInfo = GET_PARAM(0);
- size = GET_PARAM(1);
- type = GET_PARAM(2);
- angleInDegrees = GET_PARAM(3);
- useRoi = GET_PARAM(4);
- cv::cuda::setDevice(devInfo.deviceID());
- }
- };
- CUDA_TEST_P(PolarToCart, Accuracy)
- {
- cv::Mat magnitude = randomMat(size, type);
- cv::Mat angle = randomMat(size, type);
- const double tol = (type == CV_32FC1 ? 1.6e-4 : 1e-4) * (angleInDegrees ? 1.0 : 19.47);
- cv::cuda::GpuMat x = createMat(size, type, useRoi);
- cv::cuda::GpuMat y = createMat(size, type, useRoi);
- cv::cuda::polarToCart(loadMat(magnitude, useRoi), loadMat(angle, useRoi), x, y, angleInDegrees);
- cv::Mat x_gold;
- cv::Mat y_gold;
- cv::polarToCart(magnitude, angle, x_gold, y_gold, angleInDegrees);
- EXPECT_MAT_NEAR(x_gold, x, tol);
- EXPECT_MAT_NEAR(y_gold, y, tol);
- }
- INSTANTIATE_TEST_CASE_P(CUDA_Arithm, PolarToCart, testing::Combine(
- ALL_DEVICES,
- DIFFERENT_SIZES,
- testing::Values(CV_32FC1, CV_64FC1),
- testing::Values(AngleInDegrees(false), AngleInDegrees(true)),
- WHOLE_SUBMAT));
- }} // namespace
- #endif // HAVE_CUDA
|