static private List<TextMatch> findCandidateMatches(ScreenRegion screenRegion,
String word, double minScore, boolean firstMatchOnly) {
ScreenRegion snapshot = screenRegion.snapshot();
TextMap map = TextMap.createFrom(snapshot.capture());
explainer.step(map.getImage(), "text map");
List<TextMatch> ret = Lists.newArrayList();
for (WeightedFontModel fontModel : fontModels) {
logger.trace("test font model => " + fontModel);
BufferedImage img = TextImageGenerator.create(word,
fontModel.getFont(), fontModel.getSize(),
fontModel.getTracking());
ImageTarget t = new ImageTarget(img);
t.setMinScore(minScore);
List<ScreenRegion> matchedRegions = snapshot.findAll(t);
if (!matchedRegions.isEmpty()) {
logger.trace("top score = " + matchedRegions.get(0).getScore());
for (ScreenRegion matchedRegion : matchedRegions) {
Rectangle r = matchedRegion.getBounds();
Rectangle s = snapshot.getBounds();
int localx = r.x - s.x;
int localy = r.y - s.y;
if (map.computeTextScore(localx, localy, r.width, r.height) > 0) {
TextMatch m = new TextMatch(matchedRegion, fontModel);
ret.add(m);
fontModel.maxScore = Math.max(fontModel.maxScore,
matchedRegion.getScore());