1

I was attempting to use the DoGSIFTFeatureComparator with the FaceSimilarityEngine. Here's my code:

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.FImage;
import org.openimaj.image.MBFImage;
import org.openimaj.image.colour.RGBColour;
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.processing.face.detection.HaarCascadeDetector;
import org.openimaj.image.processing.face.detection.DetectedFace;
import org.openimaj.image.processing.face.feature.DoGSIFTFeature;
import org.openimaj.image.processing.face.feature.comparison.DoGSIFTFeatureComparator;
import org.openimaj.image.processing.face.similarity.FaceSimilarityEngine;
import org.openimaj.math.geometry.shape.Rectangle;

public class FaceSimilarity {
    public static void main(String[] args) throws IOException {
        final File iFile1 = new File("/Path/to/first/image.jpg");
        final File iFile2 = new File("/Path/to/second/image.jpg");
        final MBFImage mbImg1 = ImageUtilities.readMBF(iFile1);
        final MBFImage mbImg2 = ImageUtilities.readMBF(iFile2);
        final FImage image1 = mbImg1.flatten();
        final FImage image2 = mbImg2.flatten();

        final HaarCascadeDetector detector = HaarCascadeDetector.BuiltInCascade.frontalface_default.load();

        final DoGSIFTFeature.Extractor extractor = new DoGSIFTFeature.Extractor();

        final DoGSIFTFeatureComparator comparator = new DoGSIFTFeatureComparator();

        final FaceSimilarityEngine<DetectedFace, DoGSIFTFeature, FImage> engine = new FaceSimilarityEngine<>(detector, extractor, comparator);

        engine.setQuery(image1, "image1");
        engine.setTest(image2, "image2");

        engine.performTest();

        // rest of the code
    }
}

This same code works when the FaceSimilarityEngine uses the FKEFaceDetector, the FacePathFeature Extractor, and the FaceFVComparator instead, but with the code above results in the following error message:

Exception in thread "main" java.lang.NullPointerException
at org.openimaj.math.geometry.transforms.residuals.TransformedSITR2d.computeResidual(TransformedSITR2d.java:76)
at org.openimaj.math.model.fit.SimpleModelFitting.fitData(SimpleModelFitting.java:117)
at org.openimaj.feature.local.matcher.consistent.ConsistentLocalFeatureMatcher2d.findMatches(ConsistentLocalFeatureMatcher2d.java:138)
at org.openimaj.image.processing.face.feature.comparison.DoGSIFTFeatureComparator.compare(DoGSIFTFeatureComparator.java:152)
at org.openimaj.image.processing.face.feature.comparison.DoGSIFTFeatureComparator.compare(DoGSIFTFeatureComparator.java:68)
at org.openimaj.image.processing.face.similarity.FaceSimilarityEngine.performTest(FaceSimilarityEngine.java:224)
at // line of code with engine.performTest();

I though that maybe the DoGSIFTFeatureComparator just didn't work with the FaceSimilarityEngine, so I created this class instead (same imports except for the FaceSimilarityEngine):

public class DogSiftCompare {
    public static void main(String[] args) throws IOException {
        // created FImages the same way as previous code

        final HaarCascadeDetector detector = HaarCascadeDetector.BuiltInCascade.frontalface_default.load();
        final DoGSIFTFeature.Extractor extractor = new DoGSIFTFeature.Extractor();
        final DoGSIFTFeatureComparator comparator = new DoGSIFTFeatureComparator();

        List<DetectedFace> faces = detector.detectFaces(image1);
        List<DetectedFace> faces2 = detector.detectFaces(image2);
        List<DoGSIFTFeature> features1 = new ArrayList<>();
        List<DoGSIFTFeature> features2 = new ArrayList<>();

        if (!faces.isEmpty()) {
            for (DetectedFace face : faces) {
                DoGSIFTFeature feature = extractor.extractFeature(face);
                features1.add(feature);
            }
        }
        if (!faces2.isEmpty()) {
            for (DetectedFace face : faces2) {
                DoGSIFTFeature feature = extractor.extractFeature(face);
                features2.add(feature);
            }
        }

        DetectedFace face1 = null;
        DetectedFace face2 = null;

        double bestScore = Double.MAX_VALUE;

        if (!features1.isEmpty() && !features2.isEmpty()) {
            for (int i = 0; i < features1.size(); i++) {
                for (int j = 0; j < features2.size(); j++) {
                    double score = comparator.compare(features1.get(i), features2.get(j));
                    if (score < bestScore) {
                        bestScore = score;
                        face1 = faces.get(i);
                        face2 = faces2.get(j);
                    }
                }
            }
        }
        // rest of code ...
    }
}

Running this code, however, produces the same error as the previous code did:

Exception in thread "main" java.lang.NullPointerException
at org.openimaj.math.geometry.transforms.residuals.TransformedSITR2d.computeResidual(TransformedSITR2d.java:76)
at org.openimaj.math.model.fit.SimpleModelFitting.fitData(SimpleModelFitting.java:117)
at org.openimaj.feature.local.matcher.consistent.ConsistentLocalFeatureMatcher2d.findMatches(ConsistentLocalFeatureMatcher2d.java:138)
at org.openimaj.image.processing.face.feature.comparison.DoGSIFTFeatureComparator.compare(DoGSIFTFeatureComparator.java:152)
at //line of code with double score = comparator.compare(features1.get(i), features2.get(j));

So I guess I'm asking if I'm missing a key variable for this particular feature comparator, or is this a problem with the DoGSIFTFeatureComparator itself?

  • I think this is a bug introduced when I refactored the model-fitting subsystem last summer (specifically inside the `SimpleModelFitting` class, which was not setting the model in the `TransformedSITR2d` before calling `computeResidual`). Should now be fixed: https://github.com/openimaj/openimaj/commit/3558ce03c3da7e10fb4ada81ac58fe502912b4a4 – Jon Jul 14 '15 at 08:49

0 Answers0