Closed youthiya closed 5 years ago
A keypoint struct has the following fields:
pt
size
angle
response
octave
class_id
Looking at the opencv source code of the removeDuplicated
function (see here), two keypoints are considered duplicate if they have the same pt
, size
, and angle
(all three fields):
img = imread('image.jpg');
obj = cv.SIFT();
kpts = obj.detect(img);
kpts0 = cv.KeyPointsFilter.removeDuplicated(kpts);
If you want to consider only pt
(coordinates) when removing duplicates, you'll have to filter the points yourself. You can do this in plain MATLAB:
pt = cat(1, kpts.pt);
[~,ind] = unique(pt, 'rows');
kpts1 = kpts(ind);
You can make this fancier by using uniquetol
instead of unique
to perform comparison with a tolerance instead of an exact comparison (i.e. keep points that are at least a distance tolerance apart, not necessarily exactly equal):
pt = cat(1, kpts.pt);
tol = 0.1;
[~,ind] = uniquetol(pt, tol, 'ByRows',true, 'DataScale',[1 1]);
kpts2 = kpts(ind);
Thanks a lot. Issue is clear now.
Hello. I am working on removal of duplicate keypoints after SIFT feature detection but following function is not removing the duplicate keypoints (that have same coordinates but different orientation).
keypoints = cv.KeyPointsFilter.removeDuplicated(keypoints)
Is this function coded wrong? What could be the issue?