Merge pull request #72 from LYS86/master

PR#72 - LYS86 - findMultiColors调整
This commit is contained in:
SuperMonster003
2023-06-03 15:27:20 +08:00
committed by GitHub
2 changed files with 46 additions and 17 deletions

View File

@@ -333,11 +333,21 @@ module.exports = function (scriptRuntime, scope) {
list[i * 3 + 2] = colors.toInt(color); list[i * 3 + 2] = colors.toInt(color);
} }
let opt = options || {}; let opt = options || {};
let findAll = opt.All || false;
if (findAll) {
return Array.from(rtImages.colorFinder.findAllMultiColors(img,
colors.toInt(firstColor),
_.parseThreshold(opt),
'region' in opt ? _.buildRegion(img, opt.region) : null,
list));
} else {
return rtImages.colorFinder.findMultiColors(img, return rtImages.colorFinder.findMultiColors(img,
colors.toInt(firstColor), colors.toInt(firstColor),
_.parseThreshold(opt), _.parseThreshold(opt),
'region' in opt ? _.buildRegion(img, opt.region) : null, 'region' in opt ? _.buildRegion(img, opt.region) : null,
list); list);
}
}, },
findImage(img, template, options) { findImage(img, template, options) {
_.initIfNeeded(); _.initIfNeeded();

View File

@@ -13,6 +13,10 @@ import org.opencv.core.Point;
import org.opencv.core.Rect; import org.opencv.core.Rect;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import java.util.List;
import java.util.ArrayList;
/** /**
* Created by Stardust on 2017/5/18. * Created by Stardust on 2017/5/18.
*/ */
@@ -109,6 +113,21 @@ public class ColorFinder {
return result; return result;
} }
public Point[] findAllMultiColors(ImageWrapper image, int firstColor, int threshold, Rect rect, int[] points) {
Point[] firstPoints = findAllPointsForColor(image, firstColor, threshold, rect);
List<Point> resultPoints = new ArrayList<>();
for (Point firstPoint : firstPoints) {
if (firstPoint != null) {
if (checksPath(image, firstPoint, threshold, points)) {
resultPoints.add(firstPoint);
}
}
}
image.shoot();
return resultPoints.toArray(new Point[0]);
}
private boolean checksPath(ImageWrapper image, Point startingPoint, int threshold, int[] points) { private boolean checksPath(ImageWrapper image, Point startingPoint, int threshold, int[] points) {
for (int i = 0; i < points.length; i += 3) { for (int i = 0; i < points.length; i += 3) {
int x = points[i]; int x = points[i];