运行KCF的MATLAB算法——小知识与小技巧

来源:https://blog.csdn.net/sinat_27318881/article/details/52873376

            https://blog.csdn.net/tjdatamining/article/details/45343991

感谢两位大神的指点,并自己整理了一下

论文: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  
        
%render target bounding box for this frame

        (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;

变成

%   Joao F. Henriques, 2014
%   http://www.isr.uc.pt/~henriques/

    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 isempty(im_h),  %create image
			im_h = imshow(img, 'Border','tight', 'InitialMag',200, 'Parent',axes_h);
		else  %just update it
			set(im_h, 'CData', img)
        end

           加载完后,运行主程序就能看到彩色图像。

猜你喜欢

转载自blog.csdn.net/weixin_39447902/article/details/81206379
今日推荐