Reputation: 13
I have a task where I need to track a motorbike in a set of frames from a video. I have already used SIFT features to compare each frame with the motorbike object, but I need another technique to implement.
All the techniques I have found use a background, but I do not have a scene frame without the motorbike. Additionally, most of them are meant for face detection. I am looking for an implementation or resources on how to pick the motorbike and track it in the other frames, showing a rectangle around it.
Here is the code used for SIFT features. There are some frames giving me problems with estimateGeometricTransform2D and, also, with nbox2, that sometimes get negative values.
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 = 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
The error related to the geometric transform is:
Can someone provide an implementation or suggest resources for this particular problem? Any help would be appreciated.
Upvotes: 0
Views: 80