|
|
|
@ -345,20 +345,9 @@ public abstract class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findPic(File pic, double minSimilar) {
|
|
|
|
|
return findPic(getFocusRect(), ImageUtil.load(pic), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 全屏查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findPic(BufferedImage pic, double minSimilar) {
|
|
|
|
|
return findPic(getFocusRect(), pic, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -368,10 +357,20 @@ public abstract class JMacro {
|
|
|
|
|
* @param viewRect 查找范围(不设时,取全屏)
|
|
|
|
|
* @param pic 待查找图片
|
|
|
|
|
* @param minSimilar 相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, File pic, double minSimilar) {
|
|
|
|
|
return findPic(viewRect, ImageUtil.load(pic), minSimilar);
|
|
|
|
|
if (!pic.exists()) {
|
|
|
|
|
Logger.error("[{}] does not exist!", pic.getAbsolutePath());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!pic.isFile()) {
|
|
|
|
|
Logger.error("[{}] is not a file!", pic.getAbsolutePath());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Logger.info("查找图片:{}", pic.getAbsolutePath());
|
|
|
|
|
BufferedImage bufferedImage = ImageUtil.load(pic);
|
|
|
|
|
return findPic(viewRect, bufferedImage, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -380,7 +379,7 @@ public abstract class JMacro {
|
|
|
|
|
* @param viewRect 查找范围(不设时,取全屏)
|
|
|
|
|
* @param pic 待查找图片
|
|
|
|
|
* @param minSimilar 相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findPic(ViewRect viewRect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
// 当聚焦区域为null时,默认全屏查找
|
|
|
|
@ -450,48 +449,61 @@ public abstract class JMacro {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(String legend, double minSimilar) {
|
|
|
|
|
return findLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图片
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return findLegend(getFocusRect(), legend, minSimilar);
|
|
|
|
|
public ViewRect waitAndFindPic(File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图例
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, String legend, double minSimilar) {
|
|
|
|
|
return findLegend(rect, Legend.inflate(legend), minSimilar);
|
|
|
|
|
public ViewRect waitAndFindPic(File pic, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找图例
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param picFile 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, Legend legend, double minSimilar) {
|
|
|
|
|
Logger.info("查找图例:{}", legend.getName());
|
|
|
|
|
return findPic(rect, legend.getFile(), minSimilar);
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File picFile, double minSimilar, long seconds) {
|
|
|
|
|
Logger.info("等待并查找图片:{}", picFile.getAbsolutePath());
|
|
|
|
|
BufferedImage pic = ImageUtil.load(picFile);
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect result = findPic(rect, pic, minSimilar);
|
|
|
|
|
if (result != null) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -499,10 +511,10 @@ public abstract class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(legend.getFile(), minSimilar, seconds);
|
|
|
|
|
public ViewRect findLegend(String legend, double minSimilar) {
|
|
|
|
|
return findLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -510,252 +522,217 @@ public abstract class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindLegend(ViewRect rect, Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(rect, legend.getFile(), minSimilar, seconds);
|
|
|
|
|
public ViewRect findLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return findLegend(getFocusRect(), legend, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, String legend, double minSimilar) {
|
|
|
|
|
return findLegend(rect, Legend.inflate(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(BufferedImage pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect findLegend(ViewRect rect, Legend legend, double minSimilar) {
|
|
|
|
|
Logger.info("查找图例:{}", legend.getName());
|
|
|
|
|
return findPic(rect, legend.getImage(), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(File pic, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, seconds);
|
|
|
|
|
public ViewRect waitAndFindLegend(ViewRect rect, Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
Logger.info("等待并查找图例:{}", legend.getName());
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect result = findPic(rect, legend.getImage(), minSimilar);
|
|
|
|
|
if (result != null) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(BufferedImage pic, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, seconds);
|
|
|
|
|
public ViewRect waitAndFindLegend(ViewRect rect, String legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindLegend(rect, Legend.inflate(legend), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect waitAndFindLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindLegend(getFocusRect(), legend, minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File pic, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindPic(rect, ImageUtil.load(pic), minSimilar, seconds);
|
|
|
|
|
public ViewRect waitAndFindLegend(String legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndFindLegend(getFocusRect(), Legend.inflate(legend), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect waitAndFindLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return waitAndFindLegend(getFocusRect(), legend, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图片
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
* @param rect 查找区域
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, BufferedImage pic, double minSimilar, long seconds) {
|
|
|
|
|
if (rect.getWidth() < pic.getWidth()) {
|
|
|
|
|
Logger.error("查找图片区域宽度{}小于图片宽度{}", rect.getWidth(), pic.getWidth());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (rect.getHeight() < pic.getHeight()) {
|
|
|
|
|
Logger.error("查找图片区域宽度{}小于图片宽度{}", rect.getHeight(), pic.getHeight());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect result = findPic(rect, pic, minSimilar);
|
|
|
|
|
if (result != null) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
public ViewRect waitAndFindLegend(String legend, double minSimilar) {
|
|
|
|
|
return waitAndFindLegend(getFocusRect(), Legend.inflate(legend), minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图片
|
|
|
|
|
* 匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param location 定位
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect matchPic(File pic, ViewPoint location, double minSimilar) {
|
|
|
|
|
if (!pic.exists()) {
|
|
|
|
|
Logger.error("file [{}] not exist", pic.getAbsolutePath());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return matchPic(ImageUtil.load(pic), location, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ViewRect matchPic(BufferedImage pic, ViewPoint location, double minSimilar) {
|
|
|
|
|
ViewRect focusRect = getFocusRect();
|
|
|
|
|
int offsetX = location.getX();
|
|
|
|
|
int offsetY = location.getY();
|
|
|
|
|
public ViewRect matchLegend(Legend legend, double minSimilar) {
|
|
|
|
|
BufferedImage image = ImageUtil.load(legend.getFile());
|
|
|
|
|
// 获取图例相对坐标
|
|
|
|
|
int offsetX = legend.getLocation().getX();
|
|
|
|
|
int offsetY = legend.getLocation().getY();
|
|
|
|
|
// 根据原点计算图例绝对坐标
|
|
|
|
|
ViewRect viewRect = new ViewRect();
|
|
|
|
|
viewRect.setLeft(focusRect.getLeft() + offsetX);
|
|
|
|
|
viewRect.setTop(focusRect.getTop() + offsetY);
|
|
|
|
|
viewRect.setRight(viewRect.getLeft() + pic.getWidth());
|
|
|
|
|
viewRect.setBottom(viewRect.getTop() + pic.getHeight());
|
|
|
|
|
ImageUtil.show(viewRect);
|
|
|
|
|
return findPic(viewRect, pic, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图片
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(File pic, ViewPoint location, double minSimilar) {
|
|
|
|
|
return waitAndMatchPic(ImageUtil.load(pic), location, minSimilar);
|
|
|
|
|
viewRect.setLeft(getFocusRect().getLeft() + offsetX);
|
|
|
|
|
viewRect.setTop(getFocusRect().getTop() + offsetY);
|
|
|
|
|
viewRect.setRight(viewRect.getLeft() + image.getWidth());
|
|
|
|
|
viewRect.setBottom(viewRect.getTop() + image.getHeight());
|
|
|
|
|
Logger.info("匹配图例:{},区域:{}", legend.getName(), viewRect);
|
|
|
|
|
return findPic(viewRect, image, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图片
|
|
|
|
|
* 匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(BufferedImage pic, ViewPoint location, double minSimilar) {
|
|
|
|
|
return waitAndMatchPic(pic, location, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect matchLegend(String legend, double minSimilar) {
|
|
|
|
|
return matchLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图片
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(File pic, ViewPoint location, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndMatchPic(ImageUtil.load(pic), location, minSimilar, seconds);
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
Logger.info("等待并匹配图例:{}", legend.getName());
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect result = findPic(getFocusRect(), legend.getImage(), minSimilar);
|
|
|
|
|
if (result != null) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图片
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param pic 图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(BufferedImage pic, ViewPoint location, double minSimilar, long seconds) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect matchPic = matchPic(pic, location, minSimilar);
|
|
|
|
|
if (matchPic != null) {
|
|
|
|
|
return matchPic;
|
|
|
|
|
}
|
|
|
|
|
delayUnstable();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
public ViewRect waitAndMatchLegend(String legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndMatchLegend(Legend.inflate(legend), minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图例
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param legends 图例
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect[] waitAndMatchLegend(String[] legends, long seconds) {
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect[] viewRects = matchLegend(legends);
|
|
|
|
|
for (ViewRect viewRect : viewRects) {
|
|
|
|
|
if (viewRect != null) {
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delayUnstable();
|
|
|
|
|
}
|
|
|
|
|
return new ViewRect[legends.length];
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
public ViewRect waitAndMatchLegend(String legend, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegend(legend, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图例
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param legends 图例
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect[] matchLegend(String... legends) {
|
|
|
|
|
return matchLegend(legends, 1.0);
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegend(legend, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图例
|
|
|
|
|
* 图例组合匹配,图例区域结果和入参长度一致,任意图例检测到后则会返回,其他未检测到的区域则为null
|
|
|
|
|
* <p>
|
|
|
|
|
* 说明:一个操作之后可能会有多个预期结果,以发起【进攻】操作为例,可能会提示多种结果如下:
|
|
|
|
|
* 1.成功发起
|
|
|
|
|
* 2.敌人已逃走
|
|
|
|
|
* 3.兵力不足
|
|
|
|
|
* 不同的操作返回结果,会有不同的后续操作;如果以获取某一结果去检测,考虑处理时间延迟等需要加上等待时间
|
|
|
|
|
* 不同结果的获取就会依次串行,这样检查肯定会浪费大量检测时间。因此正对此情况做了并联检测机制。
|
|
|
|
|
*
|
|
|
|
|
* @param legends 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect[] matchLegend(String[] legends, double minSimilar) {
|
|
|
|
|
public ViewRect[] matchLegends(String[] legends, double minSimilar) {
|
|
|
|
|
ViewRect[] viewRects = new ViewRect[legends.length];
|
|
|
|
|
for (int i = 0; i < legends.length; i++) {
|
|
|
|
|
String legend = legends[i];
|
|
|
|
|
viewRects[i] = matchLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
viewRects[i] = matchLegend(legend, minSimilar);
|
|
|
|
|
if (viewRects[i] != null) {
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
@ -764,83 +741,73 @@ public abstract class JMacro {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图例
|
|
|
|
|
* 多图例匹配调用优化
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param legends 图例
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect matchLegend(String legend, double minSimilar) {
|
|
|
|
|
return matchLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
public ViewRect[] matchLegends(double minSimilar, String... legends) {
|
|
|
|
|
return matchLegends(legends, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 匹配图片
|
|
|
|
|
* 等待并匹配图例组合
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param legends 图例组
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect matchLegend(Legend legend, double minSimilar) {
|
|
|
|
|
if (minSimilar > 1) {
|
|
|
|
|
throw new RuntimeException("this minSimilar must be less than 1");
|
|
|
|
|
public ViewRect[] waitAndMatchLegends(String[] legends, double minSimilar, long seconds) {
|
|
|
|
|
if (legends.length == 0) {
|
|
|
|
|
return new ViewRect[0];
|
|
|
|
|
}
|
|
|
|
|
int offsetX = legend.getLocation().getX();
|
|
|
|
|
int offsetY = legend.getLocation().getY();
|
|
|
|
|
ViewRect viewRect = new ViewRect();
|
|
|
|
|
viewRect.setLeft(getFocusRect().getLeft() + offsetX);
|
|
|
|
|
viewRect.setTop(getFocusRect().getTop() + offsetY);
|
|
|
|
|
BufferedImage image = ImageUtil.load(legend.getFile());
|
|
|
|
|
viewRect.setRight(viewRect.getLeft() + image.getWidth());
|
|
|
|
|
viewRect.setBottom(viewRect.getTop() + image.getHeight());
|
|
|
|
|
//ImageUtil.show(viewRect);
|
|
|
|
|
return findPic(viewRect, image, minSimilar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchLegend(String legend, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegend(Legend.inflate(legend), minSimilar);
|
|
|
|
|
Logger.info("等待并匹配图例组合:{}", String.join(",", legends));
|
|
|
|
|
return TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
ViewRect[] viewRects = matchLegends(legends, minSimilar);
|
|
|
|
|
for (ViewRect viewRect : viewRects) {
|
|
|
|
|
if (viewRect != null) {
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
* 等待并匹配图例组合
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @param legends 图例组
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegend(legend, minSimilar, defaultTimeOut);
|
|
|
|
|
public ViewRect[] waitAndMatchLegends(double minSimilar, long seconds, String... legends) {
|
|
|
|
|
return waitAndMatchLegends(legends, minSimilar, seconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
* 等待并匹配图例组合
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @param legends 图例组
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchLegend(String legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndMatchLegend(Legend.inflate(legend), minSimilar, seconds);
|
|
|
|
|
public ViewRect[] waitAndMatchLegends(double minSimilar, String... legends) {
|
|
|
|
|
return waitAndMatchLegends(legends, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
* 等待并匹配图例组合
|
|
|
|
|
*
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param legends 图例组
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar, long seconds) {
|
|
|
|
|
return waitAndMatchPic(legend.getFile(), legend.getLocation(), minSimilar, seconds);
|
|
|
|
|
public ViewRect[] waitAndMatchLegends(String[] legends, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegends(legends, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -863,7 +830,7 @@ public abstract class JMacro {
|
|
|
|
|
*
|
|
|
|
|
* @param color 色值坐标点
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public boolean waitAndMatchColor(ViewColor color, long seconds) {
|
|
|
|
|
Boolean result = TaskUtil.timeTask(() -> {
|
|
|
|
|