test_utils.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // //////////////////////////////////////////////////////////////////////////////////////
  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) 2013, OpenCV Foundation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. // //////////////////////////////////////////////////////////////////////////////////////
  41. // Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
  42. //
  43. // LICENSE AGREEMENT
  44. // Copyright (c) 2015 The Regents of the University of California (Regents)
  45. //
  46. // Redistribution and use in source and binary forms, with or without
  47. // modification, are permitted provided that the following conditions are met:
  48. // 1. Redistributions of source code must retain the above copyright
  49. // notice, this list of conditions and the following disclaimer.
  50. // 2. Redistributions in binary form must reproduce the above copyright
  51. // notice, this list of conditions and the following disclaimer in the
  52. // documentation and/or other materials provided with the distribution.
  53. // 3. Neither the name of the University nor the
  54. // names of its contributors may be used to endorse or promote products
  55. // derived from this software without specific prior written permission.
  56. //
  57. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
  58. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  59. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  60. // DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
  61. // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  63. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  64. // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  66. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. //
  68. QUnit.module('Utils', {});
  69. QUnit.test('Test vectors', function(assert) {
  70. {
  71. let pointVector = new cv.PointVector();
  72. for (let i=0; i<100; ++i) {
  73. pointVector.push_back({x: i, y: 2*i});
  74. }
  75. assert.equal(pointVector.size(), 100);
  76. let index = 10;
  77. let item = pointVector.get(index);
  78. assert.equal(item.x, index);
  79. assert.equal(item.y, 2*index);
  80. index = 0;
  81. item = pointVector.get(index);
  82. assert.equal(item.x, index);
  83. assert.equal(item.y, 2*index);
  84. index = 99;
  85. item = pointVector.get(index);
  86. assert.equal(item.x, index);
  87. assert.equal(item.y, 2*index);
  88. pointVector.delete();
  89. }
  90. {
  91. let pointVector = new cv.PointVector();
  92. for (let i=0; i<100; ++i) {
  93. pointVector.push_back(new cv.Point(i, 2*i));
  94. }
  95. pointVector.push_back(new cv.Point());
  96. assert.equal(pointVector.size(), 101);
  97. let index = 10;
  98. let item = pointVector.get(index);
  99. assert.equal(item.x, index);
  100. assert.equal(item.y, 2*index);
  101. index = 0;
  102. item = pointVector.get(index);
  103. assert.equal(item.x, index);
  104. assert.equal(item.y, 2*index);
  105. index = 99;
  106. item = pointVector.get(index);
  107. assert.equal(item.x, index);
  108. assert.equal(item.y, 2*index);
  109. index = 100;
  110. item = pointVector.get(index);
  111. assert.equal(item.x, 0);
  112. assert.equal(item.y, 0);
  113. pointVector.delete();
  114. }
  115. });
  116. QUnit.test('Test Rect', function(assert) {
  117. let rectVector = new cv.RectVector();
  118. let rect = {x: 1, y: 2, width: 3, height: 4};
  119. rectVector.push_back(rect);
  120. rectVector.push_back(new cv.Rect());
  121. rectVector.push_back(new cv.Rect(rect));
  122. rectVector.push_back(new cv.Rect({x: 5, y: 6}, {width: 7, height: 8}));
  123. rectVector.push_back(new cv.Rect(9, 10, 11, 12));
  124. assert.equal(rectVector.size(), 5);
  125. let item = rectVector.get(0);
  126. assert.equal(item.x, 1);
  127. assert.equal(item.y, 2);
  128. assert.equal(item.width, 3);
  129. assert.equal(item.height, 4);
  130. item = rectVector.get(1);
  131. assert.equal(item.x, 0);
  132. assert.equal(item.y, 0);
  133. assert.equal(item.width, 0);
  134. assert.equal(item.height, 0);
  135. item = rectVector.get(2);
  136. assert.equal(item.x, 1);
  137. assert.equal(item.y, 2);
  138. assert.equal(item.width, 3);
  139. assert.equal(item.height, 4);
  140. item = rectVector.get(3);
  141. assert.equal(item.x, 5);
  142. assert.equal(item.y, 6);
  143. assert.equal(item.width, 7);
  144. assert.equal(item.height, 8);
  145. item = rectVector.get(4);
  146. assert.equal(item.x, 9);
  147. assert.equal(item.y, 10);
  148. assert.equal(item.width, 11);
  149. assert.equal(item.height, 12);
  150. rectVector.delete();
  151. });
  152. QUnit.test('Test Size', function(assert) {
  153. {
  154. let mat = new cv.Mat();
  155. mat.create({width: 5, height: 10}, cv.CV_8UC4);
  156. let size = mat.size();
  157. assert.ok(mat.type() === cv.CV_8UC4);
  158. assert.ok(size.height === 10);
  159. assert.ok(size.width === 5);
  160. assert.ok(mat.channels() === 4);
  161. mat.delete();
  162. }
  163. {
  164. let mat = new cv.Mat();
  165. mat.create(new cv.Size(5, 10), cv.CV_8UC4);
  166. let size = mat.size();
  167. assert.ok(mat.type() === cv.CV_8UC4);
  168. assert.ok(size.height === 10);
  169. assert.ok(size.width === 5);
  170. assert.ok(mat.channels() === 4);
  171. mat.delete();
  172. }
  173. });
  174. QUnit.test('test_rotated_rect', function(assert) {
  175. {
  176. let rect = {center: {x: 100, y: 100}, size: {height: 100, width: 50}, angle: 30};
  177. assert.equal(rect.center.x, 100);
  178. assert.equal(rect.center.y, 100);
  179. assert.equal(rect.angle, 30);
  180. assert.equal(rect.size.height, 100);
  181. assert.equal(rect.size.width, 50);
  182. }
  183. {
  184. let rect = new cv.RotatedRect();
  185. assert.equal(rect.center.x, 0);
  186. assert.equal(rect.center.y, 0);
  187. assert.equal(rect.angle, 0);
  188. assert.equal(rect.size.height, 0);
  189. assert.equal(rect.size.width, 0);
  190. let points = cv.RotatedRect.points(rect);
  191. assert.equal(points[0].x, 0);
  192. assert.equal(points[0].y, 0);
  193. assert.equal(points[1].x, 0);
  194. assert.equal(points[1].y, 0);
  195. assert.equal(points[2].x, 0);
  196. assert.equal(points[2].y, 0);
  197. assert.equal(points[3].x, 0);
  198. assert.equal(points[3].y, 0);
  199. }
  200. {
  201. let rect = new cv.RotatedRect({x: 100, y: 100}, {height: 100, width: 50}, 30);
  202. assert.equal(rect.center.x, 100);
  203. assert.equal(rect.center.y, 100);
  204. assert.equal(rect.angle, 30);
  205. assert.equal(rect.size.height, 100);
  206. assert.equal(rect.size.width, 50);
  207. let points = cv.RotatedRect.points(rect);
  208. assert.equal(points[0].x, cv.RotatedRect.boundingRect2f(rect).x);
  209. assert.equal(points[1].y, cv.RotatedRect.boundingRect2f(rect).y);
  210. let points1 = cv.boxPoints(rect);
  211. assert.deepEqual(points, points1);
  212. }
  213. });