/** * 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); } }
/** * @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); }
/** * @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); }
@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]; }
@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]; }
@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 TemplateMatcher matcher = new TemplateMatcher(current.frame, mode, searchRect); matcher.analyseImage(prev.frame); final FValuePixel[] responses = matcher.getBestResponses(1);
final TemplateMatcher matcher = new TemplateMatcher(current.frame, mode, searchRect); matcher.analyseImage(prev.frame); final FValuePixel[] responses = matcher.getBestResponses(1);
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; }
/** * 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); } }