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; }
@Override protected void finalize() throws Throwable { super.finalize(); destroy(); }
/** * 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; }
if (repeating != null && repeating._finder != null) { f = repeating._finder; f.setScreenImage(simg); f.setRepeating(); f.findAllRepeat(); } else { f = new Finder(simg, this); Image img = null; if (ptn instanceof String) { img = Image.create((String) ptn); if (img.isValid()) { f.findAll(img); } else if (img.isText()) { findingText = true; if (TextRecognizer.getInstance() != null) { log(lvl, "doFindAll: Switching to TextSearch"); f.findAllText((String) ptn); if (((Pattern) ptn).isValid()) { img = ((Pattern) ptn).getImage(); f.findAll((Pattern) ptn); f.findAll((Image) ptn); if (f.hasNext()) { return f;
simg = getScreen().capture(this); f = repeating._finder; f.setScreenImage(simg); f.setRepeating(); if (Settings.FindProfiling) { Debug.logp("[FindProfiling] Region.doFind repeat: %d msec", f.findRepeat(); } else { s = getScreen(); lastSearchTime = (new Date()).getTime(); f = checkLastSeenAndCreateFinder(img, findTimeout, null); if (!f.hasNext()) { runFinder(f, img); log(lvl, "doFind: Switching to TextSearch"); if (TextRecognizer.getInstance() != null) { f = new Finder(getScreen().capture(x, y, w, h), this); lastSearchTime = (new Date()).getTime(); f.findText(someText); 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);
Image img = new Image(r.getScreen().capture(r).getImage()); 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(); String screenFind = "Screen.find(imagefile)"; try {
if (img.isValid()) { finder = doCheckLastSeenAndCreateFinder(base, img, 0.0, null); if (!finder.hasNext()) { runFinder(finder, img); if (TextRecognizer.getInstance() != null) { log(lvl, "findInImage: Switching to TextSearch"); finder = new Finder(getScreen().capture(x, y, w, h), this); finder.findText((String) target); 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); img.setLastSeen(match.getRect(), match.getScore());
/** * do a findAll op with the given image or the given text in the Finder's image * (hasNext() and next() will reveal possible match results) * @param imageOrText iamge file name or text * @return null. if find setup not possible */ public String findAll(String imageOrText) { if (!valid) { log(-1, "not valid"); return null; } Image img = Image.create(imageOrText); _image = img; if (img.isText()) { return findAllText(imageOrText); } if (img.isValid()) { return findAll(img); } return null; }
/** * 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; } }
/** * * @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; } }
Region r = Region.create(img.getLastSeen()); if (this.contains(r)) { Finder f = new Finder(base.getSub(r.getRect()), r); if (Debug.shouldHighlight()) { if (this.scr.getW() > w + 10 && this.scr.getH() > h + 10) { f.find(new Pattern(img).similar(score)); } else { f.find(new Pattern(ptn).similar(score)); if (f.hasNext()) { log(lvl, "checkLastSeen: still there"); return f; return f; } else { return new Finder(base, this);
/** * 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; }
public Match getMatch() { if (_finder != null) { _finder.destroy(); } return (_match == null) ? _match : new Match(_match); }
if (observedRegion.contains(r)) { lastSearchTime = (new Date()).getTime(); 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()); ((ImageFinder) finder).setIsMultiFinder(); } else { finder = new Finder(simg, observedRegion); finder.find(img); if (finder.hasNext()) { match = finder.next(); match.setTimes(0, now - lastSearchTime); if (match.getScore() >= getSimiliarity(ptn)) {