Skip to content

Commit

Permalink
update to correct version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffsan committed Mar 2, 2018
1 parent 5112e20 commit b18e176
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 102 deletions.
6 changes: 4 additions & 2 deletions tracking/getScalePatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% along with this program. If not, see <http://www.gnu.org/licenses/>.


function out = getScalePatch(img, pos, target_size, search_size, rotation, scale_model_sz, hog_scale_cell_size)
function out = getScalePatch(img, pos, target_size, search_size, scale_window, scale_model_sz, hog_scale_cell_size)

% code from DSST
padding=0;
Expand All @@ -25,7 +25,7 @@
end

tmp_sz = floor((target_size * (1 + padding))*search_size);
param0 = [pos(2), pos(1), tmp_sz(2)/target_size(2), rotation/180*pi,...
param0 = [pos(2), pos(1), tmp_sz(2)/target_size(2), 0,...
tmp_sz(1)/target_size(2)/(target_size(1)/target_size(2)),0];
param0 = affparam2mat(param0);
patch = warpimg(double(img), param0, target_size);
Expand All @@ -34,3 +34,5 @@
out = patch(:);




22 changes: 2 additions & 20 deletions tracking/getScaleSubwindow_v1.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen [email protected] Nanyang Technological University
% Zhang Le [email protected] Advanced Digital Sciences Center
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.


function out = getScaleSubwindow_v1(img, pos, target_size, search_size, rotation, scale_model_sz, hog_scale_cell_size)
function out = getScaleSubwindow_v1(img, pos, target_size, search_size, scale_window, scale_model_sz, hog_scale_cell_size)

% code from DSST
padding=0;
Expand All @@ -26,7 +8,7 @@
end
for s = 1:num_scales
tmp_sz = floor((target_size * (1 + padding))*search_size(s));
param0 = [pos(2), pos(1), tmp_sz(2)/target_size(2), rotation/180*pi,...
param0 = [pos(2), pos(1), tmp_sz(2)/target_size(2), 0,...
tmp_sz(1)/target_size(2)/(target_size(1)/target_size(2)),0];
param0 = affparam2mat(param0);
patch = warpimg(double(img), param0, target_size);
Expand Down
16 changes: 5 additions & 11 deletions tracking/params.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ params.learning_rate_pwp = 0.04; % bg and fg color models learning rat
params.inner_padding = 0.2; % defines inner area used to sample colors from the foreground
params.output_sigma_factor = 1/16 ; % standard deviation for the desired translation filter output
params.lambda = 1e-3;
params.lambda_scale = 1e-3; % regularization weight
params.lambda_scale = 0.1; % regularization weight
params.learning_rate_cf = 0.01; % HOG model learning rate
params.merge_factor = 0.3; % fixed interpolation factor - how to linearly combine the two responses
params.learning_rate_scale = 0.01 %0.025;
params.learning_rate_scale = 0.008 %0.025;
params.scale_sigma_factor = 1/16;
params.scale_sigma = 0.1;
params.num_scales = 33;
params.scale_step = 1.02;

params.num_rotation = 1;
params.rotation_step = 1;
params.rotation_sigma = 0.1;

params.num_scales = 11;
params.scale_step = 1.03;

% fixed setup
params.hog_scale_cell_size = 4; % Default DSST=4
params.scale_model_factor = 1.0;
params.scale_model_max_area = 32*16;
params.scale_model_max_area = 32*16; %32*16
params.feature_type = 'fhog';
params.scale_adaptation = true;
params.rotation_adaptation = 0;
params.grayscale_sequence = false; % suppose that sequence is colour
params.merge_method = 'const_factor';
params.den_per_channel = false;
Expand Down
81 changes: 12 additions & 69 deletions tracking/trackerMain_otb_wangchen.m
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen [email protected] Nanyang Technological University
% Zhang Le [email protected] Advanced Digital Sciences Center
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.


function [results] = trackerMain_otb_wangchen(p, im, bg_area, fg_area, area_resize_factor)
%TRACKERMAIN contains the main loop of the tracker, P contains all the parameters set in runTracker
%% INITIALIZATION
num_frames = numel(p.img_files);
num_frames = numel(p.img_files);
% used for OTB-13 benchmark
OTB_rect_positions = zeros(num_frames, 4);
pos = p.init_pos;
Expand Down Expand Up @@ -49,18 +31,11 @@
base_target_sz = target_sz;
scale_sigma = sqrt(p.num_scales) * p.scale_sigma_factor;
ss = (1:p.num_scales) - ceil(p.num_scales/2);
ys = exp(-0.5 * (ss.^2) / scale_sigma^2);

rotation_factor = 0;
ys=zeros(size(ss));
ys=zeros(size(ys));
ys(1)=1;
ysf = (fft(ys));

yr = zeros(p.num_rotation,1);
yr(1) = 1;
yrf = fft(yr);
rotation_factors = p.rotation_step*(-floor(p.num_rotation/2):floor(p.num_rotation/2));


ysf = ((fft(ys)));
if mod(p.num_scales,2) == 0
scale_window = single(hann(p.num_scales+1));
scale_window = scale_window(2:end);
Expand Down Expand Up @@ -137,14 +112,15 @@

%% SCALE SPACE SEARCH
if p.scale_adaptation
current_patch = getScalePatch(im, pos, base_target_sz, scale_factor, -rotation_factor, scale_model_sz, p.hog_scale_cell_size);
current_patch = getScalePatch(im, pos, base_target_sz, scale_factor, scale_window, scale_model_sz, p.hog_scale_cell_size);
ksf = gaussian_correlation_scale_single(im_patch_scale, current_patch, p.scale_sigma);
scale_response = abs(ifft((model_hsf.*ksf)));
scale_response = abs(ifft((model_hf.*ksf)));
[max_value, recovered_scale] = max(scale_response(:));

%set the scale
scale_factor = scale_factor / scale_factors(recovered_scale);

% fprintf('frame %d: recovered scale is %.2f:, current sclae factor is %.2f:\n', frame,recovered_scale,scale_factor)

if scale_factor < min_scale_factor
scale_factor = min_scale_factor;
elseif scale_factor > max_scale_factor
Expand All @@ -164,25 +140,6 @@
% same aspect ratio as the target bboxgetScaleSubwindow_v1
area_resize_factor = sqrt(p.fixed_area/prod(bg_area));
end

%% ROTATION SPACE SEARCH
if p.rotation_adaptation
current_rotation_patch = getRotationPatch(im, pos, base_target_sz, scale_factor, -rotation_factor, p.hog_scale_cell_size);
krf = gaussian_correlation_scale_single(im_patch_rotation, current_rotation_patch, p.rotation_sigma);
rotation_response = abs(ifft((model_hrf.*krf)));
[max_value, recovered_rotation] = max(rotation_response(:));

%set the scale
rotation_factor = rotation_factor + rotation_factors(recovered_rotation);
fprintf('frame %d: current sclae factor is %.4f; current rotation %.4f:\n', frame, scale_factor, rotation_factor)


if rotation_factor <= -180
rotation_factor = rotation_factor + 360;
elseif rotation_factor > 180
rotation_factor = rotation_factor - 360;
end
end

if p.visualization_dbg==1
mySubplot(2,1,5,1,im_patch_cf,'FG+BG','gray');
Expand Down Expand Up @@ -218,14 +175,14 @@
hf_den = (1 - p.learning_rate_cf) * hf_den + p.learning_rate_cf * new_hf_den;
hf_num = (1 - p.learning_rate_cf) * hf_num + p.learning_rate_cf * new_hf_num;

% BG/FG MODEL UPDATE
%% BG/FG MODEL UPDATE
% patch of the target + padding
[bg_hist, fg_hist] = updateHistModel(new_pwp_model, im_patch_bg, bg_area, fg_area, target_sz, p.norm_bg_area, p.n_bins, p.grayscale_sequence, bg_hist, fg_hist, p.learning_rate_pwp);
end

%% SCALE UPDATE
if p.scale_adaptation
im_patch_scale_frame = getScaleSubwindow_v1(im, pos, base_target_sz, scale_factors*scale_factor, -rotation_factor, scale_model_sz, p.hog_scale_cell_size);
im_patch_scale_frame = getScaleSubwindow_v1(im, pos, base_target_sz, scale_factors*scale_factor, scale_window, scale_model_sz, p.hog_scale_cell_size);

if frame == 1
im_patch_scale=im_patch_scale_frame;
Expand All @@ -234,24 +191,10 @@
end

ksf = gaussian_correlation_scale_single(im_patch_scale, im_patch_scale(:,uint8(size(im_patch_scale,2)/2)), p.scale_sigma);
model_hsf = ysf'./(ksf+0.1);
end

%% ROTATION UPDATE
if p.rotation_adaptation
im_patch_rotation_frame = getRotationSubwindow(im, pos, base_target_sz, scale_factor, rotation_factor + rotation_factors, p.hog_scale_cell_size);

if frame == 1
im_patch_rotation=im_patch_rotation_frame;
else
im_patch_rotation=(1 - p.learning_rate_scale)*im_patch_rotation + p.learning_rate_scale*im_patch_rotation_frame;
end

krf = gaussian_correlation_scale_single(im_patch_rotation, im_patch_rotation(:,uint8(size(im_patch_rotation,2)/2)), p.rotation_sigma);
model_hrf = yrf./(krf+0.1);
model_hf = ysf'./(ksf+0.1);
end

%% update bbox position
% update bbox position
if frame==1, rect_position = [pos([2,1]) - target_sz([2,1])/2, target_sz([2,1])]; end

rect_position_padded = [pos([2,1]) - bg_area([2,1])/2, bg_area([2,1])];
Expand Down

0 comments on commit b18e176

Please sign in to comment.