Menu

FaceRecognitionEngine and Local Binary Patterns Histogram

Q3Varnam
2014-07-10
2015-09-08
  • Q3Varnam

    Q3Varnam - 2014-07-10

    I am not sure whether there is a ready made option to use LBPH in the FaceRecognitionEngine.

    Is there any example available on how to use the FaceRecognitionEngine class?

     
  • Q3Varnam

    Q3Varnam - 2014-07-14

    Based on your suggestion I did something like this

    ~~~~~~

    static int i = 0;
    
    public static void main(String args[])
    {
    
        VideoCapture video;
        try
        {
            video = new VideoCapture(320, 240);
            video.setFPS(4.0);
            VideoDisplay<MBFImage> display = VideoDisplay
                    .createVideoDisplay(video);
            final HaarCascadeDetector fd = new HaarCascadeDetector(
                    BuiltInCascade.frontalface_default.classFile(), 120);
            float threshold = Float.NaN;
            int K = 1;
            FloatFVComparison comparison = FloatFVComparison.EUCLIDEAN;
            FacialFeatureComparator<LocalLBPHistogram> comparator = new FaceFVComparator<LocalLBPHistogram, FloatFV>(
                    comparison);
            final LocalLBPHistogram.Extractor<DetectedFace> extractor = new LocalLBPHistogram.Extractor<DetectedFace>();
            KNNAnnotator<DetectedFace, String, LocalLBPHistogram> knn = KNNAnnotator
                    .create(extractor, comparator, K, threshold);
            AnnotatorFaceRecogniser<DetectedFace, String> recogniser = AnnotatorFaceRecogniser
                    .create(knn);
            final FaceRecognitionEngine<DetectedFace, String> engine = FaceRecognitionEngine
                    .create(fd, recogniser);
    
            fd.setMaxSize(300);
    
            display.addVideoListener(new VideoDisplayListener<MBFImage>() {
                public void beforeUpdate(MBFImage frame)
                {
    
                    List<DetectedFace> faces = fd.detectFaces(Transforms
                            .calculateIntensity(frame));
    
                    for (DetectedFace face : faces)
                    {
                        if (i < 10)
                        {
                            engine.train(face, "krishna_" + i);
    
                            i++;
                        } else
                        {
                            List<IndependentPair<DetectedFace, List<ScoredAnnotation<String>>>> data = engine
                                    .recognise(face.getFacePatch());
                            System.out.println(data.size());
                        }
                        frame.drawShape(face.getBounds(), RGBColour.ORANGE);
    
                    }
                    try
                    {
                        Thread.sleep(30);
                    } catch (InterruptedException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    

    ~~~~~~~~~~~

    The recognise method is returning zero sized list.

    Could you suggest what I have done incorrectly?

     
    • Jonathon Hare

      Jonathon Hare - 2014-07-15

      I think the problem is probably your threshold being set to NaN. If you don't want to use the threshold, just use:

      KNNAnnotator<DetectedFace, String, LocalLBPHistogram> knn = 
          KNNAnnotator.create(extractor, comparator, K);
      
       

      Last edit: Jonathon Hare 2014-07-15
  • Q3Varnam

    Q3Varnam - 2014-07-15

    With reference to my earlier query, I managed to get it working with the LBPH Constructor as follows

             final FaceRecognitionEngine<DetectedFace, String> engine = new LBPHistogramBaseOptions() {
                    int K = 1;
                    FloatFVComparison comparison = FloatFVComparison.EUCLIDEAN;
                    float threshold = Float.NaN;
    
                    @Override
                    public FaceRecognitionEngine<DetectedFace, String> createRecognitionEngine()
                    {
                        if (threshold == Float.NaN)
                            threshold = comparison.isDistance() ? Float.MAX_VALUE
                                    : -Float.MAX_VALUE;
                        final LocalLBPHistogram.Extractor<DetectedFace> extractor = new LocalLBPHistogram.Extractor<DetectedFace>(
                                new IdentityAligner<DetectedFace>(), blocksX, blocksY, samples,
                                radius);
                        final FacialFeatureComparator<LocalLBPHistogram> comparator = new FaceFVComparator<LocalLBPHistogram, FloatFV>(
                                comparison);
                        final KNNAnnotator<DetectedFace, String, LocalLBPHistogram> knn = KNNAnnotator
                                .create(extractor, comparator, K, threshold);
                        final AnnotatorFaceRecogniser<DetectedFace, String> recogniser = AnnotatorFaceRecogniser
                                .create(knn);
                        return FaceRecognitionEngine.create(
                                fd, recogniser);
                    }
                }.createRecognitionEngine();
    

    This is resolved

     

    Last edit: Q3Varnam 2014-07-15

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.