test_video.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if (typeof module !== 'undefined' && module.exports) {
  69. // The environment is Node.js
  70. var cv = require('./opencv.js'); // eslint-disable-line no-var
  71. }
  72. QUnit.module('Video', {});
  73. QUnit.test('Background Segmentation', function(assert) {
  74. // BackgroundSubtractorMOG2
  75. {
  76. const history = 600;
  77. const varThreshold = 15;
  78. const detectShadows = true;
  79. let mog2 = new cv.BackgroundSubtractorMOG2(history, varThreshold, detectShadows);
  80. assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
  81. mog2.delete();
  82. mog2 = new cv.BackgroundSubtractorMOG2();
  83. assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
  84. mog2.delete();
  85. mog2 = new cv.BackgroundSubtractorMOG2(history);
  86. assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
  87. mog2.delete();
  88. mog2 = new cv.BackgroundSubtractorMOG2(history, varThreshold);
  89. assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
  90. mog2.delete();
  91. }
  92. });
  93. QUnit.test('TrackerMIL', function(assert) {
  94. {
  95. let src1 = cv.Mat.zeros(100, 100, cv.CV_8UC1);
  96. let src2 = cv.Mat.zeros(100, 100, cv.CV_8UC1);
  97. let tracker = new cv.TrackerMIL();
  98. assert.equal(tracker instanceof cv.TrackerMIL, true);
  99. assert.equal(tracker instanceof cv.Tracker, true);
  100. let rect = new cv.Rect(10, 10, 50, 60);
  101. tracker.init(src1, rect);
  102. let [updated, rect2] = tracker.update(src2);
  103. assert.equal(updated, true);
  104. assert.equal(rect2.width, 50);
  105. assert.equal(rect2.height, 60);
  106. tracker.delete();
  107. src1.delete();
  108. src2.delete();
  109. }
  110. });