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