/** * do a find op with the given image or the given text in the Finder's image * (hasNext() and next() will reveal possible match results) * @param imageOrText image file name or text * @return null. if find setup not possible */ public String find(String imageOrText) { if (!valid) { log(-1, "not valid"); return null; } Image img = Image.create(imageOrText); if (img.isText()) { return findText(imageOrText); } if (img.isValid()) { return find(img); } return null; }
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; }
/** * do a find op with the given pattern in the Finder's image * (hasNext() and next() will reveal possible match results) * @param img Image * @return null. if find setup not possible */ public String find(Image img) { if (!valid) { log(-1, "not valid"); return null; } if (img.isValid()) { _findInput.setTarget(img.getMatNative()); _findInput.setSimilarity(Settings.MinSimilarity); _results = Vision.find(_findInput); _cur_result_i = 0; return img.getFilename(); } else if (img.isUseable()) { return find(new Pattern(img)); } else { return null; } }
Pattern p = new Pattern(img); Finder f = new Finder(img); boolean success = (null != f.find(p)); log(lvl, "testSetup: Finder setup with image %s", (!success ? "did not work" : "worked")); if (success &= f.hasNext()) { success = (null != f.find(img.asFile())); log(lvl, "testSetup: Finder setup with image file %s", (!success ? "did not work" : "worked")); success &= f.hasNext();