2 つの画像の類似度を計算しようとしていますが、毎回 0 になります。
これは私のコードです:
public class TemplateMatching{
static void analyze(Mat image, MatOfKeyPoint keypoints, Mat descriptors){
detector.detect(image, keypoints);
extractor.compute(image, keypoints, descriptors);
}
static FeatureDetector detector= FeatureDetector.create(FeatureDetector.ORB);
static DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
final static DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
static void ana(Mat image, MatOfKeyPoint keypoints, Mat descriptors){
detector.detect(image, keypoints);
extractor.compute(image, keypoints, descriptors);
}
static MatOfDMatch filterMatchesByDistance(MatOfDMatch matches){
List<DMatch> matches_original = matches.toList();
List<DMatch> matches_filtered = new ArrayList<DMatch>();
int DIST_LIMIT = 30;
// Check all the matches distance and if it passes add to list of filtered matches
Log.d("DISTFILTER", "ORG SIZE:" + matches_original.size() + "");
for (int i = 0; i < matches_original.size(); i++) {
DMatch d = matches_original.get(i);
if (Math.abs(d.distance) <= DIST_LIMIT) {
matches_filtered.add(d);
}
}
Log.d("DISTFILTER", "FIL SIZE:" + matches_filtered.size() + "");
MatOfDMatch mat = new MatOfDMatch();
mat.fromList(matches_filtered);
return mat;
}
public int comparer(Mat frame,Mat test) {
// Info to store analysis stats
int distance=0;
MatOfKeyPoint keypoints_o = new MatOfKeyPoint();
MatOfKeyPoint keypoints_t = new MatOfKeyPoint();
Mat descriptors_o = new Mat();
Mat descriptors_t = new Mat();
// Detect key points and compute descriptors for inputFrame
ana(frame, keypoints_o, descriptors_o);
ana(test, keypoints_t, descriptors_t);
// Compute matches
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors_o, descriptors_t, matches);
// Filter matches by distance
MatOfDMatch filtered = filterMatchesByDistance(matches);
// If count of matches is OK, apply homography check
distance = (int) filtered.size().height;
return (distance);
}
距離は毎回0です。同じ画像を与えると、距離も 0 になります。