gpt4 book ai didi

java - OpenIMAJ人脸识别中的rfaces.get(0).getSecondObject()总是返回null

转载 作者:行者123 更新时间:2023-12-01 12:45:17 25 4
gpt4 key购买 nike

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.codehaus.jackson.map.introspect.Annotated;
import org.openimaj.data.dataset.GroupedDataset;
import org.openimaj.data.dataset.ListDataset;
import org.openimaj.data.dataset.VFSGroupDataset;
import org.openimaj.experiment.dataset.split.GroupedRandomSplitter;
import org.openimaj.experiment.dataset.util.DatasetAdaptors;
import org.openimaj.feature.DoubleFV;
import org.openimaj.feature.DoubleFVComparison;
import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.FImage;
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.model.EigenImages;
import org.openimaj.image.processing.face.alignment.RotateScaleAligner;
import org.openimaj.image.processing.face.detection.HaarCascadeDetector;
import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector;
import org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace;
import org.openimaj.image.processing.face.recognition.EigenFaceRecogniser;
import org.openimaj.image.processing.face.recognition.FaceRecognitionEngine;
import org.openimaj.ml.annotation.AnnotatedObject;
import org.openimaj.ml.annotation.ScoredAnnotation;
import org.openimaj.util.pair.IndependentPair;

public class Demo {

public static void main(String ... s) throws IOException {

FKEFaceDetector faceDetector = new FKEFaceDetector(new HaarCascadeDetector());

EigenFaceRecogniser<KEDetectedFace, Integer> faceRecognizer = EigenFaceRecogniser.create(20, new RotateScaleAligner(), 1, DoubleFVComparison.CORRELATION, 0.9f);

FaceRecognitionEngine<KEDetectedFace, Integer> faceEngine = FaceRecognitionEngine.create(faceDetector, faceRecognizer);


for(int i = 1; i < 15; i ++){
System.out.println(i);
FImage pamu = ImageUtilities.createFImage(ImageIO.read(new File("/home/nagarjuna/Pictures/Webcam/"+i+".jpg")));
List<KEDetectedFace> faces = faceEngine.getDetector().detectFaces(pamu);
if(faces.size() > 0)
faceEngine.train(faces.get(0), i);
}

FImage pamu = ImageUtilities.createFImage(ImageIO.read(new File("/home/nagarjuna/Pictures/Webcam/"+12+".jpg")));

List<KEDetectedFace> faces = faceEngine.getDetector().detectFaces(pamu);

List<IndependentPair<KEDetectedFace, ScoredAnnotation<Integer>>> rfaces = faceEngine.recogniseBest(faces.get(0).getFacePatch());
ScoredAnnotation<Integer> score = rfaces.get(0).getSecondObject();
DisplayUtilities.display(rfaces.get(0).getFirstObject().getFacePatch());
if(score != null) {
System.out.println("confidence: "+score.confidence);
System.out.println("annotation: "+score.annotation);
}else {
System.out.println("score is null");
}
}
}

输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
score is null

最佳答案

不幸的是,OpenIMAJ 在 KNNAnnotator 类中处理相似性度量(而不是距离度量)的方式似乎出现了一个错误。已提交修复(修订版 #2560),并且包含该修复的新快照(版本 1.3-SNAPSHOT)应在几个小时内可用。目前,您应该能够将 DoubleFVComparison.CORRELATION 更改为 DoubleFVComparison.EUCLIDEAN,然后它应该可以工作。

我注意到您的代码中还有一些可能应该修复的其他问题:

  • 您应该使用 ImageUtilities.readF(new File("...")); 而不是 ImageUtilities.createFImage(ImageIO.read(new File("..."))); ")); 因为这可以解决 ImageIO 中的许多已记录的错误,特别是在 jpeg 读取方面,并且您还可以获得对许多其他图像文件格式的支持。
  • 您不需要自己手动对查询图像进行人脸检测; faceEngine.recogniseBest(FImage) 方法在内部为您完成此操作(连同对齐)

关于java - OpenIMAJ人脸识别中的rfaces.get(0).getSecondObject()总是返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24765018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com