我想知道如何找到匹配距离,但过了一段时间MatOfDMatch匹配得不到匹配。我通过Haar探测器检测面部,接下来我在这里做的是将一个新的检测与模板图像匹配,如果距离足够低,它将附加新的检测图像。问题是在几个iteratons之后matchlist是空的。
@Override
public void match(List<Template> listOfTemplates, List<Template> listOfDetections) {
FeatureDetector Fdetector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor Fdescriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
for (Template template : listOfTemplates) {
MatOfKeyPoint templateKeyPoints=new MatOfKeyPoint();
Mat templateDescriptors=new Mat();
Fdetector.detect(template.image, templateKeyPoints);
Fdescriptor.compute(template.image, templateKeyPoints, templateDescriptors);
for (Template detection : listOfDetections) {
MatOfKeyPoint detectionKeyPoints=new MatOfKeyPoint();
Mat detectionDescriptors=new Mat();
Fdetector.detect(detection.image, detectionKeyPoints);
Fdescriptor.compute(detection.image, detectionKeyPoints, detectionDescriptors);
MatOfDMatch matches=new MatOfDMatch();
if (detectionDescriptors.cols() <= templateDescriptors.cols()) {
matcher.match(detectionDescriptors,templateDescriptors , matches);
} else {
matcher.match(templateDescriptors, detectionDescriptors, matches);
}
List<DMatch> matchlist=matches.toList();
for (DMatch dMatch : matchlist) {
if (dMatch.distance<80) {
template.IdOfContourMatcher =listOfDetections.indexOf(detection);
}
System.out.println(dMatch.distance);
}
}
}
}
}