org.sikuli.script.Match Java Examples
The following examples show how to use
org.sikuli.script.Match.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PatternPaneScreenshot.java From SikuliX1 with MIT License | 6 votes |
void filterMatches(double similarity, int numMatches) { int count = 0; if (_fullMatches != null && numMatches >= 0) { _showMatches = new ArrayList<Match>(); if (numMatches == 0) { return; } synchronized(_fullMatches) { for (Match m : _fullMatches) { if (m.score() >= similarity) { _showMatches.add(m); if (++count >= numMatches) { break; } } } } // _lblMatchCount.setText(Integer.toString(count)); Debug.log(4, "filterMatches(%.2f,%d): %d", similarity, numMatches, count); } }
Example #2
Source File: Tracker.java From SikuliX1 with MIT License | 6 votes |
boolean isPatternStillThereInTheSameLocation(){ try { sleep(1000); } catch (InterruptedException e) { } Region center = new Region(match); //<editor-fold defaultstate="collapsed" desc="TODO Pattern with BufferedImage"> /* center.x += center.w/4-2; * center.y += center.h/4-2; * center.w = center.w/2+4; * center.h = center.h/2+4; */ //</editor-fold> Match m = center.exists(centerPattern,0); if (m == null) Debug.log("[Tracker] Pattern is not seen in the same location."); return m != null; // Debug.log("[Tracker] Pattern is still in the same location" + m); }
Example #3
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Test public void test100_ImageFind() { testIntro(); Image shot = new Image(testBase); Match match = null; try { match = shot.find(testName); } catch (FindFailed findFailed) { } testOutro("%s in %s is %s", testName, shot, match); Assert.assertNotNull(testName + " not found", match); }
Example #4
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 5 votes |
protected Match newMatch(Match match) { if (match == null) return null; try { return new AndroidRegion(match, getScreen()); // TODO: target offset should be kept, but Match.setTargetOffset() is only accessible in the same package. } catch (AWTException e) { throw new RuntimeException(e); } }
Example #5
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 5 votes |
@Override public <PSC> Iterator<Match> findAllNow(PSC target) throws FindFailed { Iterator<Match> all = super.findAllNow(getAlternativePS(target)); ArrayList<Match> wrappers = new ArrayList<Match>(); while (all.hasNext()) wrappers.add(newMatch(all.next())); return wrappers.iterator(); }
Example #6
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 5 votes |
@Override public <PSC> Iterator<Match> findAll(PSC target) throws FindFailed { Iterator<Match> all = super.findAll(getAlternativePS(target)); ArrayList<Match> wrappers = new ArrayList<Match>(); while (all.hasNext()) wrappers.add(newMatch(all.next())); return wrappers.iterator(); }
Example #7
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Test public void test120_ImageFindChanges() { Point topLeft = null; if (showImage) { JFrame jFrame = testIntro(testBase); topLeft = jFrame.getLocationOnScreen(); } else { testIntro(); } Image original = new Image(testBase); Image changed = new Image(testChanged); List<Match> changes = original.findChanges(changed); long time = -1; if (changes.size() > 0) { time = changes.get(0).getTime(); } for (Match change : changes) { if (showImage) { change.reLocate(topLeft); change.highlight(); } } if (showImage) { Highlight.closeAll(3); } testOutro("%s%s == %s changes %d (%d)", "", original, changed, changes.size(), time); Assert.assertTrue("Not all changes!", changes.size() == 6); }
Example #8
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Ignore public void test110_ImageFindTrans() { testIntro(); Image shot = new Image(testBase); Match match = null; try { match = shot.find(testNameTrans); } catch (FindFailed findFailed) { } testOutro("%s in %s is %s", testName, shot, match); }
Example #9
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Test public void test092_ImageFindResizeDown() { testIntro(); Image shot = new Image(testBase); Assert.assertTrue("", shot.isValid()); Match match = null; Settings.AlwaysResize = 0.5; try { match = shot.find(testNameX2); } catch (FindFailed findFailed) { } Image.resetCache(); testOutro("%s in %s is %s", testName, shot, match); Assert.assertNotNull(testNameX2 + " not found", match); }
Example #10
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Test public void test091_ImageFindResizeOff() { testIntro(); Image shot = new Image(testBase); Assert.assertTrue("", shot.isValid()); Match match = null; Settings.AlwaysResize = 1; try { match = shot.find(testName); } catch (FindFailed findFailed) { } testOutro("%s in %s is %s", testName, shot, match); Assert.assertNotNull(testName + " not found", match); }
Example #11
Source File: ElementImageTest.java From SikuliX1 with MIT License | 5 votes |
@Test public void test090_ImageFindResizeUp() { testIntro(); Image shot = new Image(testBaseX2); Assert.assertTrue("", shot.isValid()); Match match = null; Settings.AlwaysResize = 2; try { match = shot.find(testName); } catch (FindFailed findFailed) { } // Image.resetCache(); testOutro("%s in %s is %s", testName, shot, match); Assert.assertNotNull(testName + " not found in " + testBaseX2, match); }
Example #12
Source File: PatternPaneScreenshot.java From SikuliX1 with MIT License | 5 votes |
void paintMatches(Graphics2D g2d) { for (Match m : _showMatches) { int x = (int) (m.x * _scale); int y = (int) (m.y * _scale); int w = (int) (m.w * _scale); int h = (int) (m.h * _scale); Color c = PatternSimilaritySlider.getScoreColor(m.score()); g2d.setColor(c); g2d.fillRect(x, y, w, h); g2d.drawRect(x, y, w - 1, h - 1); } }
Example #13
Source File: PatternPaneScreenshot.java From SikuliX1 with MIT License | 5 votes |
public void setParameters(final String patFilename, final boolean exact, final double similarity, final int numMatches) { if (!_runFind) { _showMatches = null; _fullMatches.clear(); repaint(); _runFind = true; patternFileName = patFilename; new Thread(() -> { try { Finder f = new Finder(_simg); f.findAll(new Pattern(patFilename).similar(0.00001)); int count = 0; while (f.hasNext()) { if (++count > MAX_NUM_MATCHING) { break; } Match m = f.next(); Debug.log(4, me + "f.next(%d): " + m.toString(), count); _fullMatches.add(m); } EventQueue.invokeLater(() -> { setParameters(exact, similarity, numMatches); }); } catch (Exception e) { Debug.error(me + "Problems searching image in ScreenUnion\n%s", e.getMessage()); } }).start(); } else { setParameters(exact, similarity, numMatches); } }
Example #14
Source File: PatternPaneScreenshot.java From SikuliX1 with MIT License | 4 votes |
@Override public int compare(Match o1, Match o2) { return -1 * o1.compareTo(o2); }
Example #15
Source File: Tracker.java From SikuliX1 with MIT License | 4 votes |
@Override public void run(){ running = true; initialFound = true; match = null; // Looking for the target for the first time Debug.log("[Tracker] Looking for the target for the first time"); while (running && (match == null)){ match = screen.exists(pattern,0.5); } // this means the tracker has been stopped before the pattern is found if (match == null) { return; } Debug.log("[Tracker] Pattern is found for the first time"); //<editor-fold defaultstate="collapsed" desc="TODO not used currently"> // if (true){ // Rectangle bounds = match.getRect(); // anchor.found(bounds); // }else{ // // animate the initial movement to the anchor position // // // uncomment this for popup demo // anchor.moveTo(new Point(match.x, match.y), new AnimationListener(){ // public void animationCompleted(){ // anchor.anchored(); // if (listener != null){ // listener.patternAnchored(); // } // } // }); // } // //</editor-fold> Rectangle bounds = match.getRect(); anchor.found(bounds); while (running){ if (match != null && isPatternStillThereInTheSameLocation()){ //Debug.log("[Tracker] Pattern is seen in the same location."); continue; } // try for at least 1.0 sec. to have a better chance of finding the // new position of the pattern. // the first attempt often fails because the target is only a few // pixels away when the screen capture is made and it is still // due to occlusion by foreground annotations // however, it would mean it takes at least 1.0 sec to realize // the pattern has disappeared and the referencing annotations should // be hidden Match newMatch = screen.exists(pattern,1.0); if (newMatch == null){ Debug.log("[Tracker] Pattern is not found on the screen"); //anchor.setOpacity(0.0f); //not_found_counter += 1; //if (not_found_counter > 2){ anchor.addFadeoutAnimation(); anchor.startAnimation(); // not_found_counter = 0; //} }else { Debug.log("[Tracker] Pattern is found in a new location: " + newMatch); // make it visible anchor.addFadeinAnimation(); anchor.startAnimation(); // anchor.setVisible(true); // // if the match is in a different location // if (match.x != newMatch.x || match.y != newMatch.y){ // for (int i=0; i < components.size(); ++i){ // comp = components.get(i); //Point offset = offsets.get(0); // int dest_x = newMatch.x + offset.x; // int dest_y = newMatch.y + offset.y; int dest_x = newMatch.x + newMatch.w/2; int dest_y = newMatch.y + newMatch.h/2; // comp.setEmphasisAnimation(comp.createMoveAnimator(dest_x, dest_y)); //comp.startAnimation(); Debug.log("[Tracker] Pattern is moving to: (" + dest_x + "," + dest_y + ")"); anchor.moveTo(new Point(dest_x, dest_y)); } match = newMatch; } // if (!initialFound){ // Debug.log("[Tracker] Pattern has disappeared after initial find"); // // // // for (Visual comp : components){ // comp.setVisible(false); // } // guide.repaint(); // } }
Example #16
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 4 votes |
public AndroidRegion(Match match, IScreen screen) throws AWTException { super(match.x, match.y, match.w, match.h, match.getScore(), screen); _robot = (AndroidRobot) screen.getRobot(); _autoWaitTimeout = AUTO_WAIT_TIMEOUT; }
Example #17
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 4 votes |
@Override public <PSC> Match exists(PSC target, double timeout) { return newMatch(super.exists(getAlternativePS(target), timeout)); }
Example #18
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 4 votes |
@Override public <PSC> Match find(PSC target) throws FindFailed { return newMatch(super.find(getAlternativePS(target))); }
Example #19
Source File: FindAttributes.java From SikuliX1 with MIT License | 4 votes |
public Match getMatchLastSeen() { return Element.getMatchLastSeen(target); }
Example #20
Source File: AndroidRegion.java From sikuli-monkey with MIT License | 4 votes |
@Override public <PSC> Match wait(PSC target, double timeout) throws FindFailed { return newMatch(super.wait(getAlternativePS(target), timeout)); }