I am doing a project in MatLab that consists of the following:
I have got a folder containing 600 frames that, together, are a video of a motorcycle chasing, probably filmed from an helicopter. The thing is that I have to track this motorcycle along all frames, but I am having some issues.
The strategy I am following is taking the first frame and extracting the motorcycle from it. Then, I compare this extract with every frame, using the SIFT features (I'll attach the code below) but I am getting some problems:
The call to T = estimateGeometricTransform2D(m_kp_obj,m_kp_esc,"affine"); sometimes tells me there are not sufficeint match points. It basically works for some frames but others fail.
There are some frames from where nbox2 gives me a negative number, and I don't get why (there are others that work correctly).
I'll attach the code below. I really hope you can help me to solve these issues. Feel free to try the code and to apply any changes you feel convinient. Here is the link to the frames, the folder is called MotorcycleChase.zip -> https://drive.google.com/embeddedfolderview?id=1zLRwARzIfqadp8qVHiC4Y_T5U0YMQxeE#list
Thank you all! You are saving my life!
% 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 = detectSIFTFeatures(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 = detectSIFTFeatures(im_esc);
kp_esc = selectStrongest(kp_esc,50);
[feat_esc,kp_esc] = extractFeatures(im_esc,kp_esc);
pairs = matchFeatures(feat_obj,feat_esc,'MatchThreshold',5);
% Check if we have enough matched points
m_kp_obj = kp_obj(pairs(:,1),:);
m_kp_esc = kp_esc(pairs(:,2),:);
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);
nbox2 = [nbox(1,1), nbox(1, 2), nbox(2, 1)-nbox(1,1), nbox(3,2)-nbox(1,2)];
overlapRatio = bboxOverlapRatio(nbox2,BB(i,2:5))
imshow(im_esc); % mostra el frame
rectangle('Position',nbox2,'EdgeColor','blue');
drawnow
end