CVPR2018目标跟踪算法STRCF实验复现步骤

参考链接:https://blog.csdn.net/qq_17783559/article/details/82024573

CVPR2018论文:Learning Spatial-Temporal Regularized Correlation Filters for Visual Tracking

1、Github代码下载地址:https://github.com/lifeng9472/STRCF

2、从如下地址下载matconvnet,并解压到external_libs/matconvnet/ 路径 https://github.com/vlfeat/matconvnet
在这里插入图片描述
3、从如下地址下载PDollar Toolbox,并解压到external_libs/pdollar_toolbox/路径
https://github.com/pdollar/toolbox
在这里插入图片描述
4、从如下地址下载预训练模型imagenet-vgg-m-2048.mat,并放到feature_extraction/networks/路径(注:networks文件夹得自己新建)
http://www.vlfeat.org/matconvnet/pretrained/ 。或者可以直接用该路径下载:https://www.vlfeat.org/matconvnet/models/imagenet-vgg-m-2048.mat
在这里插入图片描述
5、运行install.m,此时需要调用C++编译器,如果出现错误,可参考博客配置好matlab中的C++编译环境:https://blog.csdn.net/qq_38522168/article/details/111461856本人安装matlab自带的C++编译器之后运行install.m还是会出现错误,所以,推荐安装VS2015编译器。本人安装环境为 Win10,Matlab R2020a
在这里插入图片描述
6、运行demo_STRCF.m得到结果
在这里插入图片描述
7、运行深度特征,注释掉17行results = run_STRCF(seq); 取消注释18行results = run_DeepSTRCF(seq);
在这里插入图片描述
8、 打开run_DeepSTRCF.m更改67行如下,不使用GPU(因为没有GPU,如果你有GPU,可以不改动)。
在这里插入图片描述
9、再次运行demo_STRCF.m得到深度特征的跟踪结果
在这里插入图片描述

====================================

更新STRCF在VOT中使用

1、D:\Code\MATLAB2014\STRCF-master\STRCF-master\feature_extraction\load_cnn.m 中的相对路径改为绝对路径
在这里插入图片描述
2、新建DeepSTRCF对应VOT工程(源代码给出了DeepSTRCF的接口,直接使用DeepSTRCF做示例,STRCF可以参考改动测试)

tracker_DeepSTRCF.m设置如下:

tracker_label = 'DeepSTRCF';
tracker_command = generate_matlab_command('vot_wrapper(''DeepSTRCF'', ''DeepSTRCF_VOT_setting'')', {'D:\Learn\Courses in school\Ph.D Grade 2\STRCF-master'});
tracker_interpreter = 'matlab';
tracker_trax = false;

在这里插入图片描述
3、更改工程目录下DeepSTRCF_VOT_setting.m
设置67行不使用GPU,本人没有GPU
params.use_gpu = false; % Enable GPU or not

4、重新编写VOT接口

vot_initialize.m 其中E:\Datasets\vot2016\为我的数据集路径

function [images, region] = vot_initialize()
    % Add paths
    setup_paths();
    pathstr='D:\Datasets\vot2016\';
    video=choose_video(pathstr);
    % read the image file paths
    if ~isempty(video)
        dirs=dir([pathstr video '\*.jpg']);
        images = fullfile([pathstr video '\'], {dirs.name})';
    end
    
    % read the region
    % 此处对应polygon坐标
    region = dlmread([pathstr video '\groundtruth.txt']);
    region = region(1,:)';
    % 此处对应rectangle坐标    
    %region = read_vot_regions([pathstr video '\groundtruth.txt']);
    %region = region(1,:)';
end

vot_report.m

function vot_report(regions)
 
for i = 1:numel(regions)
    region = regions{i};
    [~, ~] = traxserver('wait');
    traxserver('status', region);
end;

vot_save.m

function vot_save(regions)
 
fid = fopen('output.txt', 'w');
 
for i = 1:numel(regions)
    region = regions{i};
    
    if numel(region) == 1
        fprintf(fid, '%f\n', region);
    elseif numel(region) == 4
        fprintf(fid, '%f,%f,%f,%f\n', region(1), region(2), region(3), region(4));
    elseif numel(region) >= 6 && mod(numel(region), 2) == 0
        fprintf(fid, '%f,', region(1:end-1));
        fprintf(fid, '%f\n', region(end));
    else
        error('VOT: Illegal result format');
    end;
end;
fclose(fid);

vot_wrapper.m

function vot_wrapper(tracker_name, runfile_name, do_cleanup)
 
if nargin < 3
    do_cleanup = true;
end
 
% *************************************************************
% VOT: Always call exit command at the end to terminate Matlab!
% *************************************************************
if do_cleanup
    cleanup = onCleanup(@() exit() );
else
    [pathstr, ~, ~] = fileparts(mfilename('fullpath'));
    cd_ind = strfind(pathstr, filesep());
    pathstr = pathstr(1:cd_ind(end)-1);
    cleanup = onCleanup(@() cd(pathstr));
end
 
try
 
% *************************************************************
% VOT: Set random seed to a different value every time.
% *************************************************************
RandStream.setGlobalStream(RandStream('mt19937ar', 'Seed', sum(clock)));
 
% **********************************
% VOT: Get initialization data
% **********************************
 
if ~isempty(getenv('TRAX_MEX'))
    addpath(getenv('TRAX_MEX'));
end;
traxserver('setup', 'polygon', 'path');  %'rectangle', 'polygon'  
[images, region] = vot_initialize();
 
results = cell(length(images), 1);
 
bb_scale = 1;
 
% If the provided region is a polygon ...
if numel(region) > 4
    % Init with an axis aligned bounding box with correct area and center
    % coordinate
    cx = mean(region(1:2:end));
    cy = mean(region(2:2:end));
    x1 = min(region(1:2:end));
    x2 = max(region(1:2:end));
    y1 = min(region(2:2:end));
    y2 = max(region(2:2:end));
    A1 = norm(region(1:2) - region(3:4)) * norm(region(3:4) - region(5:6));
    A2 = (x2 - x1) * (y2 - y1);
    s = sqrt(A1/A2);
    w = s * (x2 - x1) + 1;
    h = s * (y2 - y1) + 1;
else
    cx = region(1) + (region(3) - 1)/2;
    cy = region(2) + (region(4) - 1)/2;
    w = region(3);
    h = region(4);
end
 
init_c = [cx cy];
init_sz = bb_scale * [w h];
 
im_size = size(imread(images{1}));
im_size = im_size([2 1]);
 
init_pos = min(max(round(init_c - (init_sz - 1)/2), [1 1]), im_size);
init_sz = min(max(round(init_sz), [1 1]), im_size - init_pos + 1);
 
seq.s_frames = images;
seq.init_rect = [init_pos, init_sz];
 
[file_path, file_name_start, file_ext] = fileparts(seq.s_frames{1});
[~, file_name_end, ~] = fileparts(seq.s_frames{end});
seq.path = file_path;
seq.name = 'vot_seq';
seq.ext = file_ext(2:end);
seq.len = length(seq.s_frames);
seq.nz = length(file_name_start);
seq.startFrame = str2num(file_name_start);
seq.endFrame = str2num(file_name_end);
 
% setup_tracker_paths(tracker_name);
 
otb_res = eval([runfile_name '(seq, [], []);']);
%convert the results to rectangle format
% otb_res = convert_to_rect(otb_res);
 
num_frames = numel(images);
for frame = 1:num_frames
    bb = otb_res.res(frame,:);
    sz = bb(3:4);
    c = bb(1:2) + (sz - 1)/2;
    new_sz = sz / bb_scale;
    new_tl = c - (new_sz - 1)/2;
    results{frame} = round([new_tl, new_sz]);
end
 
% **********************************
% VOT: Output the results
% **********************************
vot_report(results);
vot_save(results);
traxserver('quit');  %退出
catch err
    [wrapper_pathstr, ~, ~] = fileparts(mfilename('fullpath'));
    cd_ind = strfind(wrapper_pathstr, filesep());
    VOT_path = wrapper_pathstr(1:cd_ind(end));
    
    error_report_path = [VOT_path 'error_reports\'];
    if ~exist(error_report_path, 'dir')
        mkdir(error_report_path);
    end
    
    report_file_name = [error_report_path tracker_name '_' runfile_name datestr(now,'_yymmdd_HHMM') '.mat'];
    
    save(report_file_name, 'err')
    
    rethrow(err);
end

5、附加的.m文件

choose_video.m

function video_name = choose_video(base_path)
%CHOOSE_VIDEO
%   Allows the user to choose a video (sub-folder in the given path).
%
	%process path to make sure it's uniform
	if ispc(), base_path = strrep(base_path, '\', '/'); end
	if base_path(end) ~= '/', base_path(end+1) = '/'; end
	
	%list all sub-folders
	contents = dir(base_path);
	names = {};
	for k = 1:numel(contents),
		name = contents(k).name;
		if isdir([base_path name]) && ~any(strcmp(name, {'.', '..'})),
			names{end+1} = name;  %#ok
		end
	end
	
	%no sub-folders found
	if isempty(names), video_name = []; return; end
	
	%choice GUI
	choice = listdlg('ListString',names, 'Name','Choose video', 'SelectionMode','single');
	
	if isempty(choice),  %user cancelled
		video_name = [];
	else
		video_name = names{choice};
	end
	
end

6、运行run_test.m,选择需要测试数据
在这里插入图片描述

7、再选择一次,技术不精,接口没定义好233333(两次选择同一个数据集)

在这里插入图片描述
8、需要等一段时间才能得到结果,鼠标点击进入下一帧,红色为真实值,绿色为DeepSTRCF跟踪结果
在这里插入图片描述

9、参考博客:https://blog.csdn.net/qq_17783559/article/details/82146259

10、vot_save.m把跟踪结果保存成VOT的数据格式,可以直接拷贝到vot-toolkit工具中使用。

11、或参考格式先自己运行代码得到数据集结果,再拷贝到vot-toolkit工具中分析也可以。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值