Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/js/test/test_objdetect.js
16344 views
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
42
// //////////////////////////////////////////////////////////////////////////////////////
43
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
44
//
45
// LICENSE AGREEMENT
46
// Copyright (c) 2015 The Regents of the University of California (Regents)
47
//
48
// Redistribution and use in source and binary forms, with or without
49
// modification, are permitted provided that the following conditions are met:
50
// 1. Redistributions of source code must retain the above copyright
51
// notice, this list of conditions and the following disclaimer.
52
// 2. Redistributions in binary form must reproduce the above copyright
53
// notice, this list of conditions and the following disclaimer in the
54
// documentation and/or other materials provided with the distribution.
55
// 3. Neither the name of the University nor the
56
// names of its contributors may be used to endorse or promote products
57
// derived from this software without specific prior written permission.
58
//
59
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
60
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
61
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
62
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
63
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
65
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
66
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
68
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69
//
70
71
if (typeof module !== 'undefined' && module.exports) {
72
// The envrionment is Node.js
73
var cv = require('./opencv.js'); // eslint-disable-line no-var
74
cv.FS_createLazyFile('/', 'haarcascade_frontalface_default.xml', // eslint-disable-line new-cap
75
'haarcascade_frontalface_default.xml', true, false);
76
}
77
78
QUnit.module('Object Detection', {});
79
QUnit.test('Cascade classification', function(assert) {
80
// Group rectangle
81
{
82
let rectList = new cv.RectVector();
83
let weights = new cv.IntVector();
84
let groupThreshold = 1;
85
const eps = 0.2;
86
87
let rect1 = new cv.Rect(1, 2, 3, 4);
88
let rect2 = new cv.Rect(1, 4, 2, 3);
89
90
rectList.push_back(rect1);
91
rectList.push_back(rect2);
92
93
cv.groupRectangles(rectList, weights, groupThreshold, eps);
94
95
96
rectList.delete();
97
weights.delete();
98
}
99
100
// CascadeClassifier
101
{
102
let classifier = new cv.CascadeClassifier();
103
const modelPath = '/haarcascade_frontalface_default.xml';
104
105
assert.equal(classifier.empty(), true);
106
107
108
classifier.load(modelPath);
109
assert.equal(classifier.empty(), false);
110
111
let image = cv.Mat.eye({height: 10, width: 10}, cv.CV_8UC3);
112
let objects = new cv.RectVector();
113
let numDetections = new cv.IntVector();
114
const scaleFactor = 1.1;
115
const minNeighbors = 3;
116
const flags = 0;
117
const minSize = {height: 0, width: 0};
118
const maxSize = {height: 10, width: 10};
119
120
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
121
minNeighbors, flags, minSize, maxSize);
122
123
// test default parameters
124
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
125
minNeighbors, flags, minSize);
126
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
127
minNeighbors, flags);
128
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
129
minNeighbors);
130
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor);
131
132
classifier.delete();
133
objects.delete();
134
numDetections.delete();
135
}
136
137
// HOGDescriptor
138
{
139
let hog = new cv.HOGDescriptor();
140
let mat = new cv.Mat({height: 10, width: 10}, cv.CV_8UC1);
141
let descriptors = new cv.FloatVector();
142
let locations = new cv.PointVector();
143
144
145
assert.equal(hog.winSize.height, 128);
146
assert.equal(hog.winSize.width, 64);
147
assert.equal(hog.nbins, 9);
148
assert.equal(hog.derivAperture, 1);
149
assert.equal(hog.winSigma, -1);
150
assert.equal(hog.histogramNormType, 0);
151
assert.equal(hog.nlevels, 64);
152
153
hog.nlevels = 32;
154
assert.equal(hog.nlevels, 32);
155
156
hog.delete();
157
mat.delete();
158
descriptors.delete();
159
locations.delete();
160
}
161
});
162
163