diff --git a/openCVLibrary2410/src/main/java/org/opencv/features2d/DMatch.java b/openCVLibrary2410/src/main/java/org/opencv/features2d/DMatch.java index d520a2e..9aedc69 100644 --- a/openCVLibrary2410/src/main/java/org/opencv/features2d/DMatch.java +++ b/openCVLibrary2410/src/main/java/org/opencv/features2d/DMatch.java @@ -1,57 +1,59 @@ -package org.opencv.features2d; - -//C++: class DMatch - -/** - * Structure for matching: query descriptor index, train descriptor index, train - * image index and distance between descriptors. - */ public class DMatch { + // Member variables + private int queryIdx; // Query descriptor index + private int trainIdx; // Train descriptor index + private int imgIdx; // Train image index + private float distance; // Distance between descriptors - /** - * Query descriptor index. - */ - public int queryIdx; - /** - * Train descriptor index. - */ - public int trainIdx; - /** - * Train image index. - */ - public int imgIdx; - - public float distance; - + // Default constructor initializing to default values public DMatch() { - this(-1, -1, Float.MAX_VALUE); + this.queryIdx = -1; + this.trainIdx = -1; + this.imgIdx = -1; + this.distance = Float.MAX_VALUE; } - public DMatch(int _queryIdx, int _trainIdx, float _distance) { - queryIdx = _queryIdx; - trainIdx = _trainIdx; - imgIdx = -1; - distance = _distance; + // Constructor with query and train indices and distance + public DMatch(int queryIdx, int trainIdx, float distance) { + this.queryIdx = queryIdx; + this.trainIdx = trainIdx; + this.imgIdx = -1; + this.distance = distance; } - public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) { - queryIdx = _queryIdx; - trainIdx = _trainIdx; - imgIdx = _imgIdx; - distance = _distance; + // Constructor with query and train indices, image index, and distance + public DMatch(int queryIdx, int trainIdx, int imgIdx, float distance) { + this.queryIdx = queryIdx; + this.trainIdx = trainIdx; + this.imgIdx = imgIdx; + this.distance = distance; } - /** - * Less is better. - */ - public boolean lessThan(DMatch it) { - return distance < it.distance; + // Method to compare this DMatch with another DMatch + public boolean isLessThan(DMatch other) { + return this.distance < other.distance; } - @Override - public String toString() { - return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx - + ", imgIdx=" + imgIdx + ", distance=" + distance + "]"; + // Method to print the DMatch details + public void print() { + System.out.println("DMatch [queryIdx=" + queryIdx + + ", trainIdx=" + trainIdx + + ", imgIdx=" + imgIdx + + ", distance=" + distance + "]"); } + public static void main(String[] args) { + // Example usage of DMatch + DMatch match1 = new DMatch(0, 1, 0.5f); + DMatch match2 = new DMatch(1, 2, 0.3f); + + match1.print(); + match2.print(); + + if (match1.isLessThan(match2)) { + System.out.println("Match1 is closer than Match2."); + } else { + System.out.println("Match2 is closer than Match1."); + } + } }