Add files via upload

This commit is contained in:
LYS
2023-06-03 09:39:17 +08:00
committed by GitHub
parent 620cfa1317
commit 61845d8d50

View File

@@ -160,7 +160,7 @@ module.exports = function (scriptRuntime, scope) {
throw TypeError(`Argument size for images.medianBlur must be either a number or an array with SAME two number elements`); throw TypeError(`Argument size for images.medianBlur must be either a number or an array with SAME two number elements`);
} }
} }
let ksize = Array.isArray(size) ? [ size ][0] : size; let ksize = Array.isArray(size) ? [size][0] : size;
let mat = new Mat(); let mat = new Mat();
Imgproc.medianBlur(img.mat, mat, ksize); Imgproc.medianBlur(img.mat, mat, ksize);
img.shoot(); img.shoot();
@@ -240,7 +240,7 @@ module.exports = function (scriptRuntime, scope) {
this.results = []; this.results = [];
for (let i = 0; i < cir.rows(); i++) { for (let i = 0; i < cir.rows(); i++) {
for (let j = 0; j < cir.cols(); j++) { for (let j = 0; j < cir.cols(); j++) {
let [ x, y, radius ] = cir.get(i, j); let [x, y, radius] = cir.get(i, j);
this.results.push({ x, y, radius }); this.results.push({ x, y, radius });
} }
} }
@@ -304,13 +304,13 @@ module.exports = function (scriptRuntime, scope) {
}, },
findColorInRegion(img, color, x, y, width, height, threshold) { findColorInRegion(img, color, x, y, width, height, threshold) {
return this.findColor(img, color, { return this.findColor(img, color, {
region: [ x, y, width, height ], region: [x, y, width, height],
threshold: threshold, threshold: threshold,
}); });
}, },
findColorEquals(img, color, x, y, width, height) { findColorEquals(img, color, x, y, width, height) {
return this.findColor(img, color, { return this.findColor(img, color, {
region: [ x, y, width, height ], region: [x, y, width, height],
threshold: 0, threshold: 0,
}); });
}, },
@@ -323,21 +323,31 @@ module.exports = function (scriptRuntime, scope) {
'region' in opt ? _.buildRegion(img, opt.region) : null); 'region' in opt ? _.buildRegion(img, opt.region) : null);
return _.toPointArray(o); return _.toPointArray(o);
}, },
findMultiColors(img, firstColor, paths, options) { findMultiColors(img, firstColor, paths, options) {
_.initIfNeeded(); _.initIfNeeded();
let list = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, paths.length * 3); let list = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE, paths.length * 3);
for (let i = 0; i < paths.length; i += 1) { for (let i = 0; i < paths.length; i += 1) {
let [ x, y, color ] = paths[i]; let [x, y, color] = paths[i];
list[i * 3] = x; list[i * 3] = x;
list[i * 3 + 1] = y; list[i * 3 + 1] = y;
list[i * 3 + 2] = colors.toInt(color); list[i * 3 + 2] = colors.toInt(color);
} }
let opt = options || {}; let opt = options || {};
return rtImages.colorFinder.findMultiColors(img, let findAll = opt.All || false;
colors.toInt(firstColor),
_.parseThreshold(opt), if (findAll) {
'region' in opt ? _.buildRegion(img, opt.region) : null, return Array.from(rtImages.colorFinder.findAllMultiColors(img,
list); colors.toInt(firstColor),
_.parseThreshold(opt),
'region' in opt ? _.buildRegion(img, opt.region) : null,
list));
} else {
return rtImages.colorFinder.findMultiColors(img,
colors.toInt(firstColor),
_.parseThreshold(opt),
'region' in opt ? _.buildRegion(img, opt.region) : null,
list);
}
}, },
findImage(img, template, options) { findImage(img, template, options) {
_.initIfNeeded(); _.initIfNeeded();
@@ -350,7 +360,7 @@ module.exports = function (scriptRuntime, scope) {
}, },
findImageInRegion(img, template, x, y, width, height, threshold) { findImageInRegion(img, template, x, y, width, height, threshold) {
return this.findImage(img, template, { return this.findImage(img, template, {
region: [ x, y, width, height ], region: [x, y, width, height],
threshold: threshold, threshold: threshold,
}); });
}, },
@@ -663,7 +673,7 @@ module.exports = function (scriptRuntime, scope) {
if (size.length === 1) { if (size.length === 1) {
width = height = size[0]; width = height = size[0];
} else { } else {
[ width, height ] = size; [width, height] = size;
} }
} }
return new Size(width, height); return new Size(width, height);
@@ -683,7 +693,7 @@ module.exports = function (scriptRuntime, scope) {
* @returns {org.opencv.core.Point} * @returns {org.opencv.core.Point}
*/ */
parsePoint(point) { parsePoint(point) {
let [ x, y ] = point; let [x, y] = point;
return new Point(x, y); return new Point(x, y);
}, },
parseQuality(q) { parseQuality(q) {
@@ -771,10 +781,10 @@ module.exports = function (scriptRuntime, scope) {
* @returns {org.opencv.core.Rect} * @returns {org.opencv.core.Rect}
*/ */
buildRegion(img, region) { buildRegion(img, region) {
let [ x, y, w, h ] = region instanceof org.opencv.core.Rect let [x, y, w, h] = region instanceof org.opencv.core.Rect
? [ region.x, region.y, region.width, region.height ] ? [region.x, region.y, region.width, region.height]
: region instanceof android.graphics.Rect : region instanceof android.graphics.Rect
? [ region.left, region.top, region.width(), region.height() ] ? [region.left, region.top, region.width(), region.height()]
: Array.isArray(region) ? region : []; : Array.isArray(region) ? region : [];
x = _.parseNumber(x, 0); x = _.parseNumber(x, 0);