String processInternal(FImage img, String separator, int... pattern) throws Exception { final List<NumberOccurance> occurances = new ArrayList<NumberOccurance>(); int num = 0; for (final int i : pattern) num += i; for (int i = 0; i < 10; i++) { templates[i].analyseImage(img); final FValuePixel[] resp = templates[i].getBestResponses(num); for (final FValuePixel pt : resp) { if (pt.value > 0.95) { occurances.add(new NumberOccurance(pt.x, i)); } } } if (occurances.size() != num) throw new Exception(); Collections.sort(occurances); String result = ""; int i = 0, j = 0; for (final NumberOccurance no : occurances) { if (pattern[i] == j) { j = 0; i++; result += separator; } result += no.value; j++; } return result; }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @return the best responses found */ public FValuePixel[] getBestResponses(int numResponses) { Comparator<FValuePixel> comparator = mode.scoresAscending() ? FValuePixel.ReverseValueComparator.INSTANCE : FValuePixel.ValueComparator.INSTANCE; return getBestResponses(numResponses, responseMap, getXOffset(), getYOffset(), comparator); }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @return the best responses found */ public FValuePixel[] getBestResponses(int numResponses) { Comparator<FValuePixel> comparator = mode.scoresAscending() ? FValuePixel.ReverseValueComparator.INSTANCE : FValuePixel.ValueComparator.INSTANCE; return getBestResponses(numResponses, responseMap, getXOffset(), getYOffset(), comparator); }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @return the best responses found */ public FValuePixel[] getBestResponses(int numResponses) { Comparator<FValuePixel> comparator = mode.scoresAscending() ? FValuePixel.ReverseValueComparator.INSTANCE : FValuePixel.ValueComparator.INSTANCE; return TemplateMatcher.getBestResponses(numResponses, responseMap, getXOffset(), getYOffset(), comparator); }
/** * Get the top-N "best" responses found by the template matcher. * * @param numResponses The number of responses * @return the best responses found */ public FValuePixel[] getBestResponses(int numResponses) { Comparator<FValuePixel> comparator = mode.scoresAscending() ? FValuePixel.ReverseValueComparator.INSTANCE : FValuePixel.ValueComparator.INSTANCE; return TemplateMatcher.getBestResponses(numResponses, responseMap, getXOffset(), getYOffset(), comparator); }
@Override public ObjectFloatPair<Point2d> updatePosition(FImage image, Point2d initial, PointList pointList) { Rectangle roi = getROI((int)initial.getX(), (int)initial.getY(), searchSize, searchSize); if (matcher == null) matcher = new TemplateMatcher(average, Mode.NORM_SUM_SQUARED_DIFFERENCE); matcher.setSearchBounds(roi); image.analyseWith(matcher); FValuePixel p = matcher.getBestResponses(1)[0]; return new ObjectFloatPair<Point2d>(p, 0); } }
@Override public ObjectFloatPair<Point2d> updatePosition(FImage image, Point2d initial, PointList pointList) { Rectangle roi = getROI((int)initial.getX(), (int)initial.getY(), searchSize, searchSize); if (matcher == null) matcher = new TemplateMatcher(average, Mode.NORM_SUM_SQUARED_DIFFERENCE); matcher.setSearchBounds(roi); image.analyseWith(matcher); FValuePixel p = matcher.getBestResponses(1)[0]; return new ObjectFloatPair<Point2d>(p, 0); } }
final FValuePixel[] responses = matcher.getBestResponses(1); final FValuePixel firstBest = responses[0];
final FValuePixel[] responses = matcher.getBestResponses(1); final FValuePixel firstBest = responses[0];
/** * Testing * @param args * @throws IOException */ public static void main(String[] args) throws IOException { FImage image = ImageUtilities.readF(new File("/Users/jsh2/Desktop/image.png")); FImage template = image.extractROI(100, 100, 100, 100); image.fill(0f); image.drawImage(template, 100, 100); TemplateMatcher matcher = new TemplateMatcher(template, Mode.CORRELATION); matcher.setSearchBounds(new Rectangle(100,100,200,200)); image.analyseWith(matcher); DisplayUtilities.display(matcher.responseMap.normalise()); MBFImage cimg = image.toRGB(); for (FValuePixel p : matcher.getBestResponses(10)) { System.out.println(p); cimg.drawPoint(p, RGBColour.RED, 1); } cimg.drawShape(matcher.getSearchBounds(), RGBColour.BLUE); cimg.drawShape(new Rectangle(100,100,100,100), RGBColour.GREEN); DisplayUtilities.display(cimg); } }
/** * Testing * @param args * @throws IOException */ public static void main(String[] args) throws IOException { FImage image = ImageUtilities.readF(new File("/Users/jsh2/Desktop/image.png")); FImage template = image.extractROI(100, 100, 100, 100); image.fill(0f); image.drawImage(template, 100, 100); TemplateMatcher matcher = new TemplateMatcher(template, Mode.CORRELATION); matcher.setSearchBounds(new Rectangle(100,100,200,200)); image.analyseWith(matcher); DisplayUtilities.display(matcher.responseMap.normalise()); MBFImage cimg = image.toRGB(); for (FValuePixel p : matcher.getBestResponses(10)) { System.out.println(p); cimg.drawPoint(p, RGBColour.RED, 1); } cimg.drawShape(matcher.getSearchBounds(), RGBColour.BLUE); cimg.drawShape(new Rectangle(100,100,100,100), RGBColour.GREEN); DisplayUtilities.display(cimg); } }