fix(images): another mat released causes the mat recycled???

This commit is contained in:
hyb1996 2018-03-31 22:05:36 +08:00
parent 77c0d6bd19
commit 18a2543bb1
3 changed files with 10 additions and 4 deletions

View File

@ -73,6 +73,7 @@ public class UiSelector extends UiGlobalSelector {
public UiObjectCollection find() {
ensureAccessibilityServiceEnabled();
AccessibilityNodeInfo root = mAccessibilityBridge.getRootInActiveWindow();
Log.d(TAG, "find: root = " + root);
if (root == null) {
return UiObjectCollection.EMPTY;
}

View File

@ -1,5 +1,6 @@
package com.stardust.autojs.core.image;
import android.util.Log;
import android.util.Pair;
import android.util.TimingLogger;
@ -65,8 +66,8 @@ public class TemplateMatching {
if (!isFirstMatching && !shouldContinueMatching(level, maxLevel)) {
break;
}
if (matchResult != null)
matchResult.release();
// if (matchResult != null)
// matchResult.release();
matchResult = matchTemplate(src, currentTemplate, matchMethod);
Pair<Point, Double> bestMatched = getBestMatched(matchResult, matchMethod, weakThreshold);
p = bestMatched.first;
@ -74,8 +75,8 @@ public class TemplateMatching {
} else {
//根据上一轮的匹配点计算本次匹配的区域
Rect r = getROI(p, src, currentTemplate);
if (matchResult != null)
matchResult.release();
// if (matchResult != null)
// matchResult.release();
Mat m = new Mat(src, r);
matchResult = matchTemplate(m, currentTemplate, matchMethod);
m.release();
@ -171,6 +172,8 @@ public class TemplateMatching {
public static Mat matchTemplate(Mat img, Mat temp, int match_method) {
int result_cols = img.cols() - temp.cols() + 1;
int result_rows = img.rows() - temp.rows() + 1;
Log.d(LOG_TAG, "matchTemplate: cols = " + result_cols + ", rows = " + result_rows);
Log.d(LOG_TAG, "matchTemplate: img = " + img + ", temp = " + temp);
Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
Imgproc.matchTemplate(img, temp, result, match_method);
return result;

View File

@ -10,6 +10,7 @@ import android.os.Build;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.util.Base64;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
@ -251,6 +252,7 @@ public class Images {
if (rect != null) {
src = new Mat(src, rect);
}
Log.d("Images", "matchTemplate: img = " + src + ", temp = " + template.getMat());
org.opencv.core.Point point = TemplateMatching.fastTemplateMatching(src, template.getMat(), TemplateMatching.MATCHING_METHOD_DEFAULT,
weakThreshold, threshold, maxLevel);
if (point != null) {