perf_element_operations.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "perf_precomp.hpp"
  43. namespace opencv_test { namespace {
  44. #define ARITHM_MAT_DEPTH Values(CV_8U, CV_16U, CV_32F, CV_64F)
  45. //////////////////////////////////////////////////////////////////////
  46. // AddMat
  47. DEF_PARAM_TEST(Sz_Depth, cv::Size, MatDepth);
  48. PERF_TEST_P(Sz_Depth, AddMat,
  49. Combine(CUDA_TYPICAL_MAT_SIZES,
  50. ARITHM_MAT_DEPTH))
  51. {
  52. const cv::Size size = GET_PARAM(0);
  53. const int depth = GET_PARAM(1);
  54. cv::Mat src1(size, depth);
  55. declare.in(src1, WARMUP_RNG);
  56. cv::Mat src2(size, depth);
  57. declare.in(src2, WARMUP_RNG);
  58. if (PERF_RUN_CUDA())
  59. {
  60. const cv::cuda::GpuMat d_src1(src1);
  61. const cv::cuda::GpuMat d_src2(src2);
  62. cv::cuda::GpuMat dst;
  63. TEST_CYCLE() cv::cuda::add(d_src1, d_src2, dst);
  64. CUDA_SANITY_CHECK(dst, 1e-10);
  65. }
  66. else
  67. {
  68. cv::Mat dst;
  69. TEST_CYCLE() cv::add(src1, src2, dst);
  70. CPU_SANITY_CHECK(dst);
  71. }
  72. }
  73. //////////////////////////////////////////////////////////////////////
  74. // AddScalar
  75. PERF_TEST_P(Sz_Depth, AddScalar,
  76. Combine(CUDA_TYPICAL_MAT_SIZES,
  77. ARITHM_MAT_DEPTH))
  78. {
  79. const cv::Size size = GET_PARAM(0);
  80. const int depth = GET_PARAM(1);
  81. cv::Mat src(size, depth);
  82. declare.in(src, WARMUP_RNG);
  83. cv::Scalar s;
  84. declare.in(s, WARMUP_RNG);
  85. if (PERF_RUN_CUDA())
  86. {
  87. const cv::cuda::GpuMat d_src(src);
  88. cv::cuda::GpuMat dst;
  89. TEST_CYCLE() cv::cuda::add(d_src, s, dst);
  90. CUDA_SANITY_CHECK(dst, 1e-10);
  91. }
  92. else
  93. {
  94. cv::Mat dst;
  95. TEST_CYCLE() cv::add(src, s, dst);
  96. CPU_SANITY_CHECK(dst);
  97. }
  98. }
  99. //////////////////////////////////////////////////////////////////////
  100. // SubtractMat
  101. PERF_TEST_P(Sz_Depth, SubtractMat,
  102. Combine(CUDA_TYPICAL_MAT_SIZES,
  103. ARITHM_MAT_DEPTH))
  104. {
  105. const cv::Size size = GET_PARAM(0);
  106. const int depth = GET_PARAM(1);
  107. cv::Mat src1(size, depth);
  108. declare.in(src1, WARMUP_RNG);
  109. cv::Mat src2(size, depth);
  110. declare.in(src2, WARMUP_RNG);
  111. if (PERF_RUN_CUDA())
  112. {
  113. const cv::cuda::GpuMat d_src1(src1);
  114. const cv::cuda::GpuMat d_src2(src2);
  115. cv::cuda::GpuMat dst;
  116. TEST_CYCLE() cv::cuda::subtract(d_src1, d_src2, dst);
  117. CUDA_SANITY_CHECK(dst, 1e-10);
  118. }
  119. else
  120. {
  121. cv::Mat dst;
  122. TEST_CYCLE() cv::subtract(src1, src2, dst);
  123. CPU_SANITY_CHECK(dst);
  124. }
  125. }
  126. //////////////////////////////////////////////////////////////////////
  127. // SubtractScalar
  128. PERF_TEST_P(Sz_Depth, SubtractScalar,
  129. Combine(CUDA_TYPICAL_MAT_SIZES,
  130. ARITHM_MAT_DEPTH))
  131. {
  132. const cv::Size size = GET_PARAM(0);
  133. const int depth = GET_PARAM(1);
  134. cv::Mat src(size, depth);
  135. declare.in(src, WARMUP_RNG);
  136. cv::Scalar s;
  137. declare.in(s, WARMUP_RNG);
  138. if (PERF_RUN_CUDA())
  139. {
  140. const cv::cuda::GpuMat d_src(src);
  141. cv::cuda::GpuMat dst;
  142. TEST_CYCLE() cv::cuda::subtract(d_src, s, dst);
  143. CUDA_SANITY_CHECK(dst, 1e-10);
  144. }
  145. else
  146. {
  147. cv::Mat dst;
  148. TEST_CYCLE() cv::subtract(src, s, dst);
  149. CPU_SANITY_CHECK(dst);
  150. }
  151. }
  152. //////////////////////////////////////////////////////////////////////
  153. // MultiplyMat
  154. PERF_TEST_P(Sz_Depth, MultiplyMat,
  155. Combine(CUDA_TYPICAL_MAT_SIZES,
  156. ARITHM_MAT_DEPTH))
  157. {
  158. const cv::Size size = GET_PARAM(0);
  159. const int depth = GET_PARAM(1);
  160. cv::Mat src1(size, depth);
  161. declare.in(src1, WARMUP_RNG);
  162. cv::Mat src2(size, depth);
  163. declare.in(src2, WARMUP_RNG);
  164. if (PERF_RUN_CUDA())
  165. {
  166. const cv::cuda::GpuMat d_src1(src1);
  167. const cv::cuda::GpuMat d_src2(src2);
  168. cv::cuda::GpuMat dst;
  169. TEST_CYCLE() cv::cuda::multiply(d_src1, d_src2, dst);
  170. CUDA_SANITY_CHECK(dst, 1e-6);
  171. }
  172. else
  173. {
  174. cv::Mat dst;
  175. TEST_CYCLE() cv::multiply(src1, src2, dst);
  176. CPU_SANITY_CHECK(dst);
  177. }
  178. }
  179. //////////////////////////////////////////////////////////////////////
  180. // MultiplyScalar
  181. PERF_TEST_P(Sz_Depth, MultiplyScalar,
  182. Combine(CUDA_TYPICAL_MAT_SIZES,
  183. ARITHM_MAT_DEPTH))
  184. {
  185. const cv::Size size = GET_PARAM(0);
  186. const int depth = GET_PARAM(1);
  187. cv::Mat src(size, depth);
  188. declare.in(src, WARMUP_RNG);
  189. cv::Scalar s;
  190. declare.in(s, WARMUP_RNG);
  191. if (PERF_RUN_CUDA())
  192. {
  193. const cv::cuda::GpuMat d_src(src);
  194. cv::cuda::GpuMat dst;
  195. TEST_CYCLE() cv::cuda::multiply(d_src, s, dst);
  196. CUDA_SANITY_CHECK(dst, 1e-6);
  197. }
  198. else
  199. {
  200. cv::Mat dst;
  201. TEST_CYCLE() cv::multiply(src, s, dst);
  202. CPU_SANITY_CHECK(dst);
  203. }
  204. }
  205. //////////////////////////////////////////////////////////////////////
  206. // DivideMat
  207. PERF_TEST_P(Sz_Depth, DivideMat,
  208. Combine(CUDA_TYPICAL_MAT_SIZES,
  209. ARITHM_MAT_DEPTH))
  210. {
  211. const cv::Size size = GET_PARAM(0);
  212. const int depth = GET_PARAM(1);
  213. cv::Mat src1(size, depth);
  214. declare.in(src1, WARMUP_RNG);
  215. cv::Mat src2(size, depth);
  216. declare.in(src2, WARMUP_RNG);
  217. if (PERF_RUN_CUDA())
  218. {
  219. const cv::cuda::GpuMat d_src1(src1);
  220. const cv::cuda::GpuMat d_src2(src2);
  221. cv::cuda::GpuMat dst;
  222. TEST_CYCLE() cv::cuda::divide(d_src1, d_src2, dst);
  223. CUDA_SANITY_CHECK(dst, 1e-6);
  224. }
  225. else
  226. {
  227. cv::Mat dst;
  228. TEST_CYCLE() cv::divide(src1, src2, dst);
  229. CPU_SANITY_CHECK(dst);
  230. }
  231. }
  232. //////////////////////////////////////////////////////////////////////
  233. // DivideScalar
  234. PERF_TEST_P(Sz_Depth, DivideScalar,
  235. Combine(CUDA_TYPICAL_MAT_SIZES,
  236. ARITHM_MAT_DEPTH))
  237. {
  238. const cv::Size size = GET_PARAM(0);
  239. const int depth = GET_PARAM(1);
  240. cv::Mat src(size, depth);
  241. declare.in(src, WARMUP_RNG);
  242. cv::Scalar s;
  243. declare.in(s, WARMUP_RNG);
  244. if (PERF_RUN_CUDA())
  245. {
  246. const cv::cuda::GpuMat d_src(src);
  247. cv::cuda::GpuMat dst;
  248. TEST_CYCLE() cv::cuda::divide(d_src, s, dst);
  249. CUDA_SANITY_CHECK(dst, 1e-6);
  250. }
  251. else
  252. {
  253. cv::Mat dst;
  254. TEST_CYCLE() cv::divide(src, s, dst);
  255. CPU_SANITY_CHECK(dst);
  256. }
  257. }
  258. //////////////////////////////////////////////////////////////////////
  259. // DivideScalarInv
  260. PERF_TEST_P(Sz_Depth, DivideScalarInv,
  261. Combine(CUDA_TYPICAL_MAT_SIZES,
  262. ARITHM_MAT_DEPTH))
  263. {
  264. const cv::Size size = GET_PARAM(0);
  265. const int depth = GET_PARAM(1);
  266. cv::Mat src(size, depth);
  267. declare.in(src, WARMUP_RNG);
  268. cv::Scalar s;
  269. declare.in(s, WARMUP_RNG);
  270. if (PERF_RUN_CUDA())
  271. {
  272. const cv::cuda::GpuMat d_src(src);
  273. cv::cuda::GpuMat dst;
  274. TEST_CYCLE() cv::cuda::divide(s[0], d_src, dst);
  275. CUDA_SANITY_CHECK(dst, 1e-6);
  276. }
  277. else
  278. {
  279. cv::Mat dst;
  280. TEST_CYCLE() cv::divide(s, src, dst);
  281. CPU_SANITY_CHECK(dst);
  282. }
  283. }
  284. //////////////////////////////////////////////////////////////////////
  285. // AbsDiffMat
  286. PERF_TEST_P(Sz_Depth, AbsDiffMat,
  287. Combine(CUDA_TYPICAL_MAT_SIZES,
  288. ARITHM_MAT_DEPTH))
  289. {
  290. const cv::Size size = GET_PARAM(0);
  291. const int depth = GET_PARAM(1);
  292. cv::Mat src1(size, depth);
  293. declare.in(src1, WARMUP_RNG);
  294. cv::Mat src2(size, depth);
  295. declare.in(src2, WARMUP_RNG);
  296. if (PERF_RUN_CUDA())
  297. {
  298. const cv::cuda::GpuMat d_src1(src1);
  299. const cv::cuda::GpuMat d_src2(src2);
  300. cv::cuda::GpuMat dst;
  301. TEST_CYCLE() cv::cuda::absdiff(d_src1, d_src2, dst);
  302. CUDA_SANITY_CHECK(dst, 1e-10);
  303. }
  304. else
  305. {
  306. cv::Mat dst;
  307. TEST_CYCLE() cv::absdiff(src1, src2, dst);
  308. CPU_SANITY_CHECK(dst);
  309. }
  310. }
  311. //////////////////////////////////////////////////////////////////////
  312. // AbsDiffScalar
  313. PERF_TEST_P(Sz_Depth, AbsDiffScalar,
  314. Combine(CUDA_TYPICAL_MAT_SIZES,
  315. ARITHM_MAT_DEPTH))
  316. {
  317. const cv::Size size = GET_PARAM(0);
  318. const int depth = GET_PARAM(1);
  319. cv::Mat src(size, depth);
  320. declare.in(src, WARMUP_RNG);
  321. cv::Scalar s;
  322. declare.in(s, WARMUP_RNG);
  323. if (PERF_RUN_CUDA())
  324. {
  325. const cv::cuda::GpuMat d_src(src);
  326. cv::cuda::GpuMat dst;
  327. TEST_CYCLE() cv::cuda::absdiff(d_src, s, dst);
  328. CUDA_SANITY_CHECK(dst, 1e-10);
  329. }
  330. else
  331. {
  332. cv::Mat dst;
  333. TEST_CYCLE() cv::absdiff(src, s, dst);
  334. CPU_SANITY_CHECK(dst);
  335. }
  336. }
  337. //////////////////////////////////////////////////////////////////////
  338. // Abs
  339. PERF_TEST_P(Sz_Depth, Abs,
  340. Combine(CUDA_TYPICAL_MAT_SIZES,
  341. Values(CV_16S, CV_32F)))
  342. {
  343. const cv::Size size = GET_PARAM(0);
  344. const int depth = GET_PARAM(1);
  345. cv::Mat src(size, depth);
  346. declare.in(src, WARMUP_RNG);
  347. if (PERF_RUN_CUDA())
  348. {
  349. const cv::cuda::GpuMat d_src(src);
  350. cv::cuda::GpuMat dst;
  351. TEST_CYCLE() cv::cuda::abs(d_src, dst);
  352. CUDA_SANITY_CHECK(dst);
  353. }
  354. else
  355. {
  356. FAIL_NO_CPU();
  357. }
  358. }
  359. //////////////////////////////////////////////////////////////////////
  360. // Sqr
  361. PERF_TEST_P(Sz_Depth, Sqr,
  362. Combine(CUDA_TYPICAL_MAT_SIZES,
  363. Values(CV_8U, CV_16S, CV_32F)))
  364. {
  365. const cv::Size size = GET_PARAM(0);
  366. const int depth = GET_PARAM(1);
  367. cv::Mat src(size, depth);
  368. declare.in(src, WARMUP_RNG);
  369. if (PERF_RUN_CUDA())
  370. {
  371. const cv::cuda::GpuMat d_src(src);
  372. cv::cuda::GpuMat dst;
  373. TEST_CYCLE() cv::cuda::sqr(d_src, dst);
  374. CUDA_SANITY_CHECK(dst);
  375. }
  376. else
  377. {
  378. FAIL_NO_CPU();
  379. }
  380. }
  381. //////////////////////////////////////////////////////////////////////
  382. // Sqrt
  383. PERF_TEST_P(Sz_Depth, Sqrt,
  384. Combine(CUDA_TYPICAL_MAT_SIZES,
  385. Values(CV_8U, CV_16S, CV_32F)))
  386. {
  387. const cv::Size size = GET_PARAM(0);
  388. const int depth = GET_PARAM(1);
  389. cv::Mat src(size, depth);
  390. cv::randu(src, 0, 100000);
  391. if (PERF_RUN_CUDA())
  392. {
  393. const cv::cuda::GpuMat d_src(src);
  394. cv::cuda::GpuMat dst;
  395. TEST_CYCLE() cv::cuda::sqrt(d_src, dst);
  396. CUDA_SANITY_CHECK(dst);
  397. }
  398. else
  399. {
  400. cv::Mat dst;
  401. TEST_CYCLE() cv::sqrt(src, dst);
  402. CPU_SANITY_CHECK(dst);
  403. }
  404. }
  405. //////////////////////////////////////////////////////////////////////
  406. // Log
  407. PERF_TEST_P(Sz_Depth, Log,
  408. Combine(CUDA_TYPICAL_MAT_SIZES,
  409. Values(CV_8U, CV_16S, CV_32F)))
  410. {
  411. const cv::Size size = GET_PARAM(0);
  412. const int depth = GET_PARAM(1);
  413. cv::Mat src(size, depth);
  414. cv::randu(src, 0, 100000);
  415. if (PERF_RUN_CUDA())
  416. {
  417. const cv::cuda::GpuMat d_src(src);
  418. cv::cuda::GpuMat dst;
  419. TEST_CYCLE() cv::cuda::log(d_src, dst);
  420. CUDA_SANITY_CHECK(dst);
  421. }
  422. else
  423. {
  424. cv::Mat dst;
  425. TEST_CYCLE() cv::log(src, dst);
  426. CPU_SANITY_CHECK(dst);
  427. }
  428. }
  429. //////////////////////////////////////////////////////////////////////
  430. // Exp
  431. PERF_TEST_P(Sz_Depth, Exp,
  432. Combine(CUDA_TYPICAL_MAT_SIZES,
  433. Values(CV_8U, CV_16S, CV_32F)))
  434. {
  435. const cv::Size size = GET_PARAM(0);
  436. const int depth = GET_PARAM(1);
  437. cv::Mat src(size, depth);
  438. cv::randu(src, 0, 10);
  439. if (PERF_RUN_CUDA())
  440. {
  441. const cv::cuda::GpuMat d_src(src);
  442. cv::cuda::GpuMat dst;
  443. TEST_CYCLE() cv::cuda::exp(d_src, dst);
  444. CUDA_SANITY_CHECK(dst);
  445. }
  446. else
  447. {
  448. cv::Mat dst;
  449. TEST_CYCLE() cv::exp(src, dst);
  450. CPU_SANITY_CHECK(dst);
  451. }
  452. }
  453. //////////////////////////////////////////////////////////////////////
  454. // Pow
  455. DEF_PARAM_TEST(Sz_Depth_Power, cv::Size, MatDepth, double);
  456. PERF_TEST_P(Sz_Depth_Power, Pow,
  457. Combine(CUDA_TYPICAL_MAT_SIZES,
  458. Values(CV_8U, CV_16S, CV_32F),
  459. Values(0.3, 2.0, 2.4)))
  460. {
  461. const cv::Size size = GET_PARAM(0);
  462. const int depth = GET_PARAM(1);
  463. const double power = GET_PARAM(2);
  464. cv::Mat src(size, depth);
  465. declare.in(src, WARMUP_RNG);
  466. if (PERF_RUN_CUDA())
  467. {
  468. const cv::cuda::GpuMat d_src(src);
  469. cv::cuda::GpuMat dst;
  470. TEST_CYCLE() cv::cuda::pow(d_src, power, dst);
  471. CUDA_SANITY_CHECK(dst);
  472. }
  473. else
  474. {
  475. cv::Mat dst;
  476. TEST_CYCLE() cv::pow(src, power, dst);
  477. CPU_SANITY_CHECK(dst);
  478. }
  479. }
  480. //////////////////////////////////////////////////////////////////////
  481. // CompareMat
  482. CV_ENUM(CmpCode, cv::CMP_EQ, cv::CMP_GT, cv::CMP_GE, cv::CMP_LT, cv::CMP_LE, cv::CMP_NE)
  483. DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CmpCode);
  484. PERF_TEST_P(Sz_Depth_Code, CompareMat,
  485. Combine(CUDA_TYPICAL_MAT_SIZES,
  486. ARITHM_MAT_DEPTH,
  487. CmpCode::all()))
  488. {
  489. const cv::Size size = GET_PARAM(0);
  490. const int depth = GET_PARAM(1);
  491. const int cmp_code = GET_PARAM(2);
  492. cv::Mat src1(size, depth);
  493. declare.in(src1, WARMUP_RNG);
  494. cv::Mat src2(size, depth);
  495. declare.in(src2, WARMUP_RNG);
  496. if (PERF_RUN_CUDA())
  497. {
  498. const cv::cuda::GpuMat d_src1(src1);
  499. const cv::cuda::GpuMat d_src2(src2);
  500. cv::cuda::GpuMat dst;
  501. TEST_CYCLE() cv::cuda::compare(d_src1, d_src2, dst, cmp_code);
  502. CUDA_SANITY_CHECK(dst);
  503. }
  504. else
  505. {
  506. cv::Mat dst;
  507. TEST_CYCLE() cv::compare(src1, src2, dst, cmp_code);
  508. CPU_SANITY_CHECK(dst);
  509. }
  510. }
  511. //////////////////////////////////////////////////////////////////////
  512. // CompareScalar
  513. PERF_TEST_P(Sz_Depth_Code, CompareScalar,
  514. Combine(CUDA_TYPICAL_MAT_SIZES,
  515. ARITHM_MAT_DEPTH,
  516. CmpCode::all()))
  517. {
  518. const cv::Size size = GET_PARAM(0);
  519. const int depth = GET_PARAM(1);
  520. const int cmp_code = GET_PARAM(2);
  521. cv::Mat src(size, depth);
  522. declare.in(src, WARMUP_RNG);
  523. cv::Scalar s;
  524. declare.in(s, WARMUP_RNG);
  525. if (PERF_RUN_CUDA())
  526. {
  527. const cv::cuda::GpuMat d_src(src);
  528. cv::cuda::GpuMat dst;
  529. TEST_CYCLE() cv::cuda::compare(d_src, s, dst, cmp_code);
  530. CUDA_SANITY_CHECK(dst);
  531. }
  532. else
  533. {
  534. cv::Mat dst;
  535. TEST_CYCLE() cv::compare(src, s, dst, cmp_code);
  536. CPU_SANITY_CHECK(dst);
  537. }
  538. }
  539. //////////////////////////////////////////////////////////////////////
  540. // BitwiseNot
  541. PERF_TEST_P(Sz_Depth, BitwiseNot,
  542. Combine(CUDA_TYPICAL_MAT_SIZES,
  543. Values(CV_8U, CV_16U, CV_32S)))
  544. {
  545. const cv::Size size = GET_PARAM(0);
  546. const int depth = GET_PARAM(1);
  547. cv::Mat src(size, depth);
  548. declare.in(src, WARMUP_RNG);
  549. if (PERF_RUN_CUDA())
  550. {
  551. const cv::cuda::GpuMat d_src(src);
  552. cv::cuda::GpuMat dst;
  553. TEST_CYCLE() cv::cuda::bitwise_not(d_src, dst);
  554. CUDA_SANITY_CHECK(dst);
  555. }
  556. else
  557. {
  558. cv::Mat dst;
  559. TEST_CYCLE() cv::bitwise_not(src, dst);
  560. CPU_SANITY_CHECK(dst);
  561. }
  562. }
  563. //////////////////////////////////////////////////////////////////////
  564. // BitwiseAndMat
  565. PERF_TEST_P(Sz_Depth, BitwiseAndMat,
  566. Combine(CUDA_TYPICAL_MAT_SIZES,
  567. Values(CV_8U, CV_16U, CV_32S)))
  568. {
  569. const cv::Size size = GET_PARAM(0);
  570. const int depth = GET_PARAM(1);
  571. cv::Mat src1(size, depth);
  572. declare.in(src1, WARMUP_RNG);
  573. cv::Mat src2(size, depth);
  574. declare.in(src2, WARMUP_RNG);
  575. if (PERF_RUN_CUDA())
  576. {
  577. const cv::cuda::GpuMat d_src1(src1);
  578. const cv::cuda::GpuMat d_src2(src2);
  579. cv::cuda::GpuMat dst;
  580. TEST_CYCLE() cv::cuda::bitwise_and(d_src1, d_src2, dst);
  581. CUDA_SANITY_CHECK(dst);
  582. }
  583. else
  584. {
  585. cv::Mat dst;
  586. TEST_CYCLE() cv::bitwise_and(src1, src2, dst);
  587. CPU_SANITY_CHECK(dst);
  588. }
  589. }
  590. //////////////////////////////////////////////////////////////////////
  591. // BitwiseAndScalar
  592. DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, MatCn);
  593. PERF_TEST_P(Sz_Depth_Cn, BitwiseAndScalar,
  594. Combine(CUDA_TYPICAL_MAT_SIZES,
  595. Values(CV_8U, CV_16U, CV_32S),
  596. CUDA_CHANNELS_1_3_4))
  597. {
  598. const cv::Size size = GET_PARAM(0);
  599. const int depth = GET_PARAM(1);
  600. const int channels = GET_PARAM(2);
  601. const int type = CV_MAKE_TYPE(depth, channels);
  602. cv::Mat src(size, type);
  603. declare.in(src, WARMUP_RNG);
  604. cv::Scalar s;
  605. declare.in(s, WARMUP_RNG);
  606. cv::Scalar_<int> is = s;
  607. if (PERF_RUN_CUDA())
  608. {
  609. const cv::cuda::GpuMat d_src(src);
  610. cv::cuda::GpuMat dst;
  611. TEST_CYCLE() cv::cuda::bitwise_and(d_src, is, dst);
  612. CUDA_SANITY_CHECK(dst);
  613. }
  614. else
  615. {
  616. cv::Mat dst;
  617. TEST_CYCLE() cv::bitwise_and(src, is, dst);
  618. CPU_SANITY_CHECK(dst);
  619. }
  620. }
  621. //////////////////////////////////////////////////////////////////////
  622. // BitwiseOrMat
  623. PERF_TEST_P(Sz_Depth, BitwiseOrMat,
  624. Combine(CUDA_TYPICAL_MAT_SIZES,
  625. Values(CV_8U, CV_16U, CV_32S)))
  626. {
  627. const cv::Size size = GET_PARAM(0);
  628. const int depth = GET_PARAM(1);
  629. cv::Mat src1(size, depth);
  630. declare.in(src1, WARMUP_RNG);
  631. cv::Mat src2(size, depth);
  632. declare.in(src2, WARMUP_RNG);
  633. if (PERF_RUN_CUDA())
  634. {
  635. const cv::cuda::GpuMat d_src1(src1);
  636. const cv::cuda::GpuMat d_src2(src2);
  637. cv::cuda::GpuMat dst;
  638. TEST_CYCLE() cv::cuda::bitwise_or(d_src1, d_src2, dst);
  639. CUDA_SANITY_CHECK(dst);
  640. }
  641. else
  642. {
  643. cv::Mat dst;
  644. TEST_CYCLE() cv::bitwise_or(src1, src2, dst);
  645. CPU_SANITY_CHECK(dst);
  646. }
  647. }
  648. //////////////////////////////////////////////////////////////////////
  649. // BitwiseOrScalar
  650. PERF_TEST_P(Sz_Depth_Cn, BitwiseOrScalar,
  651. Combine(CUDA_TYPICAL_MAT_SIZES,
  652. Values(CV_8U, CV_16U, CV_32S),
  653. CUDA_CHANNELS_1_3_4))
  654. {
  655. const cv::Size size = GET_PARAM(0);
  656. const int depth = GET_PARAM(1);
  657. const int channels = GET_PARAM(2);
  658. const int type = CV_MAKE_TYPE(depth, channels);
  659. cv::Mat src(size, type);
  660. declare.in(src, WARMUP_RNG);
  661. cv::Scalar s;
  662. declare.in(s, WARMUP_RNG);
  663. cv::Scalar_<int> is = s;
  664. if (PERF_RUN_CUDA())
  665. {
  666. const cv::cuda::GpuMat d_src(src);
  667. cv::cuda::GpuMat dst;
  668. TEST_CYCLE() cv::cuda::bitwise_or(d_src, is, dst);
  669. CUDA_SANITY_CHECK(dst);
  670. }
  671. else
  672. {
  673. cv::Mat dst;
  674. TEST_CYCLE() cv::bitwise_or(src, is, dst);
  675. CPU_SANITY_CHECK(dst);
  676. }
  677. }
  678. //////////////////////////////////////////////////////////////////////
  679. // BitwiseXorMat
  680. PERF_TEST_P(Sz_Depth, BitwiseXorMat,
  681. Combine(CUDA_TYPICAL_MAT_SIZES,
  682. Values(CV_8U, CV_16U, CV_32S)))
  683. {
  684. const cv::Size size = GET_PARAM(0);
  685. const int depth = GET_PARAM(1);
  686. cv::Mat src1(size, depth);
  687. declare.in(src1, WARMUP_RNG);
  688. cv::Mat src2(size, depth);
  689. declare.in(src2, WARMUP_RNG);
  690. if (PERF_RUN_CUDA())
  691. {
  692. const cv::cuda::GpuMat d_src1(src1);
  693. const cv::cuda::GpuMat d_src2(src2);
  694. cv::cuda::GpuMat dst;
  695. TEST_CYCLE() cv::cuda::bitwise_xor(d_src1, d_src2, dst);
  696. CUDA_SANITY_CHECK(dst);
  697. }
  698. else
  699. {
  700. cv::Mat dst;
  701. TEST_CYCLE() cv::bitwise_xor(src1, src2, dst);
  702. CPU_SANITY_CHECK(dst);
  703. }
  704. }
  705. //////////////////////////////////////////////////////////////////////
  706. // BitwiseXorScalar
  707. PERF_TEST_P(Sz_Depth_Cn, BitwiseXorScalar,
  708. Combine(CUDA_TYPICAL_MAT_SIZES,
  709. Values(CV_8U, CV_16U, CV_32S),
  710. CUDA_CHANNELS_1_3_4))
  711. {
  712. const cv::Size size = GET_PARAM(0);
  713. const int depth = GET_PARAM(1);
  714. const int channels = GET_PARAM(2);
  715. const int type = CV_MAKE_TYPE(depth, channels);
  716. cv::Mat src(size, type);
  717. declare.in(src, WARMUP_RNG);
  718. cv::Scalar s;
  719. declare.in(s, WARMUP_RNG);
  720. cv::Scalar_<int> is = s;
  721. if (PERF_RUN_CUDA())
  722. {
  723. const cv::cuda::GpuMat d_src(src);
  724. cv::cuda::GpuMat dst;
  725. TEST_CYCLE() cv::cuda::bitwise_xor(d_src, is, dst);
  726. CUDA_SANITY_CHECK(dst);
  727. }
  728. else
  729. {
  730. cv::Mat dst;
  731. TEST_CYCLE() cv::bitwise_xor(src, is, dst);
  732. CPU_SANITY_CHECK(dst);
  733. }
  734. }
  735. //////////////////////////////////////////////////////////////////////
  736. // RShift
  737. PERF_TEST_P(Sz_Depth_Cn, RShift,
  738. Combine(CUDA_TYPICAL_MAT_SIZES,
  739. Values(CV_8U, CV_16U, CV_32S),
  740. CUDA_CHANNELS_1_3_4))
  741. {
  742. const cv::Size size = GET_PARAM(0);
  743. const int depth = GET_PARAM(1);
  744. const int channels = GET_PARAM(2);
  745. const int type = CV_MAKE_TYPE(depth, channels);
  746. cv::Mat src(size, type);
  747. declare.in(src, WARMUP_RNG);
  748. const cv::Scalar_<int> val = cv::Scalar_<int>::all(4);
  749. if (PERF_RUN_CUDA())
  750. {
  751. const cv::cuda::GpuMat d_src(src);
  752. cv::cuda::GpuMat dst;
  753. TEST_CYCLE() cv::cuda::rshift(d_src, val, dst);
  754. CUDA_SANITY_CHECK(dst);
  755. }
  756. else
  757. {
  758. FAIL_NO_CPU();
  759. }
  760. }
  761. //////////////////////////////////////////////////////////////////////
  762. // LShift
  763. PERF_TEST_P(Sz_Depth_Cn, LShift,
  764. Combine(CUDA_TYPICAL_MAT_SIZES,
  765. Values(CV_8U, CV_16U, CV_32S),
  766. CUDA_CHANNELS_1_3_4))
  767. {
  768. const cv::Size size = GET_PARAM(0);
  769. const int depth = GET_PARAM(1);
  770. const int channels = GET_PARAM(2);
  771. const int type = CV_MAKE_TYPE(depth, channels);
  772. cv::Mat src(size, type);
  773. declare.in(src, WARMUP_RNG);
  774. const cv::Scalar_<int> val = cv::Scalar_<int>::all(4);
  775. if (PERF_RUN_CUDA())
  776. {
  777. const cv::cuda::GpuMat d_src(src);
  778. cv::cuda::GpuMat dst;
  779. TEST_CYCLE() cv::cuda::lshift(d_src, val, dst);
  780. CUDA_SANITY_CHECK(dst);
  781. }
  782. else
  783. {
  784. FAIL_NO_CPU();
  785. }
  786. }
  787. //////////////////////////////////////////////////////////////////////
  788. // MinMat
  789. PERF_TEST_P(Sz_Depth, MinMat,
  790. Combine(CUDA_TYPICAL_MAT_SIZES,
  791. Values(CV_8U, CV_16U, CV_32F)))
  792. {
  793. const cv::Size size = GET_PARAM(0);
  794. const int depth = GET_PARAM(1);
  795. cv::Mat src1(size, depth);
  796. declare.in(src1, WARMUP_RNG);
  797. cv::Mat src2(size, depth);
  798. declare.in(src2, WARMUP_RNG);
  799. if (PERF_RUN_CUDA())
  800. {
  801. const cv::cuda::GpuMat d_src1(src1);
  802. const cv::cuda::GpuMat d_src2(src2);
  803. cv::cuda::GpuMat dst;
  804. TEST_CYCLE() cv::cuda::min(d_src1, d_src2, dst);
  805. CUDA_SANITY_CHECK(dst);
  806. }
  807. else
  808. {
  809. cv::Mat dst;
  810. TEST_CYCLE() cv::min(src1, src2, dst);
  811. CPU_SANITY_CHECK(dst);
  812. }
  813. }
  814. //////////////////////////////////////////////////////////////////////
  815. // MinScalar
  816. PERF_TEST_P(Sz_Depth, MinScalar,
  817. Combine(CUDA_TYPICAL_MAT_SIZES,
  818. Values(CV_8U, CV_16U, CV_32F)))
  819. {
  820. const cv::Size size = GET_PARAM(0);
  821. const int depth = GET_PARAM(1);
  822. cv::Mat src(size, depth);
  823. declare.in(src, WARMUP_RNG);
  824. cv::Scalar val;
  825. declare.in(val, WARMUP_RNG);
  826. if (PERF_RUN_CUDA())
  827. {
  828. const cv::cuda::GpuMat d_src(src);
  829. cv::cuda::GpuMat dst;
  830. TEST_CYCLE() cv::cuda::min(d_src, val[0], dst);
  831. CUDA_SANITY_CHECK(dst);
  832. }
  833. else
  834. {
  835. cv::Mat dst;
  836. TEST_CYCLE() cv::min(src, val[0], dst);
  837. CPU_SANITY_CHECK(dst);
  838. }
  839. }
  840. //////////////////////////////////////////////////////////////////////
  841. // MaxMat
  842. PERF_TEST_P(Sz_Depth, MaxMat,
  843. Combine(CUDA_TYPICAL_MAT_SIZES,
  844. Values(CV_8U, CV_16U, CV_32F)))
  845. {
  846. const cv::Size size = GET_PARAM(0);
  847. const int depth = GET_PARAM(1);
  848. cv::Mat src1(size, depth);
  849. declare.in(src1, WARMUP_RNG);
  850. cv::Mat src2(size, depth);
  851. declare.in(src2, WARMUP_RNG);
  852. if (PERF_RUN_CUDA())
  853. {
  854. const cv::cuda::GpuMat d_src1(src1);
  855. const cv::cuda::GpuMat d_src2(src2);
  856. cv::cuda::GpuMat dst;
  857. TEST_CYCLE() cv::cuda::max(d_src1, d_src2, dst);
  858. CUDA_SANITY_CHECK(dst);
  859. }
  860. else
  861. {
  862. cv::Mat dst;
  863. TEST_CYCLE() cv::max(src1, src2, dst);
  864. CPU_SANITY_CHECK(dst);
  865. }
  866. }
  867. //////////////////////////////////////////////////////////////////////
  868. // MaxScalar
  869. PERF_TEST_P(Sz_Depth, MaxScalar,
  870. Combine(CUDA_TYPICAL_MAT_SIZES,
  871. Values(CV_8U, CV_16U, CV_32F)))
  872. {
  873. const cv::Size size = GET_PARAM(0);
  874. const int depth = GET_PARAM(1);
  875. cv::Mat src(size, depth);
  876. declare.in(src, WARMUP_RNG);
  877. cv::Scalar val;
  878. declare.in(val, WARMUP_RNG);
  879. if (PERF_RUN_CUDA())
  880. {
  881. const cv::cuda::GpuMat d_src(src);
  882. cv::cuda::GpuMat dst;
  883. TEST_CYCLE() cv::cuda::max(d_src, val[0], dst);
  884. CUDA_SANITY_CHECK(dst);
  885. }
  886. else
  887. {
  888. cv::Mat dst;
  889. TEST_CYCLE() cv::max(src, val[0], dst);
  890. CPU_SANITY_CHECK(dst);
  891. }
  892. }
  893. //////////////////////////////////////////////////////////////////////
  894. // AddWeighted
  895. DEF_PARAM_TEST(Sz_3Depth, cv::Size, MatDepth, MatDepth, MatDepth);
  896. PERF_TEST_P(Sz_3Depth, AddWeighted,
  897. Combine(CUDA_TYPICAL_MAT_SIZES,
  898. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  899. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  900. Values(CV_8U, CV_16U, CV_32F, CV_64F)))
  901. {
  902. const cv::Size size = GET_PARAM(0);
  903. const int depth1 = GET_PARAM(1);
  904. const int depth2 = GET_PARAM(2);
  905. const int dst_depth = GET_PARAM(3);
  906. cv::Mat src1(size, depth1);
  907. declare.in(src1, WARMUP_RNG);
  908. cv::Mat src2(size, depth2);
  909. declare.in(src2, WARMUP_RNG);
  910. if (PERF_RUN_CUDA())
  911. {
  912. const cv::cuda::GpuMat d_src1(src1);
  913. const cv::cuda::GpuMat d_src2(src2);
  914. cv::cuda::GpuMat dst;
  915. TEST_CYCLE() cv::cuda::addWeighted(d_src1, 0.5, d_src2, 0.5, 10.0, dst, dst_depth);
  916. CUDA_SANITY_CHECK(dst, 1e-10);
  917. }
  918. else
  919. {
  920. cv::Mat dst;
  921. TEST_CYCLE() cv::addWeighted(src1, 0.5, src2, 0.5, 10.0, dst, dst_depth);
  922. CPU_SANITY_CHECK(dst);
  923. }
  924. }
  925. //////////////////////////////////////////////////////////////////////
  926. // MagnitudeComplex
  927. PERF_TEST_P(Sz, MagnitudeComplex,
  928. CUDA_TYPICAL_MAT_SIZES)
  929. {
  930. const cv::Size size = GetParam();
  931. cv::Mat src(size, CV_32FC2);
  932. declare.in(src, WARMUP_RNG);
  933. if (PERF_RUN_CUDA())
  934. {
  935. const cv::cuda::GpuMat d_src(src);
  936. cv::cuda::GpuMat dst;
  937. TEST_CYCLE() cv::cuda::magnitude(d_src, dst);
  938. CUDA_SANITY_CHECK(dst);
  939. }
  940. else
  941. {
  942. cv::Mat xy[2];
  943. cv::split(src, xy);
  944. cv::Mat dst;
  945. TEST_CYCLE() cv::magnitude(xy[0], xy[1], dst);
  946. CPU_SANITY_CHECK(dst);
  947. }
  948. }
  949. //////////////////////////////////////////////////////////////////////
  950. // MagnitudeSqrComplex
  951. PERF_TEST_P(Sz, MagnitudeSqrComplex,
  952. CUDA_TYPICAL_MAT_SIZES)
  953. {
  954. const cv::Size size = GetParam();
  955. cv::Mat src(size, CV_32FC2);
  956. declare.in(src, WARMUP_RNG);
  957. if (PERF_RUN_CUDA())
  958. {
  959. const cv::cuda::GpuMat d_src(src);
  960. cv::cuda::GpuMat dst;
  961. TEST_CYCLE() cv::cuda::magnitudeSqr(d_src, dst);
  962. CUDA_SANITY_CHECK(dst);
  963. }
  964. else
  965. {
  966. FAIL_NO_CPU();
  967. }
  968. }
  969. //////////////////////////////////////////////////////////////////////
  970. // Magnitude
  971. PERF_TEST_P(Sz, Magnitude,
  972. CUDA_TYPICAL_MAT_SIZES)
  973. {
  974. const cv::Size size = GetParam();
  975. cv::Mat src1(size, CV_32FC1);
  976. declare.in(src1, WARMUP_RNG);
  977. cv::Mat src2(size, CV_32FC1);
  978. declare.in(src2, WARMUP_RNG);
  979. if (PERF_RUN_CUDA())
  980. {
  981. const cv::cuda::GpuMat d_src1(src1);
  982. const cv::cuda::GpuMat d_src2(src2);
  983. cv::cuda::GpuMat dst;
  984. TEST_CYCLE() cv::cuda::magnitude(d_src1, d_src2, dst);
  985. CUDA_SANITY_CHECK(dst);
  986. }
  987. else
  988. {
  989. cv::Mat dst;
  990. TEST_CYCLE() cv::magnitude(src1, src2, dst);
  991. CPU_SANITY_CHECK(dst);
  992. }
  993. }
  994. //////////////////////////////////////////////////////////////////////
  995. // MagnitudeSqr
  996. PERF_TEST_P(Sz, MagnitudeSqr,
  997. CUDA_TYPICAL_MAT_SIZES)
  998. {
  999. const cv::Size size = GetParam();
  1000. cv::Mat src1(size, CV_32FC1);
  1001. declare.in(src1, WARMUP_RNG);
  1002. cv::Mat src2(size, CV_32FC1);
  1003. declare.in(src2, WARMUP_RNG);
  1004. if (PERF_RUN_CUDA())
  1005. {
  1006. const cv::cuda::GpuMat d_src1(src1);
  1007. const cv::cuda::GpuMat d_src2(src2);
  1008. cv::cuda::GpuMat dst;
  1009. TEST_CYCLE() cv::cuda::magnitudeSqr(d_src1, d_src2, dst);
  1010. CUDA_SANITY_CHECK(dst);
  1011. }
  1012. else
  1013. {
  1014. FAIL_NO_CPU();
  1015. }
  1016. }
  1017. //////////////////////////////////////////////////////////////////////
  1018. // Phase
  1019. DEF_PARAM_TEST(Sz_AngleInDegrees, cv::Size, bool);
  1020. DEF_PARAM_TEST(Sz_Type_AngleInDegrees, cv::Size, MatType, bool);
  1021. PERF_TEST_P(Sz_AngleInDegrees, Phase,
  1022. Combine(CUDA_TYPICAL_MAT_SIZES,
  1023. Bool()))
  1024. {
  1025. const cv::Size size = GET_PARAM(0);
  1026. const bool angleInDegrees = GET_PARAM(1);
  1027. cv::Mat src1(size, CV_32FC1);
  1028. declare.in(src1, WARMUP_RNG);
  1029. cv::Mat src2(size, CV_32FC1);
  1030. declare.in(src2, WARMUP_RNG);
  1031. if (PERF_RUN_CUDA())
  1032. {
  1033. const cv::cuda::GpuMat d_src1(src1);
  1034. const cv::cuda::GpuMat d_src2(src2);
  1035. cv::cuda::GpuMat dst;
  1036. TEST_CYCLE() cv::cuda::phase(d_src1, d_src2, dst, angleInDegrees);
  1037. CUDA_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
  1038. }
  1039. else
  1040. {
  1041. cv::Mat dst;
  1042. TEST_CYCLE() cv::phase(src1, src2, dst, angleInDegrees);
  1043. CPU_SANITY_CHECK(dst);
  1044. }
  1045. }
  1046. //////////////////////////////////////////////////////////////////////
  1047. // CartToPolar
  1048. PERF_TEST_P(Sz_AngleInDegrees, CartToPolar,
  1049. Combine(CUDA_TYPICAL_MAT_SIZES,
  1050. Bool()))
  1051. {
  1052. const cv::Size size = GET_PARAM(0);
  1053. const bool angleInDegrees = GET_PARAM(1);
  1054. cv::Mat src1(size, CV_32FC1);
  1055. declare.in(src1, WARMUP_RNG);
  1056. cv::Mat src2(size, CV_32FC1);
  1057. declare.in(src2, WARMUP_RNG);
  1058. if (PERF_RUN_CUDA())
  1059. {
  1060. const cv::cuda::GpuMat d_src1(src1);
  1061. const cv::cuda::GpuMat d_src2(src2);
  1062. cv::cuda::GpuMat magnitude;
  1063. cv::cuda::GpuMat angle;
  1064. TEST_CYCLE() cv::cuda::cartToPolar(d_src1, d_src2, magnitude, angle, angleInDegrees);
  1065. CUDA_SANITY_CHECK(magnitude);
  1066. CUDA_SANITY_CHECK(angle, 1e-6, ERROR_RELATIVE);
  1067. }
  1068. else
  1069. {
  1070. cv::Mat magnitude;
  1071. cv::Mat angle;
  1072. TEST_CYCLE() cv::cartToPolar(src1, src2, magnitude, angle, angleInDegrees);
  1073. CPU_SANITY_CHECK(magnitude);
  1074. CPU_SANITY_CHECK(angle);
  1075. }
  1076. }
  1077. //////////////////////////////////////////////////////////////////////
  1078. // PolarToCart
  1079. PERF_TEST_P(Sz_Type_AngleInDegrees, PolarToCart,
  1080. Combine(CUDA_TYPICAL_MAT_SIZES,
  1081. testing::Values(CV_32FC1, CV_64FC1),
  1082. Bool()))
  1083. {
  1084. const cv::Size size = GET_PARAM(0);
  1085. const int type = GET_PARAM(1);
  1086. const bool angleInDegrees = GET_PARAM(2);
  1087. cv::Mat magnitude(size, type);
  1088. declare.in(magnitude, WARMUP_RNG);
  1089. cv::Mat angle(size, type);
  1090. declare.in(angle, WARMUP_RNG);
  1091. if (PERF_RUN_CUDA())
  1092. {
  1093. const cv::cuda::GpuMat d_magnitude(magnitude);
  1094. const cv::cuda::GpuMat d_angle(angle);
  1095. cv::cuda::GpuMat x;
  1096. cv::cuda::GpuMat y;
  1097. TEST_CYCLE() cv::cuda::polarToCart(d_magnitude, d_angle, x, y, angleInDegrees);
  1098. CUDA_SANITY_CHECK(x);
  1099. CUDA_SANITY_CHECK(y);
  1100. }
  1101. else
  1102. {
  1103. cv::Mat x;
  1104. cv::Mat y;
  1105. TEST_CYCLE() cv::polarToCart(magnitude, angle, x, y, angleInDegrees);
  1106. CPU_SANITY_CHECK(x);
  1107. CPU_SANITY_CHECK(y);
  1108. }
  1109. }
  1110. //////////////////////////////////////////////////////////////////////
  1111. // Threshold
  1112. CV_ENUM(ThreshOp, cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV)
  1113. DEF_PARAM_TEST(Sz_Depth_Op, cv::Size, MatDepth, ThreshOp);
  1114. PERF_TEST_P(Sz_Depth_Op, Threshold,
  1115. Combine(CUDA_TYPICAL_MAT_SIZES,
  1116. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  1117. ThreshOp::all()))
  1118. {
  1119. const cv::Size size = GET_PARAM(0);
  1120. const int depth = GET_PARAM(1);
  1121. const int threshOp = GET_PARAM(2);
  1122. cv::Mat src(size, depth);
  1123. declare.in(src, WARMUP_RNG);
  1124. if (PERF_RUN_CUDA())
  1125. {
  1126. const cv::cuda::GpuMat d_src(src);
  1127. cv::cuda::GpuMat dst;
  1128. TEST_CYCLE() cv::cuda::threshold(d_src, dst, 100.0, 255.0, threshOp);
  1129. CUDA_SANITY_CHECK(dst, 1e-10);
  1130. }
  1131. else
  1132. {
  1133. cv::Mat dst;
  1134. TEST_CYCLE() cv::threshold(src, dst, 100.0, 255.0, threshOp);
  1135. CPU_SANITY_CHECK(dst);
  1136. }
  1137. }
  1138. //////////////////////////////////////////////////////////////////////
  1139. // InRange
  1140. PERF_TEST_P(Sz_Depth_Cn, InRange,
  1141. Combine(CUDA_TYPICAL_MAT_SIZES,
  1142. Values(CV_8U, CV_16U, CV_32F, CV_64F),
  1143. CUDA_CHANNELS_1_3_4))
  1144. {
  1145. const cv::Size size = GET_PARAM(0);
  1146. const int depth = GET_PARAM(1);
  1147. const int channels = GET_PARAM(2);
  1148. cv::Mat src(size, CV_MAKE_TYPE(depth, channels));
  1149. declare.in(src, WARMUP_RNG);
  1150. const cv::Scalar lowerb(10, 50, 100);
  1151. const cv::Scalar upperb(70, 85, 200);
  1152. if (PERF_RUN_CUDA())
  1153. {
  1154. const cv::cuda::GpuMat d_src(src);
  1155. cv::cuda::GpuMat dst;
  1156. TEST_CYCLE() cv::cuda::inRange(d_src, lowerb, upperb, dst);
  1157. CUDA_SANITY_CHECK(dst, 0);
  1158. }
  1159. else
  1160. {
  1161. cv::Mat dst;
  1162. TEST_CYCLE() cv::inRange(src, lowerb, upperb, dst);
  1163. CPU_SANITY_CHECK(dst);
  1164. }
  1165. }
  1166. }} // namespace