@@ -64,22 +64,22 @@ module.exports = function (runtime, scope) {
64
64
MatchingResult . prototype . best = function ( ) {
65
65
return this . findMax ( ( l , r ) => r . similarity - l . similarity ) ;
66
66
}
67
- MatchingResult . prototype . sortBy = function ( cmp ) {
67
+ MatchingResult . prototype . sortBy = function ( cmp ) {
68
68
var comparatorFn = null ;
69
- if ( typeof ( cmp ) == 'string' ) {
69
+ if ( typeof ( cmp ) == 'string' ) {
70
70
cmp . split ( "-" ) . forEach ( direction => {
71
71
var buildInFn = comparators [ direction ] ;
72
- if ( ! buildInFn ) {
73
- throw new Error ( "unknown direction '" + direction + "' in '" + cmp + "'" ) ;
72
+ if ( ! buildInFn ) {
73
+ throw new Error ( "unknown direction '" + direction + "' in '" + cmp + "'" ) ;
74
74
}
75
- ( function ( fn ) {
76
- if ( comparatorFn == null ) {
75
+ ( function ( fn ) {
76
+ if ( comparatorFn == null ) {
77
77
comparatorFn = fn ;
78
- } else {
79
- comparatorFn = ( function ( comparatorFn , fn ) {
80
- return function ( l , r ) {
78
+ } else {
79
+ comparatorFn = ( function ( comparatorFn , fn ) {
80
+ return function ( l , r ) {
81
81
var cmpValue = comparatorFn ( l , r ) ;
82
- if ( cmpValue == 0 ) {
82
+ if ( cmpValue == 0 ) {
83
83
return fn ( l , r ) ;
84
84
}
85
85
return cmpValue ;
@@ -88,7 +88,7 @@ module.exports = function (runtime, scope) {
88
88
}
89
89
} ) ( buildInFn ) ;
90
90
} ) ;
91
- } else {
91
+ } else {
92
92
comparatorFn = cmp ;
93
93
}
94
94
var clone = this . matches . slice ( ) ;
@@ -188,29 +188,32 @@ module.exports = function (runtime, scope) {
188
188
189
189
images . inRange = function ( img , lowerBound , upperBound ) {
190
190
initIfNeeded ( ) ;
191
- var lb , ub ;
192
- if ( typeof ( lowerBound ) == 'string' ) {
193
- if ( typeof ( upperBound ) == 'string' ) {
194
- lb = new Scalar ( colors . red ( lowerBound ) , colors . green ( lowerBound ) ,
195
- colors . blue ( lowerBound ) , colors . alpha ( lowerBound ) ) ;
196
- ub = new Scalar ( colors . red ( upperBound ) , colors . green ( upperBound ) ,
197
- colors . blue ( upperBound ) , colors . alpha ( lowerBound ) ) ;
198
- } else if ( typeof ( upperBound ) == 'number' ) {
199
- var color = lowerBound ;
200
- var threshold = upperBound ;
201
- lb = new Scalar ( colors . red ( color ) - threshold , colors . green ( color ) - threshold ,
202
- colors . blue ( color ) - threshold , colors . alpha ( color ) ) ;
203
- ub = new Scalar ( colors . red ( color ) + threshold , colors . green ( color ) + threshold ,
204
- colors . blue ( color ) + threshold , colors . alpha ( color ) ) ;
205
- } else {
206
- throw new TypeError ( 'lowerBound = ' + lowerBound , + 'upperBound = ' + upperBound ) ;
207
- }
191
+ var lb = new Scalar ( colors . red ( lowerBound ) , colors . green ( lowerBound ) ,
192
+ colors . blue ( lowerBound ) , colors . alpha ( lowerBound ) ) ;
193
+ var ub = new Scalar ( colors . red ( upperBound ) , colors . green ( upperBound ) ,
194
+ colors . blue ( upperBound ) , colors . alpha ( lowerBound ) )
195
+ if ( typeof ( upperBound ) == 'number' ) {
196
+ var color = lowerBound ;
197
+ var threshold = upperBound ;
198
+
199
+ } else {
200
+ throw new TypeError ( 'lowerBound = ' + lowerBound , + 'upperBound = ' + upperBound ) ;
208
201
}
209
202
var bi = new Mat ( ) ;
210
203
Core . inRange ( img . mat , lb , ub , bi ) ;
211
204
return images . matToImage ( bi ) ;
212
205
}
213
206
207
+ images . interval = function ( img , color , threshold ) {
208
+ initIfNeeded ( ) ;
209
+ var lb = new Scalar ( colors . red ( color ) - threshold , colors . green ( color ) - threshold ,
210
+ colors . blue ( color ) - threshold , colors . alpha ( color ) ) ;
211
+ var ub = new Scalar ( colors . red ( color ) + threshold , colors . green ( color ) + threshold ,
212
+ colors . blue ( color ) + threshold , colors . alpha ( color ) ) ;
213
+ var bi = new Mat ( ) ;
214
+ Core . inRange ( img . mat , lb , ub , bi ) ;
215
+ return images . matToImage ( bi ) ;
216
+ }
214
217
215
218
images . adaptiveThreshold = function ( img , maxValue , adaptiveMethod , thresholdType , blockSize , C ) {
216
219
initIfNeeded ( ) ;
@@ -225,7 +228,7 @@ module.exports = function (runtime, scope) {
225
228
initIfNeeded ( ) ;
226
229
var mat = new Mat ( ) ;
227
230
size = newSize ( size ) ;
228
- type = Imgproc [ "BORDER_" + ( type || "CONSTANT " ) ] ;
231
+ type = Imgproc [ "BORDER_" + ( type || "DEFAULT " ) ] ;
229
232
if ( point == undefined ) {
230
233
Imgproc . blur ( img . mat , mat , size ) ;
231
234
} else {
@@ -322,12 +325,10 @@ module.exports = function (runtime, scope) {
322
325
return javaImages . rotate ( img , x , y , degree ) ;
323
326
}
324
327
325
- images . concat = function ( img1 , img2 , direction , rect1 , rect2 ) {
328
+ images . concat = function ( img1 , img2 , direction ) {
326
329
initIfNeeded ( ) ;
327
330
direction = direction || "right" ;
328
- rect1 = buildRegion ( rect1 , img1 ) ;
329
- rect2 = buildRegion ( rect2 , img1 ) ;
330
- return javaImages . concat ( img1 , rect1 , img2 , rect2 , android . view . Gravity [ direction . toUpperCase ( ) ] ) ;
331
+ return javaImages . concat ( img1 , img2 , android . view . Gravity [ direction . toUpperCase ( ) ] ) ;
331
332
}
332
333
333
334
images . detectsColor = function ( img , color , x , y , threshold , algorithm ) {
@@ -525,7 +526,7 @@ module.exports = function (runtime, scope) {
525
526
var width = region [ 2 ] === undefined ? img . getWidth ( ) - x : region [ 2 ] ;
526
527
var height = region [ 3 ] === undefined ? ( img . getHeight ( ) - y ) : region [ 3 ] ;
527
528
var r = new org . opencv . core . Rect ( x , y , width , height ) ;
528
- if ( x < 0 || y < 0 || x + width > img . width || y + height > img . height ) {
529
+ if ( x < 0 || y < 0 || x + width > img . width || y + height > img . height ) {
529
530
throw new Error ( "out of region: region = [" + [ x , y , width , height ] + "], image.size = [" + [ img . width , img . height ] + "]" ) ;
530
531
}
531
532
return r ;
0 commit comments