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?
Anonymous
You seem to have CSS turned off. Please don't fill out this field.
There's currently no proper tutorial, but there is some code you could look at to get an idea here: https://sourceforge.net/p/openimaj/code/HEAD/tree/trunk/tools/FaceTools/src/main/java/org/openimaj/tools/faces/recognition/options/RecognitionStrategy.java (look for the LBPHistograms_KNN enumeration to see how a FaceRecognitionEngine can be pieced together from a face detector, face aligner, LBP feature extractor and KNN classifier.
LBPHistograms_KNN
FaceRecognitionEngine
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?
I think the problem is probably your threshold being set to NaN. If you don't want to use the threshold, just use:
NaN
KNNAnnotator<DetectedFace, String, LocalLBPHistogram> knn = KNNAnnotator.create(extractor, comparator, K);
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
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?
There's currently no proper tutorial, but there is some code you could look at to get an idea here: https://sourceforge.net/p/openimaj/code/HEAD/tree/trunk/tools/FaceTools/src/main/java/org/openimaj/tools/faces/recognition/options/RecognitionStrategy.java (look for the
LBPHistograms_KNN
enumeration to see how aFaceRecognitionEngine
can be pieced together from a face detector, face aligner, LBP feature extractor and KNN classifier.Based on your suggestion I did something like this
~~~~~~
~~~~~~~~~~~
The recognise method is returning zero sized list.
Could you suggest what I have done incorrectly?
I think the problem is probably your threshold being set to
NaN
. If you don't want to use the threshold, just use:Last edit: Jonathon Hare 2014-07-15
With reference to my earlier query, I managed to get it working with the LBPH Constructor as follows
This is resolved
Last edit: Q3Varnam 2014-07-15