@Override public boolean equals(Object oThat) { if (this == oThat) { return true; } if (!(oThat instanceof Match)) { return false; } Match that = (Match) oThat; return x == that.x && y == that.y && w == that.w && h == that.h && Math.abs(simScore - that.simScore) < 1e-5 && getTarget().equals(that.getTarget()); }
protected Location checkMatch() { if (lastMatch != null) { return lastMatch.getTarget(); } return getTarget(); }
/** * convenience - same as {@link Pattern#getTargetOffset()} * * @return the relative offset to the center */ public Location getTargetOffset() { return (getCenter().getOffset(getTarget())); }
protected <PSIMRL> Location getLocationFromTarget(PSIMRL target) throws FindFailed { if (target instanceof Pattern || target instanceof String || target instanceof Image) { Match m = find(target); if (m != null) { if (isOtherScreen()) { return m.getTarget().setOtherScreen(scr); } else { return m.getTarget(); } } return null; } if (target instanceof Match) { return ((Match) target).getTarget(); } if (target instanceof Region) { return ((Region) target).getCenter(); } if (target instanceof Location) { return new Location((Location) target); } return null; } //</editor-fold>
public Point2D getCoords(BufferedImage baseImg, String targetImgPath, double minSimilarityValue) { //set new minimum similarity Settings.MinSimilarity = minSimilarityValue; Match m; Finder f = new Finder(baseImg); Point2D coords = new Point2D.Double(-1, -1); f.find(targetImgPath); if (f.hasNext()) { m = f.next(); coords.setLocation(m.getTarget().getX(), m.getTarget().getY()); } //revert to default similarity Settings.MinSimilarity = DEFAULT_MIN_SIMILARITY; return coords; }
/** * getCoords returns the coordinates of the FIRST element that matches the specified * @param baseImg is the screenshot of the device * @param targetImgPath is the image of the element that you want to find * @return coordinates of the centre of the element found as Point2D */ public Point2D getCoords(BufferedImage baseImg, String targetImgPath) { Match m; Finder f = new Finder(baseImg); Point2D coords = new Point2D.Double(-1, -1); f.find(targetImgPath); if (f.hasNext()) { m = f.next(); coords.setLocation(m.getTarget().getX(), m.getTarget().getY()); } return coords; }
/** * getCoords returns a list of coordinates of all the matches found for the element specified * @param targetImgPath is the image of the element that you want to find * @return list of coordinates of the matches found for the element specified */ public List<Point2D> getCoordsForAllMatchingElements(String targetImgPath) { Finder f = new Finder(takeScreenshot()); List<Point2D> coordsList = new ArrayList<>(); Match m; f.findAll(targetImgPath); while (f.hasNext()) { m = f.next(); coordsList.add(new Point2D.Double(m.getTarget().getX(), m.getTarget().getY())); } return coordsList; }
try { aMatch = wait(args); Mouse.move(aMatch.getTarget()); } catch (Exception ex) { Mouse.move(scr.checkMatch());