@Override protected List<ScreenRegion> getUnorderedMatches(ScreenRegion screenRegion) { Rectangle screenRegionBounds = screenRegion.getBounds(); if (screenRegionBounds.width < targetImage.getWidth() || screenRegionBounds.height < targetImage.getHeight()) { // if screen region is smaller than the target, no target can be found // TODO: perhaps a more fault tolerant approach is to return a smaller target with a lower // score return Lists.newArrayList(); } List<TemplateMatcher.Result> matches; BufferedImage screenImage = screenRegion.capture(); List<Rectangle> rois = screenRegion.getROIs(); if (rois.isEmpty()) { matches = TemplateMatcher.findMatchesByGrayscaleAtOriginalResolution( screenImage, targetImage, getLimit(), getMinScore()); } else { matches = TemplateMatcher.findMatchesByGrayscaleAtOriginalResolutionWithROIs( screenImage, targetImage, getLimit(), getMinScore(), rois); } return convertToScreenRegions(screenRegion, matches); }
@Override protected List<ScreenRegion> getUnorderedMatches(ScreenRegion screenRegion) { BufferedImage exampleImage = getImage(); FourCornerModel buttonModel = FourCornerModel.learnFrom(exampleImage); List<RegionMatch> matches = VisualModelFinder.searchButton(buttonModel, screenRegion.capture()); List<RegionMatch> subList = matches.subList(0, Math.min(getLimit(), matches.size())); return convertToScreenRegions(screenRegion, subList); }
// TODO: this is not working yet public static void main(String[] args) throws IOException, InterruptedException { URL backgroundImage = Images.GoogleSearchPage; URL dragTargetImage = Images.OSXDockIcon; DragDropFrame imageFrame = new DragDropFrame(backgroundImage, dragTargetImage); imageFrame.autoClose(10000); ScreenRegion s = new DesktopScreenRegion(); Mouse mouse = new DesktopMouse(); URL imageURL = Images.OSXDockIcon; Target imageTarget = new ImageTarget(imageURL); ScreenRegion r = s.wait(imageTarget, 1000); mouse.drag(r.getCenter()); imageURL = Images.GoogleMicrophoneIcon; imageTarget = new ImageTarget(imageURL); r = s.wait(imageTarget, 1000); mouse.drop(r.getCenter()); ScreenLocation c = mouse.getLocation(); mouse.drag(c); mouse.drop(Relative.to(c).left(200).above(50).getScreenLocation()); }