user2062340
user2062340

Reputation: 73

How to get pixel distance from two matched features

I am using Android OpenCV to detect features from the input frame of the camera. I am using the ORB feature detector and ORB descriptor extractor with BFMatcher. Now I got some matches Mat in the format of

matches = Mat [ 421*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x5fad7b30, dataAddr=0x5fab84f0 ]

I wonder what is the nativeObj and dataAddr represented for? I want to get the distance between two matched features in pixel, any idea?

I have found someone else had the same question and there was no reply. How to Access Points location on OpenCV Matcher?

Thanks in advance!

Upvotes: 0

Views: 1106

Answers (1)

andriy
andriy

Reputation: 4154

When you are performing match of descriptors of features you should get MatOfDMatch. Your code should be like this:

DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1,descriptors2 ,matches);

After you can transform MatOfDMatch to the List<DMatch> for easier manipulation. You can do it with :

List<DMatch> matchesList = matches.toList();

Then you can access to the matched points and obtain the Cartesian coordinates with:

Point pt1 = keypoints1.toList().get(matchesList.get(i).queryIdx).pt; 
Point pt2 = keypoints2.toList().get(matchesList.get(i).trainIdx).pt;

After just calculate the distance between two points:

double dist_x_pow = Math.pow(Math.abs(pt1.x - pt2.x),2);
double dist_y_pow = Math.pow(Math.abs(pt1.y - pt2.y),2);
double DISTANCE = Math.sqrt(dist_x_pow + dist_y_pow);

About nativeObj and dataAddr I'm not sure, but I think it is related to the fact that OpenCV library is implemented in C and I think that this values represent address in memory of the Mat object.

Upvotes: 2

Related Questions