@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); } }
/** * 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); } }