test_fitellipse_direct.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2016, Itseez, Inc, all rights reserved.
  6. #include "test_precomp.hpp"
  7. namespace opencv_test { namespace {
  8. TEST(Imgproc_FitEllipseDirect_Issue_1, accuracy) {
  9. vector<Point2f>pts;
  10. pts.push_back(Point2f(173.41854895999165f, 125.84473135880411f));
  11. pts.push_back(Point2f(180.63769498640912f, 130.960006577589f));
  12. pts.push_back(Point2f(174.99173759130173f, 137.34265632926764f));
  13. pts.push_back(Point2f(170.9044645313217f, 141.68017556480243f));
  14. pts.push_back(Point2f(163.48965388499656f, 141.9404438924043f));
  15. pts.push_back(Point2f(159.37687818401147f, 148.60835331594876f));
  16. pts.push_back(Point2f(150.38917629356735f, 155.68825577720446f));
  17. pts.push_back(Point2f(147.16319653316862f, 157.06039984963923f));
  18. pts.push_back(Point2f(141.73118707843207f, 157.2570155198414f));
  19. pts.push_back(Point2f(130.61569602948597f, 159.40742182929364f));
  20. pts.push_back(Point2f(127.00573042229027f, 161.34430232187867f));
  21. pts.push_back(Point2f(120.49383815053747f, 163.72610883128334f));
  22. pts.push_back(Point2f(114.62383760040998f, 162.6788666385239f));
  23. pts.push_back(Point2f(108.84871269183333f, 161.90597054388132f));
  24. pts.push_back(Point2f(103.04574087829076f, 167.44352944383985f));
  25. pts.push_back(Point2f(96.31623870161255f, 163.71641295746116f));
  26. pts.push_back(Point2f(89.86174417295126f, 157.2967811253635f));
  27. pts.push_back(Point2f(84.27940674801192f, 168.6331304010667f));
  28. pts.push_back(Point2f(76.61995117937661f, 159.4445412678832f));
  29. pts.push_back(Point2f(72.22526316142418f, 154.60770776728293f));
  30. pts.push_back(Point2f(64.97742405067658f, 152.3687174339018f));
  31. pts.push_back(Point2f(58.34612797237003f, 155.61116802371583f));
  32. pts.push_back(Point2f(55.59089117268539f, 148.56245696566418f));
  33. pts.push_back(Point2f(45.22711195983706f, 145.6713241271927f));
  34. pts.push_back(Point2f(40.090542298840234f, 142.36141304004002f));
  35. pts.push_back(Point2f(31.788996807277414f, 136.26164877915585f));
  36. pts.push_back(Point2f(27.27613006088805f, 137.46860042141503f));
  37. pts.push_back(Point2f(23.972392188502226f, 129.17993872328594f));
  38. pts.push_back(Point2f(20.688046711616977f, 121.52750840733087f));
  39. pts.push_back(Point2f(14.635115184257643f, 115.36942800110485f));
  40. pts.push_back(Point2f(14.850919318756809f, 109.43609786936987f));
  41. pts.push_back(Point2f(7.476847697758103f, 102.67657265589285f));
  42. pts.push_back(Point2f(1.8896944088091914f, 95.78878215565676f));
  43. pts.push_back(Point2f(1.731997022935417f, 88.17674033990495f));
  44. pts.push_back(Point2f(1.6780841363402033f, 80.65581939883002f));
  45. pts.push_back(Point2f(0.035330281415411946f, 73.1088693846768f));
  46. pts.push_back(Point2f(0.14652518786238033f, 65.42769523404296f));
  47. pts.push_back(Point2f(6.99914645302843f, 58.436451064804245f));
  48. pts.push_back(Point2f(6.719616410428614f, 50.15263031354927f));
  49. pts.push_back(Point2f(5.122267598477748f, 46.03603214691343f));
  50. bool directGoodQ;
  51. float tol = 0.01f;
  52. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(91.3256f, 90.4668f),Size2f(187.211f, 140.031f), 21.5808f);
  53. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  54. Point2f ellipseDirectTrueVertices[4];
  55. Point2f ellipseDirectTestVertices[4];
  56. ellipseDirectTest.points(ellipseDirectTestVertices);
  57. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  58. float directDiff = 0.0f;
  59. for (size_t i=0; i <=3; i++) {
  60. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  61. float d = diff.x * diff.x + diff.y * diff.y;
  62. for (size_t j=1; i <=3; i++) {
  63. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  64. float dd = diff.x * diff.x + diff.y * diff.y;
  65. if(dd<d){d=dd;}
  66. }
  67. directDiff += std::sqrt(d);
  68. }
  69. directGoodQ = directDiff < tol;
  70. EXPECT_TRUE(directGoodQ);
  71. }
  72. TEST(Imgproc_FitEllipseDirect_Issue_2, accuracy) {
  73. vector<Point2f>pts;
  74. pts.push_back(Point2f(436.59985753246326f, 99.52113368023126f));
  75. pts.push_back(Point2f(454.40214161915856f, 160.47565296546912f));
  76. pts.push_back(Point2f(406.01996690372687f, 215.41999534561575f));
  77. pts.push_back(Point2f(362.8738685722881f, 262.1842668997318f));
  78. pts.push_back(Point2f(300.72864073265407f, 290.8182699272777f));
  79. pts.push_back(Point2f(247.62963883830972f, 311.383137106776f));
  80. pts.push_back(Point2f(194.15394659099445f, 313.30260991427565f));
  81. pts.push_back(Point2f(138.934393338296f, 310.50203123324223f));
  82. pts.push_back(Point2f(91.66999301197541f, 300.57303988670515f));
  83. pts.push_back(Point2f(28.286233855826133f, 268.0670159317756f));
  84. bool directGoodQ;
  85. float tol = 0.01f;
  86. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(228.232f, 174.879f),Size2f(450.68f, 265.556f), 166.181f);
  87. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  88. Point2f ellipseDirectTrueVertices[4];
  89. Point2f ellipseDirectTestVertices[4];
  90. ellipseDirectTest.points(ellipseDirectTestVertices);
  91. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  92. float directDiff = 0.0f;
  93. for (size_t i=0; i <=3; i++) {
  94. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  95. float d = diff.x * diff.x + diff.y * diff.y;
  96. for (size_t j=1; i <=3; i++) {
  97. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  98. float dd = diff.x * diff.x + diff.y * diff.y;
  99. if(dd<d){d=dd;}
  100. }
  101. directDiff += std::sqrt(d);
  102. }
  103. directGoodQ = directDiff < tol;
  104. EXPECT_TRUE(directGoodQ);
  105. }
  106. TEST(Imgproc_FitEllipseDirect_Issue_3, accuracy) {
  107. vector<Point2f>pts;
  108. pts.push_back(Point2f(459.59217920219083f, 480.1054989283611f));
  109. pts.push_back(Point2f(427.2759071813645f, 501.82653857689616f));
  110. pts.push_back(Point2f(388.35145730295574f, 520.9488690267101f));
  111. pts.push_back(Point2f(349.53248668650656f, 522.9153107979839f));
  112. pts.push_back(Point2f(309.56018996762094f, 527.449631776843f));
  113. pts.push_back(Point2f(272.07480726768665f, 508.12367135706165f));
  114. pts.push_back(Point2f(234.69230939247115f, 519.8943877180591f));
  115. pts.push_back(Point2f(201.65185545142472f, 509.47870288702813f));
  116. pts.push_back(Point2f(169.37222144138462f, 498.2681549419808f));
  117. pts.push_back(Point2f(147.96233740677815f, 467.0923094529034f));
  118. pts.push_back(Point2f(109.68331701139209f, 433.39069422941986f));
  119. pts.push_back(Point2f(81.95454413977822f, 397.34325168750087f));
  120. pts.push_back(Point2f(63.74923800767195f, 371.939105294963f));
  121. pts.push_back(Point2f(39.966434417279885f, 329.9581349942296f));
  122. pts.push_back(Point2f(21.581668415402532f, 292.6692716276865f));
  123. pts.push_back(Point2f(13.687334926511767f, 248.91164234903772f));
  124. pts.push_back(Point2f(0.0f, 201.25693715845716f));
  125. pts.push_back(Point2f(3.90259455356599f, 155.68155247210575f));
  126. pts.push_back(Point2f(39.683930802331844f, 110.26290871953987f));
  127. pts.push_back(Point2f(47.85826684019932f, 70.82454140948524f));
  128. bool directGoodQ;
  129. float tol = 0.01f;
  130. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(255.326f, 272.626f),Size2f(570.999f, 434.23f), 49.0265f);
  131. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  132. Point2f ellipseDirectTrueVertices[4];
  133. Point2f ellipseDirectTestVertices[4];
  134. ellipseDirectTest.points(ellipseDirectTestVertices);
  135. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  136. float directDiff = 0.0f;
  137. for (size_t i=0; i <=3; i++) {
  138. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  139. float d = diff.x * diff.x + diff.y * diff.y;
  140. for (size_t j=1; i <=3; i++) {
  141. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  142. float dd = diff.x * diff.x + diff.y * diff.y;
  143. if(dd<d){d=dd;}
  144. }
  145. directDiff += std::sqrt(d);
  146. }
  147. directGoodQ = directDiff < tol;
  148. EXPECT_TRUE(directGoodQ);
  149. }
  150. TEST(Imgproc_FitEllipseDirect_Issue_4, accuracy) {
  151. vector<Point2f>pts;
  152. pts.push_back(Point2f(461.1761758124861f, 79.55196261616746f));
  153. pts.push_back(Point2f(470.5034888757249f, 100.56760245239015f));
  154. pts.push_back(Point2f(470.7814479849749f, 127.45783922150272f));
  155. pts.push_back(Point2f(465.214384653262f, 157.51792078285405f));
  156. pts.push_back(Point2f(465.3739691861813f, 185.89204350118942f));
  157. pts.push_back(Point2f(443.36043162278366f, 214.43399982709002f));
  158. pts.push_back(Point2f(435.04682693174095f, 239.2657073987589f));
  159. pts.push_back(Point2f(444.48553588292697f, 262.0816619678671f));
  160. pts.push_back(Point2f(407.1290185495328f, 285.07828783776347f));
  161. pts.push_back(Point2f(397.71436554935804f, 304.782713567108f));
  162. pts.push_back(Point2f(391.65678619785854f, 323.6809382153118f));
  163. pts.push_back(Point2f(366.3904205781036f, 328.09416679736563f));
  164. pts.push_back(Point2f(341.7656517790918f, 346.9672607008338f));
  165. pts.push_back(Point2f(335.8021864809171f, 358.22416661090296f));
  166. pts.push_back(Point2f(313.29224574204227f, 373.3267160317279f));
  167. pts.push_back(Point2f(291.121216115417f, 377.3339312050791f));
  168. pts.push_back(Point2f(284.20367595990547f, 389.5930108233698f));
  169. pts.push_back(Point2f(270.9682061106809f, 388.4352006517971f));
  170. pts.push_back(Point2f(253.10188273008825f, 392.35120876055373f));
  171. pts.push_back(Point2f(234.2306946938868f, 407.0773705761117f));
  172. pts.push_back(Point2f(217.0544384092144f, 407.54850609237235f));
  173. pts.push_back(Point2f(198.40910966657933f, 423.7008860314684f));
  174. pts.push_back(Point2f(175.47011114845057f, 420.4223434173364f));
  175. pts.push_back(Point2f(154.92083551695902f, 418.5288198459268f));
  176. pts.push_back(Point2f(136.52988517939698f, 417.8311217226818f));
  177. pts.push_back(Point2f(114.74657291069317f, 410.1534699388714f));
  178. pts.push_back(Point2f(78.9220388330042f, 397.6266608135022f));
  179. pts.push_back(Point2f(76.82658673144391f, 404.27399269891055f));
  180. pts.push_back(Point2f(50.953595435605116f, 386.3824077178053f));
  181. pts.push_back(Point2f(43.603489077456985f, 368.7894972436907f));
  182. pts.push_back(Point2f(19.37402592752713f, 343.3511017547511f));
  183. pts.push_back(Point2f(8.714663367287343f, 322.2148323327599f));
  184. pts.push_back(Point2f(0., 288.7836318007535f));
  185. pts.push_back(Point2f(3.98686689837605f, 263.1748167870333f));
  186. pts.push_back(Point2f(9.536389714519785f, 233.02995195684738f));
  187. pts.push_back(Point2f(17.83246556512455f, 205.6536519851621f));
  188. pts.push_back(Point2f(33.00593702846919f, 180.52628138608327f));
  189. pts.push_back(Point2f(41.572400996463394f, 153.95185568689314f));
  190. pts.push_back(Point2f(54.55733659450332f, 136.54322891729444f));
  191. pts.push_back(Point2f(78.60990563833005f, 112.76538180538182f));
  192. bool directGoodQ;
  193. float tol = 0.01f;
  194. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(236.836f, 208.089f),Size2f(515.893f, 357.166f), -35.9996f);
  195. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  196. Point2f ellipseDirectTrueVertices[4];
  197. Point2f ellipseDirectTestVertices[4];
  198. ellipseDirectTest.points(ellipseDirectTestVertices);
  199. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  200. float directDiff = 0.0f;
  201. for (size_t i=0; i <=3; i++) {
  202. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  203. float d = diff.x * diff.x + diff.y * diff.y;
  204. for (size_t j=1; i <=3; i++) {
  205. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  206. float dd = diff.x * diff.x + diff.y * diff.y;
  207. if(dd<d){d=dd;}
  208. }
  209. directDiff += std::sqrt(d);
  210. }
  211. directGoodQ = directDiff < tol;
  212. EXPECT_TRUE(directGoodQ);
  213. }
  214. TEST(Imgproc_FitEllipseDirect_Issue_5, accuracy) {
  215. vector<Point2f>pts;
  216. pts.push_back(Point2f(509.60609444351917f, 484.8233016998119f));
  217. pts.push_back(Point2f(508.55357451809846f, 498.61004779125176f));
  218. pts.push_back(Point2f(495.59325478416525f, 507.9238702677585f));
  219. pts.push_back(Point2f(455.32905012177747f, 517.7518674113691f));
  220. pts.push_back(Point2f(461.24821761238667f, 524.2115477440211f));
  221. pts.push_back(Point2f(438.8983455906825f, 528.424911702069f));
  222. pts.push_back(Point2f(425.9259699875303f, 532.5700430134499f));
  223. pts.push_back(Point2f(405.77496728300616f, 535.7295008444993f));
  224. pts.push_back(Point2f(384.31968113982475f, 536.3076260371831f));
  225. pts.push_back(Point2f(381.5356536818977f, 540.183355729414f));
  226. pts.push_back(Point2f(378.2530503455792f, 540.2871855284832f));
  227. pts.push_back(Point2f(357.7242088314752f, 543.473075733281f));
  228. pts.push_back(Point2f(339.27871831324853f, 541.2099003613087f));
  229. pts.push_back(Point2f(339.22481874867435f, 541.1105421426018f));
  230. pts.push_back(Point2f(331.50337377509396f, 539.7296050163102f));
  231. pts.push_back(Point2f(317.8306501537862f, 540.9077275195326f));
  232. pts.push_back(Point2f(304.9192648323086f, 541.3434792768918f));
  233. pts.push_back(Point2f(297.33855427908617f, 543.0590309600501f));
  234. pts.push_back(Point2f(288.95330515997694f, 543.8756702506837f));
  235. pts.push_back(Point2f(278.5850913122515f, 538.1343888329859f));
  236. pts.push_back(Point2f(266.05355938101724f, 538.4115695907074f));
  237. pts.push_back(Point2f(255.30186994366096f, 534.2459272411796f));
  238. pts.push_back(Point2f(238.52054973466758f, 537.5007401480628f));
  239. pts.push_back(Point2f(228.444463024996f, 533.8992361116678f));
  240. pts.push_back(Point2f(217.8111623149833f, 538.2269193558991f));
  241. pts.push_back(Point2f(209.43502138981037f, 532.8057062984569f));
  242. pts.push_back(Point2f(193.33570716763276f, 527.2038128630041f));
  243. pts.push_back(Point2f(172.66725340039625f, 526.4020881005537f));
  244. pts.push_back(Point2f(158.33654199771337f, 525.2093856704676f));
  245. pts.push_back(Point2f(148.65905485249067f, 521.0146762179431f));
  246. pts.push_back(Point2f(147.6615365176719f, 517.4315201992808f));
  247. pts.push_back(Point2f(122.43568509949394f, 514.2089723387337f));
  248. pts.push_back(Point2f(110.88482982039073f, 509.14004840857046f));
  249. pts.push_back(Point2f(107.10516681523065f, 502.49943180234266f));
  250. pts.push_back(Point2f(82.66611013934804f, 494.0581153893113f));
  251. pts.push_back(Point2f(63.573319848965966f, 485.6772487054385f));
  252. pts.push_back(Point2f(47.65729058071245f, 475.4468806518075f));
  253. pts.push_back(Point2f(19.96819458379347f, 463.98285210241943f));
  254. pts.push_back(Point2f(27.855803175234342f, 450.2298664426336f));
  255. pts.push_back(Point2f(12.832198085636549f, 435.6317753810441f));
  256. bool directGoodQ;
  257. float tol = 0.01f;
  258. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(264.354f, 457.336f),Size2f(493.728f, 162.9f), 5.36186f);
  259. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  260. Point2f ellipseDirectTrueVertices[4];
  261. Point2f ellipseDirectTestVertices[4];
  262. ellipseDirectTest.points(ellipseDirectTestVertices);
  263. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  264. float directDiff = 0.0f;
  265. for (size_t i=0; i <=3; i++) {
  266. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  267. float d = diff.x * diff.x + diff.y * diff.y;
  268. for (size_t j=1; i <=3; i++) {
  269. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  270. float dd = diff.x * diff.x + diff.y * diff.y;
  271. if(dd<d){d=dd;}
  272. }
  273. directDiff += std::sqrt(d);
  274. }
  275. directGoodQ = directDiff < tol;
  276. EXPECT_TRUE(directGoodQ);
  277. }
  278. TEST(Imgproc_FitEllipseDirect_Issue_6, accuracy) {
  279. vector<Point2f>pts;
  280. pts.push_back(Point2f(414.90156479295905f, 29.063453659930833f));
  281. pts.push_back(Point2f(393.79576036337977f, 58.59512774879134f));
  282. pts.push_back(Point2f(387.9100725249931f, 94.65067695657254f));
  283. pts.push_back(Point2f(351.6987114318621f, 124.6049267560123f));
  284. pts.push_back(Point2f(335.3270519942532f, 154.52182750730412f));
  285. pts.push_back(Point2f(329.2955843262556f, 179.38031343427303f));
  286. pts.push_back(Point2f(322.7316812937696f, 201.88774427737036f));
  287. pts.push_back(Point2f(301.48326350826585f, 217.63331351026562f));
  288. pts.push_back(Point2f(287.4603938315088f, 228.68790184154113f));
  289. pts.push_back(Point2f(273.36617750656023f, 234.48397257849905f));
  290. pts.push_back(Point2f(270.7787206270782f, 242.85279436204632f));
  291. pts.push_back(Point2f(268.6973828073692f, 246.10891460870312f));
  292. pts.push_back(Point2f(261.60715070464255f, 252.65744793902192f));
  293. pts.push_back(Point2f(262.9041824871923f, 257.1813047575656f));
  294. pts.push_back(Point2f(263.3210079177046f, 260.0532193246593f));
  295. pts.push_back(Point2f(248.49568488533242f, 264.56723557175013f));
  296. pts.push_back(Point2f(245.4134174127509f, 264.87259401292f));
  297. pts.push_back(Point2f(244.73208618171216f, 272.32307359830884f));
  298. pts.push_back(Point2f(232.82093196087555f, 272.0239734764616f));
  299. pts.push_back(Point2f(235.28539413113458f, 276.8668447478244f));
  300. pts.push_back(Point2f(231.9766571511147f, 277.71179872893083f));
  301. pts.push_back(Point2f(227.23880706209866f, 284.5588878789101f));
  302. pts.push_back(Point2f(222.53202223537826f, 282.2293154479012f));
  303. pts.push_back(Point2f(217.27525654729595f, 297.42961148365725f));
  304. pts.push_back(Point2f(212.19490057230672f, 294.5344078014253f));
  305. pts.push_back(Point2f(207.47417472945446f, 301.72230412668307f));
  306. pts.push_back(Point2f(202.11143229969164f, 298.8588627545512f));
  307. pts.push_back(Point2f(196.62967096845824f, 309.39738607353223f));
  308. pts.push_back(Point2f(190.37809841992106f, 318.3250479151242f));
  309. pts.push_back(Point2f(183.1296129732803f, 322.35242231955453f));
  310. pts.push_back(Point2f(171.58530535265993f, 330.4981441404153f));
  311. pts.push_back(Point2f(160.40092880652247f, 337.47275990208226f));
  312. pts.push_back(Point2f(149.44888762618092f, 343.42296086656717f));
  313. pts.push_back(Point2f(139.7923528305302f, 353.4821948045352f));
  314. pts.push_back(Point2f(121.08414969113318f, 359.7010225709457f));
  315. pts.push_back(Point2f(100.10629739219641f, 375.3155744055458f));
  316. pts.push_back(Point2f(78.15715630786733f, 389.0311284319413f));
  317. pts.push_back(Point2f(51.22820988075294f, 396.98646504159547f));
  318. pts.push_back(Point2f(30.71132492338431f, 402.85098740402844f));
  319. pts.push_back(Point2f(10.994737323179852f, 394.6764602972333f));
  320. bool directGoodQ;
  321. float tol = 0.01f;
  322. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(207.145f, 223.308f),Size2f(499.583f, 117.473f), -42.6851f);
  323. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  324. Point2f ellipseDirectTrueVertices[4];
  325. Point2f ellipseDirectTestVertices[4];
  326. ellipseDirectTest.points(ellipseDirectTestVertices);
  327. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  328. float directDiff = 0.0f;
  329. for (size_t i=0; i <=3; i++) {
  330. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  331. float d = diff.x * diff.x + diff.y * diff.y;
  332. for (size_t j=1; i <=3; i++) {
  333. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  334. float dd = diff.x * diff.x + diff.y * diff.y;
  335. if(dd<d){d=dd;}
  336. }
  337. directDiff += std::sqrt(d);
  338. }
  339. directGoodQ = directDiff < tol;
  340. EXPECT_TRUE(directGoodQ);
  341. }
  342. TEST(Imgproc_FitEllipseDirect_Issue_7, accuracy) {
  343. vector<Point2f>pts;
  344. pts.push_back(Point2f(386.7497806918209f, 119.55623710363142f));
  345. pts.push_back(Point2f(399.0712613744503f, 132.61095972401034f));
  346. pts.push_back(Point2f(400.3582576852657f, 146.71942033652573f));
  347. pts.push_back(Point2f(383.31046706707906f, 160.13631428164982f));
  348. pts.push_back(Point2f(387.1626582455823f, 173.82700569763574f));
  349. pts.push_back(Point2f(378.88843308401425f, 186.10333319745317f));
  350. pts.push_back(Point2f(367.55061701208f, 201.41492900400164f));
  351. pts.push_back(Point2f(360.3254967185148f, 209.03834085076022f));
  352. pts.push_back(Point2f(346.2645164278429f, 222.03214282040395f));
  353. pts.push_back(Point2f(342.3483403634167f, 230.58290419787073f));
  354. pts.push_back(Point2f(326.2900969991908f, 240.23679566682756f));
  355. pts.push_back(Point2f(324.5622396580625f, 249.56961396707823f));
  356. pts.push_back(Point2f(304.23417130914095f, 259.6693711280021f));
  357. pts.push_back(Point2f(295.54035697534675f, 270.82284542557704f));
  358. pts.push_back(Point2f(291.7403057147348f, 276.1536825048371f));
  359. pts.push_back(Point2f(269.19344116558665f, 287.1705579044651f));
  360. pts.push_back(Point2f(256.5350613899267f, 274.91264707500943f));
  361. pts.push_back(Point2f(245.93644351417183f, 286.12398028743064f));
  362. pts.push_back(Point2f(232.40892420943732f, 282.73986583867065f));
  363. pts.push_back(Point2f(216.17957969101082f, 293.22229708237705f));
  364. pts.push_back(Point2f(205.66843722622573f, 295.7032575625158f));
  365. pts.push_back(Point2f(192.219969335765f, 302.6968969534755f));
  366. pts.push_back(Point2f(178.37758801730416f, 295.56656776633287f));
  367. pts.push_back(Point2f(167.60089103756644f, 301.4629292267722f));
  368. pts.push_back(Point2f(157.44802813915317f, 298.90830855734504f));
  369. pts.push_back(Point2f(138.44311818820313f, 293.951927187897f));
  370. pts.push_back(Point2f(128.92747660038592f, 291.4122695492978f));
  371. pts.push_back(Point2f(119.75160909865994f, 282.5809454721714f));
  372. pts.push_back(Point2f(98.48443737042328f, 290.39938776333247f));
  373. pts.push_back(Point2f(88.05275635126131f, 280.11156058895745f));
  374. pts.push_back(Point2f(82.45799026448167f, 271.46668468419773f));
  375. pts.push_back(Point2f(68.04031962064084f, 267.8136468580707f));
  376. pts.push_back(Point2f(58.99967170878713f, 263.8859310392943f));
  377. pts.push_back(Point2f(41.256097220823484f, 260.6041605773932f));
  378. pts.push_back(Point2f(40.66198797608645f, 246.64973068177196f));
  379. pts.push_back(Point2f(31.085484380646008f, 239.28615601336074f));
  380. pts.push_back(Point2f(24.069417111444253f, 225.2228746297288f));
  381. pts.push_back(Point2f(22.10122953275156f, 212.75509683149195f));
  382. pts.push_back(Point2f(9.929991244497518f, 203.20662088477752f));
  383. pts.push_back(Point2f(0.0f, 190.04891498441148f));
  384. bool directGoodQ;
  385. float tol = 0.01f;
  386. RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(199.463f, 150.997f),Size2f(390.341f, 286.01f), -12.9696f);
  387. RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
  388. Point2f ellipseDirectTrueVertices[4];
  389. Point2f ellipseDirectTestVertices[4];
  390. ellipseDirectTest.points(ellipseDirectTestVertices);
  391. ellipseDirectTrue.points(ellipseDirectTrueVertices);
  392. float directDiff = 0.0f;
  393. for (size_t i=0; i <=3; i++) {
  394. Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
  395. float d = diff.x * diff.x + diff.y * diff.y;
  396. for (size_t j=1; i <=3; i++) {
  397. diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
  398. float dd = diff.x * diff.x + diff.y * diff.y;
  399. if(dd<d){d=dd;}
  400. }
  401. directDiff += std::sqrt(d);
  402. }
  403. directGoodQ = directDiff < tol;
  404. EXPECT_TRUE(directGoodQ);
  405. }
  406. }} // namespace