@Override public FaceAligner<KEDetectedFace> getAligner() { return new AffineAligner(); }
/** * Estimate the affine transform required to warp a set of facial keypoints * to their canonical coordinates. * <p> * Affine transform is from a flat, vertically oriented (canonical) face to * located face space. You'll need to invert this if you want to use it to * extract the face from the image. * * @param face * the face * @return the affine transform matrix */ public static Matrix estimateAffineTransform(KEDetectedFace face) { return estimateAffineTransform(face.getKeypoints()); }
/** * Default Constructor with the default mask (80x80) and default border * percentage (0.225). */ public AffineAligner() { this(loadDefaultMask()); };
@Override public FaceAligner<KEDetectedFace> getAligner() { return new AffineAligner(); }
protected void extractFeatures(KEDetectedFace face) { final Matrix T0 = AffineAligner.estimateAffineTransform(face); final Matrix T = T0.copy(); final FImage J = FKEFaceDetector.pyramidResize(face.getFacePatch(), T);
final AffineAligner aligner = new AffineAligner(125, 160, 0.1f);
@Override public FImage align(KEDetectedFace descriptor) { final int facePatchSize = Math.max(facePatchWidth, facePatchHeight); final double size = facePatchSize + 2.0 * facePatchSize * facePatchBorderPercentage; final double sc = CANONICAL_SIZE / size; // do the scaling to everything but the translation!!! final Matrix T = estimateAffineTransform(descriptor); T.set(0, 0, T.get(0, 0) * sc); T.set(1, 1, T.get(1, 1) * sc); T.set(0, 1, T.get(0, 1) * sc); T.set(1, 0, T.get(1, 0) * sc); final FImage J = FKEFaceDetector.pyramidResize(descriptor.getFacePatch(), T); final FImage bigPatch = FKEFaceDetector.extractPatch(J, T, (int) size, (int) (facePatchSize * facePatchBorderPercentage)); return bigPatch.extractCenter(facePatchWidth, facePatchHeight).extractROI(0, 0, facePatchWidth, facePatchHeight) .multiplyInplace(mask); }
final AffineAligner aligner = new AffineAligner(125, 160, 0.1f);
/** * Detect faces in the image and render mustaches. * * @param image * @return image with rendered mustaches */ public MBFImage addMustaches(MBFImage image) { MBFImage cimg; if (image.getWidth() > image.getHeight() && image.getWidth() > 640) { cimg = image.process(new ResizeProcessor(640, 480)); } else if (image.getHeight() > image.getWidth() && image.getHeight() > 640) { cimg = image.process(new ResizeProcessor(480, 640)); } else { cimg = image.clone(); } final FImage img = Transforms.calculateIntensityNTSC(cimg); final List<KEDetectedFace> faces = detector.detectFaces(img); final MBFImageRenderer renderer = cimg.createRenderer(); for (final KEDetectedFace face : faces) { final Matrix tf = AffineAligner.estimateAffineTransform(face); final Shape bounds = face.getBounds(); final MBFImage m = mustache.transform(tf.times(TransformUtilities.scaleMatrix(1f / 4f, 1f / 4f))); renderer.drawImage(m, (int) bounds.minX(), (int) bounds.minY()); } return cimg; }
@Override public FaceSimilarityEngine<?, ?, FImage> strategy() { // FacialFeatureFactory<LocalLBPHistogram, KEDetectedFace> factory = // new LocalLBPHistogram.Factory<KEDetectedFace>(new // AffineAligner(), 20, 20, 8, 1); // FacialFeatureFactory<LocalLBPHistogram, KEDetectedFace> factory = // new LocalLBPHistogram.Factory<KEDetectedFace>(new // AffineAligner(), 7, 7, 16, 4); final FacialFeatureExtractor<LocalLBPHistogram, KEDetectedFace> factory = new LocalLBPHistogram.Extractor<KEDetectedFace>( new AffineAligner(), 7, 7, 8, 2); final FacialFeatureComparator<LocalLBPHistogram> comparator = new FaceFVComparator<LocalLBPHistogram, FloatFV>( FloatFVComparison.CHI_SQUARE); final FKEFaceDetector detector = new FKEFaceDetector(); return FaceSimilarityEngine.create(detector, factory, comparator); }
/** * Detect faces in the image and render mustaches. * * @param image * @return image with rendered mustaches */ public MBFImage addMustaches(MBFImage image) { MBFImage cimg; if (image.getWidth() > image.getHeight() && image.getWidth() > 640) { cimg = image.process(new ResizeProcessor(640, 480)); } else if (image.getHeight() > image.getWidth() && image.getHeight() > 640) { cimg = image.process(new ResizeProcessor(480, 640)); } else { cimg = image.clone(); } final FImage img = Transforms.calculateIntensityNTSC(cimg); final List<KEDetectedFace> faces = detector.detectFaces(img); final MBFImageRenderer renderer = cimg.createRenderer(); for (final KEDetectedFace face : faces) { final Matrix tf = AffineAligner.estimateAffineTransform(face); final Shape bounds = face.getBounds(); final MBFImage m = mustache.transform(tf.times(TransformUtilities.scaleMatrix(1f / 4f, 1f / 4f))); renderer.drawImage(m, (int) bounds.minX(), (int) bounds.minY()); } return cimg; }
@Override public FaceSimilarityEngine<?, ?, FImage> strategy() { // FacialFeatureFactory<LocalLBPHistogram, KEDetectedFace> factory = // new LocalLBPHistogram.Factory<KEDetectedFace>(new // AffineAligner(), 20, 20, 8, 1); // FacialFeatureFactory<LocalLBPHistogram, KEDetectedFace> factory = // new LocalLBPHistogram.Factory<KEDetectedFace>(new // AffineAligner(), 7, 7, 16, 4); final FacialFeatureExtractor<LocalLBPHistogram, KEDetectedFace> factory = new LocalLBPHistogram.Extractor<KEDetectedFace>( new AffineAligner(), 7, 7, 8, 2); final FacialFeatureComparator<LocalLBPHistogram> comparator = new FaceFVComparator<LocalLBPHistogram, FloatFV>( FloatFVComparison.CHI_SQUARE); final FKEFaceDetector detector = new FKEFaceDetector(); return FaceSimilarityEngine.create(detector, factory, comparator); }
@Override public FaceSimilarityEngine<?, ?, FImage> strategy() { final FacialFeatureComparator<LtpDtFeature> comparator = new ReversedLtpDtFeatureComparator(); final FKEFaceDetector detector = new FKEFaceDetector(); final FacialFeatureExtractor<LtpDtFeature, KEDetectedFace> factory = new LtpDtFeature.Extractor<KEDetectedFace>( new AffineAligner(), new TruncatedWeighting() ); return FaceSimilarityEngine.create(detector, factory, comparator); }
@Override public FaceSimilarityEngine<?, ?, FImage> strategy() { final FacialFeatureComparator<LtpDtFeature> comparator = new ReversedLtpDtFeatureComparator(); final FKEFaceDetector detector = new FKEFaceDetector(); final FacialFeatureExtractor<LtpDtFeature, KEDetectedFace> factory = new LtpDtFeature.Extractor<KEDetectedFace>( new AffineAligner(), new TruncatedWeighting() ); return FaceSimilarityEngine.create(detector, factory, comparator); }
"/Volumes/Raid/face_databases/lfw/Aaron_Peirsol/Aaron_Peirsol_0002.jpg")); final FKEFaceDetector detector = new FKEFaceDetector(1.6f); final FaceAligner<KEDetectedFace> aligner = new AffineAligner(125, 160, 0.1f);
"/Volumes/Raid/face_databases/lfw/Aaron_Peirsol/Aaron_Peirsol_0002.jpg")); final FKEFaceDetector detector = new FKEFaceDetector(1.6f); final FaceAligner<KEDetectedFace> aligner = new AffineAligner(125, 160, 0.1f);