CVPR2016跟踪算法Staple的配置(Staple: Complementary Learners for Real-Time Tracking)

代码下载地址:

https://github.com/bertinetto/staple

由于Staple运行需要特定的数据格式,本文把原工程目录runTracker.m简单修改便于测试,改动不大。

1、运行测试自带视频例子

在工程目录下新建run_example1.m文件

function run_example1
% RUN_TRACKER  is the external function of the tracker - does initialization and calls trackerMain

    %% Read params.txt
    params = readParams('params.txt');
	%% load video info
    start_frame=1;                      %开始帧
	sequence_path = ['vot15_ball1/'];   %视频路径总路径
    img_path = [sequence_path 'imgs/']; %图片路径
    %% Read files
    text_files = dir([sequence_path '*_frames.txt']);
    f = fopen([sequence_path text_files(1).name]);
    frames = textscan(f, '%f,%f');    %一共多少帧
    if exist('start_frame')
        frames{1} = start_frame;
    else
        frames{1} = 1;
    end
    
    fclose(f);
    
    params.bb_VOT = csvread([sequence_path 'groundtruth.txt']);
    region = params.bb_VOT(frames{1},:);
    %%%%%%%%%%%%%%%%%%%%%%%%%
    % read all the frames in the 'imgs' subfolder
    dir_content = dir([sequence_path 'imgs/']);
    % skip '.' and '..' from the count
    n_imgs = length(dir_content) - 2;
    img_files = cell(n_imgs, 1);
    for ii = 1:n_imgs
        img_files{ii} = dir_content(ii+2).name;
    end
       
    img_files(1:start_frame-1)=[];

    im = imread([img_path img_files{1}]);
    % is a grayscale sequence ?
    if(size(im,3)==1)
        params.grayscale_sequence = true;
    end

    params.img_files = img_files;
    params.img_path = img_path;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if(numel(region)==8)
        % polygon format
        [cx, cy, w, h] = getAxisAlignedBB(region);
    else
        x = region(1);
        y = region(2);
        w = region(3);
        h = region(4);
        cx = x+w/2;
        cy = y+h/2;
    end

    % init_pos is the centre of the initial bounding box
    params.init_pos = [cy cx];
    params.target_sz = round([h w]);
    [params, bg_area, fg_area, area_resize_factor] = initializeAllAreas(im, params);
	if params.visualization
		params.videoPlayer = vision.VideoPlayer('Position', [100 100 [size(im,2), size(im,1)]+30]);
	end
    % in runTracker we do not output anything
	params.fout = -1;
	% start the actual tracking
	trackerMain(params, im, bg_area, fg_area, area_resize_factor);
    fclose('all');
end

2、运行run_example1.m

 3、跑OTB数据集

在工程目录下新建run_example2.m文件

function run_example2
% RUN_TRACKER  is the external function of the tracker - does initialization and calls trackerMain

    %% Read params.txt
    params = readParams('params.txt');
	%% load video info
    videos = {'David','Basketball', 'Bolt'};
    start_frame=1;
%     videos = {'Basketball', 'Bolt', 'Boy', 'Car4', 'CarDark', 'CarScale', ...
%     'Coke', 'Couple', 'Crossing', 'David2', 'David3', 'David', 'Deer', ...
%     'Dog1', 'Doll', 'Dudek', 'Faceocc1', 'Faceocc2', 'Fish', 'Fleetface', ...
%     'Football', 'Football1', 'Freeman1', 'Freeman3', 'Freeman4', 'Girl', ...
%     'Ironman', 'Jogging_1', 'Jumping', 'Lemming', 'Liquor', 'Matrix', ...
%     'Mhyang', 'MotorRolling', 'MountainBike', 'Shaking', 'Singer1', ...
%     'Singer2', 'Skating1', 'Skiing', 'Soccer', 'Subway', 'Suv', 'Sylvester', ...
%     'Tiger1', 'Tiger2', 'Trellis', 'Walking', 'Walking2', 'Woman'};
for s=1:numel(videos)
    sequence_path = ['D:/Datasets/OTB100/',videos{s},'/'];   %视频路径总路径
    img_path = [sequence_path 'img/']; %图片路径
    
    params.bb_VOT = csvread([sequence_path 'groundtruth_rect.txt']);
    region = params.bb_VOT(start_frame,:);
    %%%%%%%%%%%%%%%%%%%%%%%%%
    % read all the frames in the 'imgs' subfolder
    dir_content = dir([sequence_path 'img/']);
    % skip '.' and '..' from the count
    n_imgs = length(dir_content) - 2;
    img_files = cell(n_imgs, 1);
    for ii = 1:n_imgs
        img_files{ii} = dir_content(ii+2).name;
    end
       
    img_files(1:start_frame-1)=[];

    im = imread([img_path img_files{1}]);
    % is a grayscale sequence ?
    if(size(im,3)==1)
        params.grayscale_sequence = true;
    end

    params.img_files = img_files;
    params.img_path = img_path;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if(numel(region)==8)
        % polygon format
        [cx, cy, w, h] = getAxisAlignedBB(region);
    else
        x = region(1);
        y = region(2);
        w = region(3);
        h = region(4);
        cx = x+w/2;
        cy = y+h/2;
    end

    % init_pos is the centre of the initial bounding box
    params.init_pos = [cy cx];
    params.target_sz = round([h w]);
    [params, bg_area, fg_area, area_resize_factor] = initializeAllAreas(im, params);
	if params.visualization
		params.videoPlayer = vision.VideoPlayer('Position', [100 100 [size(im,2), size(im,1)]+30]);
	end
    % in runTracker we do not output anything
	params.fout = -1;
	% start the actual tracking
	trackerMain(params, im, bg_area, fg_area, area_resize_factor);
    fclose('all');
end	
end

更改第七行为你想测试的OTB视频序列名称

更改第十八行为数据集所在路径

4、运行run_example2.m

5、跑VOT数据集

在工程目录下新建run_example3.m文件

function run_example3
% RUN_TRACKER  is the external function of the tracker - does initialization and calls trackerMain

    %% Read params.txt
    params = readParams('params.txt');
	%% load video info
    videos = {'bag','ball1','ball2'};
    start_frame=1;
%     videos = {'bag','ball1','ball2','basketball','birds1','birds2','blanket','bmx','bolt1',...
%               'bolt2','book','butterfly','car1','car2','crossing','dinosaur','fernando','fish1',...
%               'fish2','fish3','fish4','girl','glove','godfather','graduate','gymnastics1',...
%               'gymnastics2','gymnastics3','gymnastics4','hand','handball1','handball2',...
%               'helicopter','iceskater1','iceskater2','leaves','marching','matrix','motocross1',...
%               'motocross2','nature','octopus','pedestrian1','pedestrian2','rabbit','racing',...
%               'road','shaking','sheep','singer1','singer2','singer3','soccer1','soccer2',...
%               'soldier','sphere','tiger','traffic','tunnel','wiper'};
for s=1:numel(videos)
    sequence_path = ['D:/Datasets/vot2016/',videos{s},'/'];   %视频路径总路径
    img_path = sequence_path; %图片路径
    
    params.bb_VOT = csvread([img_path 'groundtruth.txt']);
    region = params.bb_VOT(start_frame,:);
    %%%%%%%%%%%%%%%%%%%%%%%%%
    % read all the frames in the 'imgs' subfolder
    dir_content = dir(sequence_path);
    % skip '.' and '..' from the count
    n_imgs = length(dir_content) - 2;
    img_files = cell(n_imgs, 1);
    for ii = 1:n_imgs
        img_files{ii} = dir_content(ii+2).name;
    end
       
    img_files(1:start_frame-1)=[];

    im = imread([img_path img_files{1}]);
    % is a grayscale sequence ?
    if(size(im,3)==1)
        params.grayscale_sequence = true;
    end

    params.img_files = img_files;
    params.img_path = img_path;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if(numel(region)==8)
        % polygon format
        [cx, cy, w, h] = getAxisAlignedBB(region);
    else
        x = region(1);
        y = region(2);
        w = region(3);
        h = region(4);
        cx = x+w/2;
        cy = y+h/2;
    end

    % init_pos is the centre of the initial bounding box
    params.init_pos = [cy cx];
    params.target_sz = round([h w]);
    [params, bg_area, fg_area, area_resize_factor] = initializeAllAreas(im, params);
	if params.visualization
		params.videoPlayer = vision.VideoPlayer('Position', [100 100 [size(im,2), size(im,1)]+30]);
	end
    % in runTracker we do not output anything
	params.fout = -1;
	% start the actual tracking
	trackerMain(params, im, bg_area, fg_area, area_resize_factor);
    fclose('all');
end	
end

更改第七行为你想测试的VOT视频序列名称

更改第十八行为数据集所在路径

6、运行run_example3.m

评论 37
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值