Skip to content

Commit

Permalink
修复 matchTemplate函数返回的结果相等或接近的问题
Browse files Browse the repository at this point in the history
修复 app.getUriForFile()等报错的问题
  • Loading branch information
hyb1996 committed Dec 21, 2018
1 parent f65ab0f commit d05b65b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion autojs/src/main/assets/modules/__app__.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module.exports = function (runtime, global) {
if (app.fileProviderAuthority == null) {
return android.net.Uri.fromFile(file);
}
return androidx.core.content.FileProvider.getUriForFile(context,
return Packages["androidx"].core.content.FileProvider.getUriForFile(context,
app.fileProviderAuthority, file);
};

Expand Down
2 changes: 1 addition & 1 deletion autojs/src/main/assets/modules/__automator__.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module.exports = function(runtime, global){
});

auto.__defineGetter__("windows", function() {
var service = auto.getService();
var service = auto.service;
return service == null ? [] : util.java.toJsArray(service.getWindows(), true);
});

Expand Down
11 changes: 2 additions & 9 deletions autojs/src/main/assets/modules/__images__.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ module.exports = function (runtime, scope) {
colors.blue(lowerBound), colors.alpha(lowerBound));
var ub = new Scalar(colors.red(upperBound), colors.green(upperBound),
colors.blue(upperBound), colors.alpha(lowerBound))
if (typeof (upperBound) == 'number') {
var color = lowerBound;
var threshold = upperBound;

} else {
throw new TypeError('lowerBound = ' + lowerBound, + 'upperBound = ' + upperBound);
}
var bi = new Mat();
Core.inRange(img.mat, lb, ub, bi);
return images.matToImage(bi);
Expand Down Expand Up @@ -228,7 +221,7 @@ module.exports = function (runtime, scope) {
initIfNeeded();
var mat = new Mat();
size = newSize(size);
type = Imgproc["BORDER_" + (type || "DEFAULT")];
type = Core["BORDER_" + (type || "DEFAULT")];
if (point == undefined) {
Imgproc.blur(img.mat, mat, size);
} else {
Expand All @@ -251,7 +244,7 @@ module.exports = function (runtime, scope) {
size = newSize(size);
sigmaX = sigmaX == undefined ? 0 : sigmaX;
sigmaY = sigmaY == undefined ? 0 : sigmaY;
type = Imgproc["BORDER_" + (type || "DEFAULT")];
type = Core["BORDER_" + (type || "DEFAULT")];
Imgproc.GaussianBlur(img.mat, mat, size, sigmaX, sigmaY, type);
return images.matToImage(mat);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ private static void getBestMatched(Mat tmResult, Mat template, int matchMethod,
break;
}
outResult.add(bestMatched);
Imgproc.rectangle(tmResult, bestMatched.point,
new Point(bestMatched.point.x + template.cols(), bestMatched.point.y + template.rows()),
new Scalar(0, 255, 0), -1);
Point start = new Point(Math.max(0, bestMatched.point.x - template.width() + 1),
Math.max(0, bestMatched.point.y - template.height() + 1));
Point end = new Point(Math.min(tmResult.width(), bestMatched.point.x + template.width()),
Math.min(tmResult.height(), bestMatched.point.y + template.height()));
Imgproc.rectangle(tmResult, start, end, new Scalar(0, 255, 0), -1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public List<TemplateMatching.Match> matchTemplate(ImageWrapper image, ImageWrapp
if (rect != null) {
src = new Mat(src, rect);
}
List<TemplateMatching.Match> result = TemplateMatching.fastTemplateMatching(src, template.getMat(), TemplateMatching.MATCHING_METHOD_DEFAULT,
List<TemplateMatching.Match> result = TemplateMatching.fastTemplateMatching(src, template.getMat(), Imgproc.TM_CCOEFF_NORMED,
weakThreshold, threshold, maxLevel, limit);
for (TemplateMatching.Match match : result) {
Point point = match.point;
Expand All @@ -331,7 +331,6 @@ public List<TemplateMatching.Match> matchTemplate(ImageWrapper image, ImageWrapp
if (src != image.getMat()) {
OpenCVHelper.release(src);
}
Collections.sort(result, (l, r) -> Double.compare(r.similarity, l.similarity));
return result;
}

Expand Down

0 comments on commit d05b65b

Please sign in to comment.