How to properly initialize Histogram-based tracker?

2 次查看(过去 30 天)
Hi all, I am trying to track flying drones for a school project.
My strategy is to use the detectSURF features function to detect a SURF point on the object and then use this point to construct an search box around the drone to initialize the Histogram-based tracker in the computer vision toolbox.
I am able to detect the drone SURF feature but the Histogram tracker is not behaving as intended as the red bounding box keeps expanding towards all edges of the frame. The green box below shows the placement of the search box. The next picture with red lines at the frame edges shows the problem I am facing - the Histogram tracker is simply not tracking the target. I have followed the face-tracking example for HistogramBasedTacker in computer vision toolbox, given in the MATLAB documentation, but my code doesn't work and I can't figure out what's wrong.
I am posting my code to seek advice on how I can overcome this problem. Appreciate your help pls. There are mainly 2 FOR loops in the code.
The first FOR loop reads the file to detect SURF points. The frame is then processed into HSV color space to segment by hue values. Once detected, the Histogram tracker is initialized with a region of interest (i.e the search box) and the algorithm breaks out of the first FOR loop.
The second FOR loop mainly runs the Histogram tracker until end of video. (At least this was my intention, but the code isn't working )
%test of image processing
clear;
clc;
%read inputs and test play the video
dronevid = VideoReader('scott 2.mp4');
get(dronevid);
nframes = dronevid.NumberOfFrames;
%videoFileReader = vision.VideoFileReader('scott 2.mp4');
%videoPlayer = vision.VideoPlayer();
shapeInserter = vision.ShapeInserter('BorderColor','Custom', ...
'CustomBorderColor',[1 0 0]);
init=1;
k=1;
for i=0:nframes
if i==0
continue
end
frame=read(dronevid,i);
image(frame);
hold on;
%img_tmp = double(frame); %load in the image and convert to double to allow for computations on the image
img = frame(:,:,1);
points = detectSURFFeatures(img);
y=points.selectStrongest(1);
plot(points.selectStrongest(1));
k=i+1;
if (~isempty(points) & i > 80 ) %break out of FOR loop when SURF features is detected
%initialize tracker
hsv = rgb2hsv(frame);
hframe=hsv(:,:,1);
sframe=hsv(:,:,2);
initx=round(y.Location(1));
inity=round(y.Location(2));
%objectRegion=round(getPosition(imrect));
objectRegion = [initx-10, inity-30, 65, 46];
rectangle('Position',objectRegion,'EdgeColor','g','LineWidth',2);
pause(3);
%objectImage = shapeInserter(frame, objectRegion);
%imshow(objectImage);
tracker = vision.HistogramBasedTracker;
initializeObject(tracker, hframe , objectRegion);
%bbox = tracker(frame(:,:,1)); % draw first bounding box
%rectangle('Position',[bbox(1),bbox(2),bbox(3),bbox(4)],'EdgeColor','y','LineWidth',2);
pause(3)
init=0; % tracker initialization is done
break
end
drawnow;
end
hold off;
for j=i:nframes
frame1=read(dronevid,j);
image(frame1);
hold on;
hsv = rgb2hsv(frame1);
hframe=hsv(:,:,1);
sframe=hsv(:,:,2);
bb = tracker(hframe);
rectangle('Position',[bb(1),bb(2),bb(3),bb(4)],'EdgeColor','r','LineWidth',2);
pause(0.1);
drawnow;
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tracking and Motion Estimation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by