論文:High-Speed Tracking with Kernelized Correlation Filters.
代碼來源:http://www.robots.ox.ac.uk/~joao/
準備工作:
下載代碼,並在http://cvlab.hanyang.ac.kr/tracker_benchmark/datasets.html 下載OTB數據庫中的視頻,作者提供的download_video.m實在是不好用。注意下載的文件的內容,解壓的一級目錄必須包含img文件夾和groudtruth_rect.txt文件,前者是視頻序列,後者提供了target和準確路徑用於評估。下面以我下載的Basketball數據集爲例。
運行
下面需要在run_tracker.m中修改路徑
base_path = 'D:\data_seq\';
這裏data_seq爲Basketball的上一級目錄。
按理說然後直接輸入run_tracker();就可以跑了,但是出現瞭如下錯誤
Error in precision_plot (line 40)
figure('Number','off', 'Name',['Precisions - ' title])
解決方案
在show_video.m中有這一段代碼,其中將‘Number‘,’off’刪去
%create window
[fig_h, axes_h, unused, scroll] = videofig(num_frames, @redraw, [], [], @on_key_press); %#ok, unused outputs
set(fig_h, 'Number','off','Name', ['Tracker - ' video_path])
變成
%create window
[fig_h, axes_h, unused, scroll] = videofig(num_frames, @redraw, [], [], @on_key_press); %#ok, unused outputs
set(fig_h, 'Name', ['Tracker - ' video_path])
同時precision_plot.m中同樣將‘Number‘,’off’刪去
if show == 1,
figure('Number','off' ,'Name',['Precisions - ' title])
plot(precisions, 'k-', 'LineWidth',2)
xlabel('Threshold'), ylabel('Precision')
end
變成
if show == 1,
figure('Name',['Precisions - ' title])
plot(precisions, 'k-', 'LineWidth',2)
xlabel('Threshold'), ylabel('Precision')
end
這樣基本就搞定了,就能運行了。
顯示幀數
在show_video.m文件中加上了一些代碼
(1) 在代碼rect_h=[];
後加上下面這段代碼:
fps_h=[];%show the frame number
變成
rect_h = [];
fps_h=[];%show the frame number
(2)在代碼%render target bounding box for this frame前加上下面這段代碼:
%show the frame number
if isempty(fps_h),
fps_h=text('Position',[5,18], 'String','#1','Color','y', 'FontWeight','bold', 'FontSize',20,'Parent',axes_h);
end
變成
%show the frame number
if isempty(fps_h),
fps_h=text('Position',[5,18], 'String','#1','Color','y','FontWeight','bold', 'FontSize',20,'Parent',axes_h);
end
(3)在代碼set(rect_h, 'Visible', 'on', 'Position', boxes{frame});後加上下面這段代碼:
set(fps_h,'String',strcat('#',num2str(frame)));%show the frame number
變成
set(rect_h, 'Visible', 'on', 'Position', boxes{frame});
set(fps_h,'String',strcat('#',num2str(frame)));%show the frame number
加載完後,運行主程序就能顯示幀數。
顯示彩色圖像
也在show_video.m文件中修改
先定義
img=[];%show color image;
在函數function redraw(frame)裏添加代碼
img=im;%show color image
並在該函數內修改下面兩處的代碼,主要是將im替換成img。
im_h = imshow(im, 'Border','tight', 'InitialMag',200, 'Parent',axes_h);%show color image
set(im_h, 'CData', im);%show gray image
變成
function redraw(frame)
%render main image
im = imread([video_path img_files{frame}]);
img=im;%show color image
% if size(im,3) > 1,
% im = rgb2gray(im);
% end
% if resize_image,
% im = imresize(im, 0.5);
% end
if isempty(im_h), %create image
im_h = imshow(img, 'Border','tight', 'InitialMag',200, 'Parent',axes_h);
else %just update it
set(im_h, 'CData', im)
end
%render target bounding box for this frame
if isempty(fps_h),
fps_h=text('Position',[5,18], 'String','#1','Color','y', 'FontWeight','bold', 'FontSize',20,'Parent',axes_h);
end
if isempty(rect_h), %create it for the first time
rect_h = rectangle('Position',[0,0,1,1], 'EdgeColor','g', 'Parent',axes_h);
end
if ~isempty(boxes{frame}),
set(rect_h, 'Visible', 'on', 'Position', boxes{frame});
set(fps_h,'String',strcat('#',num2str(frame)));%show the frame number
else
set(rect_h, 'Visible', 'off');
end
end
-
記得把這個函數裏的這幾句話註釋掉或者刪掉
-
% if size(im,3) > 1, % im = rgb2gray(im); % end % if resize_image, % im = imresize(im, 0.5); % end
加載完後,運行主程序就能看到彩色圖像。