fix: selected pyramid level too small
This commit is contained in:
@@ -95,7 +95,10 @@ module.exports = function(__runtime__, scope){
|
||||
images.findImage = function(img, template, options){
|
||||
options = options || {};
|
||||
var threshold = options.threshold || 0.9;
|
||||
var maxLevel = options.level || -1;
|
||||
var maxLevel = -1;
|
||||
if(typeof(options.level) == 'number'){
|
||||
maxLevel = options.level;
|
||||
}
|
||||
var weakThreshold = options.weakThreshold || 0.7;
|
||||
if(options.region){
|
||||
return rtImages.findImage(img, template, weakThreshold, threshold, buildRegion(options, img), maxLevel);
|
||||
|
||||
@@ -76,18 +76,18 @@ public class TemplateMatching {
|
||||
Pair<Point, Double> bestMatched = getBestMatched(matchResult, matchMethod, weakThreshold);
|
||||
//不满足弱阈值,返回null
|
||||
if (bestMatched.second < weakThreshold) {
|
||||
p = null;
|
||||
break;
|
||||
// p = null;
|
||||
// break;
|
||||
}
|
||||
p = bestMatched.first;
|
||||
similarity = bestMatched.second;
|
||||
p.x += r.x;
|
||||
p.y += r.y;
|
||||
//满足强阈值,返回当前结果
|
||||
if (bestMatched.second >= strictThreshold) {
|
||||
pyrUp(p, level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//满足强阈值,返回当前结果
|
||||
if (similarity >= strictThreshold) {
|
||||
pyrUp(p, level);
|
||||
break;
|
||||
}
|
||||
logger.addSplit("level:" + level + " point:" + p);
|
||||
isFirstMatching = false;
|
||||
@@ -150,8 +150,8 @@ public class TemplateMatching {
|
||||
|
||||
private static int selectPyramidLevel(Mat img, Mat template) {
|
||||
int minDim = Nath.min(img.rows(), img.cols(), template.rows(), template.cols());
|
||||
//这里选取12为图像缩小后的最小宽高,从而用log(2, minDim / 16)得到最多可以经过几次缩小。
|
||||
int maxLevel = (int) (Math.log(minDim / 7) / Math.log(2));
|
||||
//这里选取16为图像缩小后的最小宽高,从而用log(2, minDim / 16)得到最多可以经过几次缩小。
|
||||
int maxLevel = (int) (Math.log(minDim / 16) / Math.log(2));
|
||||
if (maxLevel < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,20 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class Drawables {
|
||||
|
||||
private final Pattern DATA_PATTERN = Pattern.compile("data:(\\w+/\\w+);base64,(.+)");
|
||||
private static final Pattern DATA_PATTERN = Pattern.compile("data:(\\w+/\\w+);base64,(.+)");
|
||||
private static ImageLoader sDefaultImageLoader = new DefaultImageLoader();
|
||||
private ImageLoader mImageLoader = sDefaultImageLoader;
|
||||
|
||||
public static void setDefaultImageLoader(ImageLoader defaultImageLoader) {
|
||||
if (defaultImageLoader == null)
|
||||
throw new NullPointerException();
|
||||
sDefaultImageLoader = defaultImageLoader;
|
||||
}
|
||||
|
||||
public static ImageLoader getDefaultImageLoader() {
|
||||
return sDefaultImageLoader;
|
||||
}
|
||||
|
||||
public Drawable parse(Context context, String value) {
|
||||
Resources resources = context.getResources();
|
||||
if (value.startsWith("@color/") || value.startsWith("@android:color/") || value.startsWith("#")) {
|
||||
@@ -93,7 +99,7 @@ public class Drawables {
|
||||
view.setImageBitmap(bitmap);
|
||||
}
|
||||
|
||||
public Bitmap loadData(String data) {
|
||||
public static Bitmap loadData(String data) {
|
||||
Matcher matcher = DATA_PATTERN.matcher(data);
|
||||
if (!matcher.matches() || matcher.groupCount() != 2) {
|
||||
return null;
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.stardust.autojs.core.image.ImageWrapper;
|
||||
import com.stardust.autojs.core.image.ScreenCaptureRequester;
|
||||
import com.stardust.autojs.core.image.ScreenCapturer;
|
||||
import com.stardust.autojs.core.image.TemplateMatching;
|
||||
import com.stardust.autojs.core.ui.inflater.util.Drawables;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||
import com.stardust.concurrent.VolatileDispose;
|
||||
@@ -151,6 +152,10 @@ public class Images {
|
||||
return ImageWrapper.ofBitmap(bitmap);
|
||||
}
|
||||
|
||||
public ImageWrapper decodeBase64(String data){
|
||||
return ImageWrapper.ofBitmap(Drawables.loadData(data));
|
||||
}
|
||||
|
||||
public ImageWrapper load(String src) {
|
||||
try {
|
||||
URL url = new URL(src);
|
||||
|
||||
Reference in New Issue
Block a user