Использование DoGSIFTFeatureComparator генерирует исключение NullPointerException
Я пытался использовать DoGSIFTFeatureComparator с FaceSdentifityEngine. Вот мой код:
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
}
}
Этот же код работает, когда FaceSdentifityEngine использует вместо этого FKEFaceDetector, FacePathFeature Extractor и FaceFVComparator, но с приведенным выше кодом приводит к следующему сообщению об ошибке:
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();
Я подумал, что, может быть, DoGSIFTFeatureComparator просто не работает с FaceSdentifityEngine, поэтому я создал этот класс (тот же импорт, за исключением FaceSimilityEngine):
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 ...
}
}
Однако выполнение этого кода приводит к той же ошибке, что и предыдущий код:
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));
Итак, я предполагаю, что спрашиваю, не пропущена ли ключевая переменная для этого конкретного компаратора функций, или это проблема с самим DoGSIFTFeatureComparator?