KCF-matlab版修改彩色显示

论文: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
  1. 记得把这个函数里的这几句话注释掉或者删掉

  2. % 		if size(im,3) > 1,
    % 			im = rgb2gray(im);
    % 		end
    % 		if resize_image,
    % 			im = imresize(im, 0.5);
    % 		end

     

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

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值