@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); } }
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; }
@Override public float computeCost(FImage image, Point2d point, PointList pointList) { FImage extracted = extractBlock(image, point, blockSize); if (matcher == null) matcher = new TemplateMatcher(average, Mode.NORM_SUM_SQUARED_DIFFERENCE); matcher.setSearchBounds(null); extracted.analyseWith(matcher); return matcher.getResponseMap().pixels[0][0]; }
/** * 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); }
/** * 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); } }
final TemplateMatcher matcher = new TemplateMatcher(current.frame, mode, searchRect); matcher.analyseImage(prev.frame); final FValuePixel[] responses = matcher.getBestResponses(1); final FValuePixel firstBest = responses[0];
/** * Construct the engine and load the templates. * * @throws IOException */ public SimpleOCR() throws IOException { for (int i = 0; i < 10; i++) { final FImage img = ImageUtilities.readF(SimpleOCR.class.getResourceAsStream(i + ".png")); templates[i] = new TemplateMatcher(img, TemplateMatcher.Mode.NORM_CORRELATION_COEFFICIENT); } }
matcher.analyseImage(I); FImage res = matcher.getResponseMap();
/** * 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); }
/** * 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); } }
final TemplateMatcher matcher = new TemplateMatcher(current.frame, mode, searchRect); matcher.analyseImage(prev.frame); final FValuePixel[] responses = matcher.getBestResponses(1); final FValuePixel firstBest = responses[0];
/** * @param t * @param a * @param b * @param W */ public Patch(int t, double a, double b, FImage W) { _t = t; _a = a; _b = b; _W = W; matcher = new TemplateMatcher(W.clone(), Mode.NORM_CORRELATION_COEFFICIENT); }
/** * 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); }
matcher.analyseImage(I); FImage res = matcher.getResponseMap();
/** * 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 float computeCost(FImage image, Point2d point, PointList pointList) { FImage extracted = extractBlock(image, point, blockSize); if (matcher == null) matcher = new TemplateMatcher(average, Mode.NORM_SUM_SQUARED_DIFFERENCE); matcher.setSearchBounds(null); extracted.analyseWith(matcher); return matcher.getResponseMap().pixels[0][0]; }
/** * @param t * @param a * @param b * @param W */ public Patch(int t, double a, double b, FImage W) { _t = t; _a = a; _b = b; _W = W; matcher = new TemplateMatcher(W.clone(), Mode.NORM_CORRELATION_COEFFICIENT); }
static Patch read(Scanner s, boolean readType) { if (readType) { int type = s.nextInt(); assert (type == IO.Types.PATCH.ordinal()); } Patch p = new Patch(); // s.nextInt(), s.nextDouble(), s.nextDouble(), // IO.ReadImg(s) ); p._t = s.nextInt(); p._a = s.nextDouble(); p._b = s.nextDouble(); p._W = IO.readImg(s); p.matcher = new TemplateMatcher(p._W.clone(), Mode.NORM_CORRELATION_COEFFICIENT); return p; }
static Patch read(Scanner s, boolean readType) { if (readType) { int type = s.nextInt(); assert (type == IO.Types.PATCH.ordinal()); } Patch p = new Patch(); // s.nextInt(), s.nextDouble(), s.nextDouble(), // IO.ReadImg(s) ); p._t = s.nextInt(); p._a = s.nextDouble(); p._b = s.nextDouble(); p._W = IO.readImg(s); p.matcher = new TemplateMatcher(p._W.clone(), Mode.NORM_CORRELATION_COEFFICIENT); return p; }