SURF features for object tracking

9 views (last 30 days)
Pol
Pol on 19 Jun 2023
Answered: Ranjeet on 28 Jun 2023
Hi!
In there you can find the origin of my problem. So I am using SURF features now instead of SIFT features for matching a motorcycle to a set of frames where this motorcycle appears. The thing is that no matter what I try, there is always a frame that gives the following error in line T = estimateGeometricTransform2D(m_kp_obj, m_kp_esc, "affine") :
Error using vision.internal.geotrans.algEstimateGeometricTransform>checkRuntimeStatus Could not find enough inliers in matchedPoints1 and matchedPoints2. Error in vision.internal.geotrans.algEstimateGeometricTransform (line 72) checkRuntimeStatus(statusCode, status, sampleSize); Error in estimateGeometricTransform2D (line 157) vision.internal.geotrans.algEstimateGeometricTransform(...
I have changed descriptors from SIFT to SURF, changes MatchThreshold value, change the points required for matching, but it still gives me this error and is a completely nightmare. I hope someone really could help me fixing this. I now provide the code, please feel free to use it and test it, if that means understanding better my issue or fixing it. If interested, you can find the link to all frames folder in the previous related questoin I made (link above).
Thank you very much. I really hope someone can help me. I'm open to do discord or whatever if that means making things easier.
Here is the code:
% myTracker, codi inicial del short project
close all
% Llegim el fitxer d'anotacions groundtruth_rect.txt: frame, bounding boxes, is_lost
BB = importdata('./MotorcycleChase/groundtruth_rect.txt');
Idir = dir('./MotorcycleChase/img/*.jpg');
% figure
% hold on % mantenim sempre oberta la mateixa figura
filename = horzcat(Idir(1).folder,'/',Idir(1).name);
I = imread(filename);
imshow(I);
moto = imcrop(I,BB(1,2:5));
imshow(moto);
im_obj = rgb2gray(moto);
kp_obj = detectSURFFeatures(im_obj);
kp_obj = selectStrongest(kp_obj,50);
[feat_obj,kp_obj] = extractFeatures(im_obj,kp_obj);
nf = size(Idir);
for i = 2:nf
filename = horzcat(Idir(i).folder,'/',Idir(i).name);
im_esc = rgb2gray(imread(filename));
kp_esc = detectSURFFeatures(im_esc);
kp_esc = selectStrongest(kp_esc,50);
[feat_esc,kp_esc] = extractFeatures(im_esc,kp_esc);
pairs = matchFeatures(feat_obj, feat_esc, 'MatchThreshold', 3);
m_kp_obj = kp_obj(pairs(:, 1), :);
m_kp_esc = kp_esc(pairs(:, 2), :);
if size(m_kp_obj, 1) >= 3 && size(m_kp_esc, 1) >= 3
T = estimateGeometricTransform2D(m_kp_obj, m_kp_esc, "affine");
[f, c] = size(im_obj);
box = [1, 1; c, 1; c, f; 1, f; 1, 1];
nbox = transformPointsForward(T, box);
nbox = sortrows(nbox, [2 1]); % Sort points based on y, then x
% Calculate the new bounding box coordinates (nbox2)
minCoord = min(nbox);
maxCoord = max(nbox);
nbox2 = [minCoord(1), minCoord(2), maxCoord(1)-minCoord(1), maxCoord(2)-minCoord(2)];
overlapRatio = bboxOverlapRatio(nbox2, BB(i, 2:5));
imshow(im_esc); % Show the frame
rectangle('Position', nbox2, 'EdgeColor', 'blue');
drawnow
else
% Handle the case when there are not enough matched points
% You can either skip this frame or use a different approach
end
end

Answers (1)

Ranjeet
Ranjeet on 28 Jun 2023
Hi Pol,
The key message in the provided error message is “Could not find enough inliers in matchedPoint1 and matchedPoint2”.
Have a look at the following resources discussing the same issue and proposed debugging/solution –
  1. Error: Could not find enough inliers in imagePoints and worldPoints
  2. estimateGeometricTransform don’t return the status
Also, ‘estimategeometricTransform’ is not recommended to use, you may refer to the following alternatives –
  1. estgeotfrom2d
  2. estgeotfrom3d

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!