修复 matchTemplate函数返回的结果相等或接近的问题
修复 app.getUriForFile()等报错的问题
This commit is contained in:
@@ -146,7 +146,7 @@ module.exports = function (runtime, global) {
|
|||||||
if (app.fileProviderAuthority == null) {
|
if (app.fileProviderAuthority == null) {
|
||||||
return android.net.Uri.fromFile(file);
|
return android.net.Uri.fromFile(file);
|
||||||
}
|
}
|
||||||
return androidx.core.content.FileProvider.getUriForFile(context,
|
return Packages["androidx"].core.content.FileProvider.getUriForFile(context,
|
||||||
app.fileProviderAuthority, file);
|
app.fileProviderAuthority, file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ module.exports = function(runtime, global){
|
|||||||
});
|
});
|
||||||
|
|
||||||
auto.__defineGetter__("windows", function() {
|
auto.__defineGetter__("windows", function() {
|
||||||
var service = auto.getService();
|
var service = auto.service;
|
||||||
return service == null ? [] : util.java.toJsArray(service.getWindows(), true);
|
return service == null ? [] : util.java.toJsArray(service.getWindows(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -192,13 +192,6 @@ module.exports = function (runtime, scope) {
|
|||||||
colors.blue(lowerBound), colors.alpha(lowerBound));
|
colors.blue(lowerBound), colors.alpha(lowerBound));
|
||||||
var ub = new Scalar(colors.red(upperBound), colors.green(upperBound),
|
var ub = new Scalar(colors.red(upperBound), colors.green(upperBound),
|
||||||
colors.blue(upperBound), colors.alpha(lowerBound))
|
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();
|
var bi = new Mat();
|
||||||
Core.inRange(img.mat, lb, ub, bi);
|
Core.inRange(img.mat, lb, ub, bi);
|
||||||
return images.matToImage(bi);
|
return images.matToImage(bi);
|
||||||
@@ -228,7 +221,7 @@ module.exports = function (runtime, scope) {
|
|||||||
initIfNeeded();
|
initIfNeeded();
|
||||||
var mat = new Mat();
|
var mat = new Mat();
|
||||||
size = newSize(size);
|
size = newSize(size);
|
||||||
type = Imgproc["BORDER_" + (type || "DEFAULT")];
|
type = Core["BORDER_" + (type || "DEFAULT")];
|
||||||
if (point == undefined) {
|
if (point == undefined) {
|
||||||
Imgproc.blur(img.mat, mat, size);
|
Imgproc.blur(img.mat, mat, size);
|
||||||
} else {
|
} else {
|
||||||
@@ -251,7 +244,7 @@ module.exports = function (runtime, scope) {
|
|||||||
size = newSize(size);
|
size = newSize(size);
|
||||||
sigmaX = sigmaX == undefined ? 0 : sigmaX;
|
sigmaX = sigmaX == undefined ? 0 : sigmaX;
|
||||||
sigmaY = sigmaY == undefined ? 0 : sigmaY;
|
sigmaY = sigmaY == undefined ? 0 : sigmaY;
|
||||||
type = Imgproc["BORDER_" + (type || "DEFAULT")];
|
type = Core["BORDER_" + (type || "DEFAULT")];
|
||||||
Imgproc.GaussianBlur(img.mat, mat, size, sigmaX, sigmaY, type);
|
Imgproc.GaussianBlur(img.mat, mat, size, sigmaX, sigmaY, type);
|
||||||
return images.matToImage(mat);
|
return images.matToImage(mat);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,9 +214,11 @@ public class TemplateMatching {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
outResult.add(bestMatched);
|
outResult.add(bestMatched);
|
||||||
Imgproc.rectangle(tmResult, bestMatched.point,
|
Point start = new Point(Math.max(0, bestMatched.point.x - template.width() + 1),
|
||||||
new Point(bestMatched.point.x + template.cols(), bestMatched.point.y + template.rows()),
|
Math.max(0, bestMatched.point.y - template.height() + 1));
|
||||||
new Scalar(0, 255, 0), -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ public class Images {
|
|||||||
if (rect != null) {
|
if (rect != null) {
|
||||||
src = new Mat(src, rect);
|
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);
|
weakThreshold, threshold, maxLevel, limit);
|
||||||
for (TemplateMatching.Match match : result) {
|
for (TemplateMatching.Match match : result) {
|
||||||
Point point = match.point;
|
Point point = match.point;
|
||||||
@@ -331,7 +331,6 @@ public class Images {
|
|||||||
if (src != image.getMat()) {
|
if (src != image.getMat()) {
|
||||||
OpenCVHelper.release(src);
|
OpenCVHelper.release(src);
|
||||||
}
|
}
|
||||||
Collections.sort(result, (l, r) -> Double.compare(r.similarity, l.similarity));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user