Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DMatch.java #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions openCVLibrary2410/src/main/java/org/opencv/features2d/DMatch.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}