0

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: enter image description here

Can someone provide an implementation or suggest resources for this particular problem? Any help would be appreciated.

Pol
  • 13
  • 3
  • It is impossible to answer without more information about your video. Is the camera static? Mounted on a car? Tracking the motorbike? – Cris Luengo Jun 17 '23 at 13:51
  • My apologies for the lack of infomation. The video is given in individual frame form, I literally have a folder with 600 frames. The video seems to be an helicopter filming the motorbike, so the most part of it the motorbike shows. Here is the link where you can find the folder containing the frames, is called MotorcycleChase: https://drive.google.com/embeddedfolderview?id=1VE8QTjD8yWYvn5pYFj4DjVkIPEMmc4s_#list – Pol Jun 17 '23 at 14:55
  • new question: https://stackoverflow.com/questions/76496880/sift-features-for-image-tracking – Christoph Rackwitz Jun 17 '23 at 16:58
  • hi Pol, the same way that an image is worth 1000 words, some code, if not THE code you have started with, such code and a sample of the video, if not the complete video itself would operate wonders in assisting the readers of your question in understanding what would eventually culminate in probably someone supplying a working solution to the question you have here posed. Please Pol provide code and video, both in significant amounts, thanks for your cooperation, awaiting answer – John BG Jun 17 '23 at 23:47
  • ok, the video is one of the zip files in the google drive in the link provided, good. Now the not-working code, we need to start were you stopped, again thanks for your cooperation – John BG Jun 17 '23 at 23:50
  • Hi John, I really appreciate your help! Thank you very much in advanced. The thing is that the code I have got tries to implement the tracking using the SIFT features, and I need a totally new algorithm/technique. But I don't mind posting the code I currently have! Thank you John again for your dedication! – Pol Jun 18 '23 at 08:57

0 Answers0