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 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; }
/** * 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; }
lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, null); if (!f.hasNext()) { runFinder(f, img); lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, (Pattern) ptn); if (!f.hasNext()) { runFinder(f, ptn); lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, null); if (!f.hasNext()) { runFinder(f, img); lastSearchTimeRepeat = lastSearchTime; lastSearchTime = (new Date()).getTime() - lastSearchTime; if (f.hasNext()) { lastFindTime = (new Date()).getTime() - lastFindTime; m = f.next();
if (img.isValid()) { finder = doCheckLastSeenAndCreateFinder(base, img, 0.0, null); if (!finder.hasNext()) { runFinder(finder, img); img = ((Pattern) target).getImage(); finder = doCheckLastSeenAndCreateFinder(base, img, 0.0, (Pattern) target); if (!finder.hasNext()) { runFinder(finder, target); img = ((Image) target); finder = doCheckLastSeenAndCreateFinder(base, img, 0.0, null); if (!finder.hasNext()) { runFinder(finder, img); return null; if (finder.hasNext()) { match = finder.next(); match.setImage(img);
Finder f = new Finder(new Screen().capture(r), r); f.find(new Pattern(img).similar(Settings.CheckLastSeenSimilar)); if (f.hasNext()) { log(lvl + 1, "checkLastSeen: still there"); match = new Match(new Region(img.getLastSeen()), img.getLastSeenScore()); now = (new Date()).getTime(); finder.find(img); if (finder.hasNext()) { match = finder.next(); match.setTimes(0, now - lastSearchTime);
/** * * @return the next match or null */ @Override public Match next() { Match match = null; if (hasNext()) { FindResult fr = _results.get(_cur_result_i++); IScreen parentScreen = null; if (screenFinder && _region != null) { parentScreen = _region.getScreen(); } match = new Match(fr, parentScreen); match.setOnScreen(screenFinder); fr.delete(); if (_region != null) { match = _region.toGlobalCoord(match); } if (_pattern != null) { Location offset = _pattern.getTargetOffset(); match.setTargetOffset(offset); } match.setImage(_image); } return match; } }
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(); String screenFind = "Screen.find(imagefile)"; try {
if (f.hasNext()) { return f;
f.find(new Pattern(ptn).similar(score)); if (f.hasNext()) { log(lvl, "checkLastSeen: still there"); return f;