|
|
|
@ -57,6 +57,10 @@ public abstract class JMacro {
|
|
|
|
|
this.legend = legend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Robot getRobot() {
|
|
|
|
|
return robot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getLegend() {
|
|
|
|
|
return legend;
|
|
|
|
|
}
|
|
|
|
@ -401,11 +405,30 @@ public abstract class JMacro {
|
|
|
|
|
//中心点
|
|
|
|
|
boolean cc = ColorUtil.isSimilar(screenData[x - xMin + pic.getWidth() / 2][y - yMin + pic.getHeight() / 2], picData[pic.getWidth() / 2][pic.getHeight() / 2]);
|
|
|
|
|
if (lt && rt && lb && rb && cc) {
|
|
|
|
|
// 进行全像素匹配
|
|
|
|
|
double similar = ImageUtil.calcSimilar(x - xMin, y - yMin, pic.getHeight(), pic.getWidth(), screenData, picData);
|
|
|
|
|
// 统计相似点数
|
|
|
|
|
int samePixels = 0;
|
|
|
|
|
// 统计不相似点数
|
|
|
|
|
int diffPixels = 0;
|
|
|
|
|
for (int smallY = 0; smallY < pic.getHeight(); smallY++) {
|
|
|
|
|
for (int smallX = 0; smallX < pic.getWidth(); smallX++) {
|
|
|
|
|
if (ColorUtil.isSimilar(screenData[x + smallX][y + smallY], picData[smallX][smallY])) {
|
|
|
|
|
samePixels++;
|
|
|
|
|
} else {
|
|
|
|
|
diffPixels++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 计算目前相似度
|
|
|
|
|
double similar = (double) samePixels / (pic.getWidth() * pic.getHeight());
|
|
|
|
|
if (similar >= minSimilar) {
|
|
|
|
|
return new ViewRect(x, y, x + pic.getWidth(), y + pic.getHeight(), similar);
|
|
|
|
|
}
|
|
|
|
|
// 计算目前最大相似度
|
|
|
|
|
// 根据不相似像素点数推断本次可能达到的最大相似度,如果可能达到的最大相似度都小于预取相似度就不用比下去了
|
|
|
|
|
double maxSimilar = 1.0d - (double) diffPixels / (pic.getWidth() * pic.getHeight());
|
|
|
|
|
if (maxSimilar < minSimilar) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -575,13 +598,13 @@ public abstract class JMacro {
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(ViewRect rect, File file, double minSimilar, long time, TimeUnit unit) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
// TODO: 2024/9/1 因为另起线程,导致发起线程已停止,但此线程未停止
|
|
|
|
|
while (true) {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect matchPic = matchPic(rect, file, minSimilar);
|
|
|
|
|
if (matchPic != null) {
|
|
|
|
|
return matchPic;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, time, unit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|