@Override public synchronized void afterUpdate(final VideoDisplay<MBFImage> display) { if (this.matcher != null && !this.videoFrame.isPaused()) { final MBFImage capImg = this.videoFrame.getVideo().getCurrentFrame(); final LocalFeatureList<Keypoint> kpl = this.engine.findFeatures(capImg); final MBFImageRenderer renderer = capImg.createRenderer(); renderer.drawPoints(kpl, RGBColour.MAGENTA, 3); MBFImage matches; if (this.matcher.findMatches(kpl)) { try { // Shape sh = // modelImage.getBounds().transform(((MatrixTransformProvider) // matcher.getModel()).getTransform().inverse()); // renderer.drawShape(sh, 3, RGBColour.BLUE); final Matrix boundsToPoly = ((MatrixTransformProvider) this.matcher.getModel()).getTransform().inverse(); this.renderMode.render(renderer, boundsToPoly, this.modelImage.getBounds()); } catch (final RuntimeException e) { } matches = MatchingUtilities.drawMatches( this.modelImage, capImg, this.matcher.getMatches(), RGBColour.RED); } else { matches = MatchingUtilities.drawMatches( this.modelImage, capImg, this.matcher.getMatches(), RGBColour.RED); } this.matchPanel.setPreferredSize(this.matchPanel.getSize()); this.matchFrame.setImage(ImageUtilities.createBufferedImageForDisplay(matches)); } }
@Override public void beforeUpdate(MBFImage frame) { FImage gimg = frame.flatten(); // bring to sigma = 1.0 gimg.processInplace(new FGaussianConvolve(1f)); for (int i = 0; i < 3; i++) { final int t = (int) Math.pow(2, i); final double sigma = Math.sqrt(t); final float sf = t; harris.setDetectionScale((float) sigma); harris.setImageBlurred(true); harris.findInterestPoints(gimg); final float iscale = harris.getIntegrationScale(); final float samplesize = 4 * iscale + 1; for (final InterestPointData ipd : harris.getInterestPoints((float) (1e-5))) { ipd.x *= sf; ipd.y *= sf; frame.drawShape(new Circle(ipd, sf * samplesize), RGBColour.RED); } gimg.processInplace(new FGaussianConvolve((float) Math.sqrt((Math.pow(2, i + 1) - t)))); gimg = ResizeProcessor.halfSize(gimg); } }
@Override public void beforeUpdate(MBFImage frame) { if (transform != null) { MBFImage bgCopy = mbfImage.clone(); MBFProjectionProcessor proj = new MBFProjectionProcessor(); proj.setMatrix(transform); proj.accumulate(frame); proj.performProjection(0, 0, bgCopy); panel.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(bgCopy, bimg)); } else panel.setImage(bimg = ImageUtilities.createBufferedImageForDisplay(frame, bimg)); }
/** * {@inheritDoc} * * @see org.openimaj.video.VideoDisplayListener#beforeUpdate(org.openimaj.image.Image) */ @Override public void beforeUpdate(MBFImage frame) { if (edgeDetect) frame.processInplace(new CannyEdgeDetector2()); if (faceDetect) { HaarCascadeDetector d = new HaarCascadeDetector(100); List<DetectedFace> faces = d.detectFaces(Transforms.calculateIntensityNTSC(frame)); for (DetectedFace face : faces) { Shape transBounds = face.getBounds(); MBFImageRenderer renderer = frame.createRenderer(); renderer.drawPolygon(transBounds.asPolygon(), RGBColour.RED); } } if (faceKPDetect) { System.out.println("HERE"); FKEFaceDetector fkp = new FKEFaceDetector(HaarCascadeDetector.BuiltInCascade.frontalface_alt.load()); List<KEDetectedFace> faces = fkp.detectFaces(Transforms.calculateIntensityNTSC(frame)); for (KEDetectedFace face : faces) { Shape transBounds = face.getBounds(); MBFImageRenderer renderer = frame.createRenderer(); renderer.drawPolygon(transBounds.asPolygon(), RGBColour.RED); for (FacialKeypoint kp : face.getKeypoints()) { Point2d pt = kp.position.clone(); pt.translate((float) transBounds.minX(), (float) transBounds.minY()); renderer.drawPoint(pt, RGBColour.GREEN, 3); } } } if (moustache) try { frame.internalAssign(new Mustache().addMustaches(frame)); } catch (IOException e) { e.printStackTrace(); } }
/** * 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); }
private void displayCurrentPatch( FImage unwarped, float unwarpedx, float unwarpedy, FImage warped, int warpedx, int warpedy, Matrix transform, float scale) { DisplayUtilities.createNamedWindow("warpunwarp", "Warped and Unwarped Image", true); logger.debug("Displaying patch"); float resizeScale = 5f; float warppedPatchScale = resizeScale; ResizeProcessor patchSizer = new ResizeProcessor(resizeScale); FImage warppedPatchGrey = warped.process(patchSizer); MBFImage warppedPatch = new MBFImage(warppedPatchGrey.clone(), warppedPatchGrey.clone(), warppedPatchGrey.clone()); float x = warpedx * warppedPatchScale; float y = warpedy * warppedPatchScale; float r = scale * warppedPatchScale; warppedPatch.createRenderer().drawShape(new Ellipse(x, y, r, r, 0), RGBColour.RED); warppedPatch.createRenderer().drawPoint(new Point2dImpl(x, y), RGBColour.RED, 3); FImage unwarppedPatchGrey = unwarped.clone(); MBFImage unwarppedPatch = new MBFImage( unwarppedPatchGrey.clone(), unwarppedPatchGrey.clone(), unwarppedPatchGrey.clone()); unwarppedPatch = unwarppedPatch.process(patchSizer); float unwarppedPatchScale = resizeScale; x = unwarpedx * unwarppedPatchScale; y = unwarpedy * unwarppedPatchScale; // Matrix sm = state.selected.secondMoments; // float scale = state.selected.scale * unwarppedPatchScale; // Ellipse e = EllipseUtilities.ellipseFromSecondMoments(x, y, sm, scale*2); Ellipse e = EllipseUtilities.fromTransformMatrix2x2(transform, x, y, scale * unwarppedPatchScale); unwarppedPatch.createRenderer().drawShape(e, RGBColour.BLUE); unwarppedPatch.createRenderer().drawPoint(new Point2dImpl(x, y), RGBColour.RED, 3); // give the patch a border (10px, black) warppedPatch = warppedPatch.padding(5, 5, RGBColour.BLACK); unwarppedPatch = unwarppedPatch.padding(5, 5, RGBColour.BLACK); MBFImage displayArea = warppedPatch.newInstance(warppedPatch.getWidth() * 2, warppedPatch.getHeight()); displayArea.createRenderer().drawImage(warppedPatch, 0, 0); displayArea.createRenderer().drawImage(unwarppedPatch, warppedPatch.getWidth(), 0); DisplayUtilities.displayName(displayArea, "warpunwarp"); logger.debug("Done"); }