Skip to content

Commit

Permalink
clean up codes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffsanC committed Mar 8, 2018
1 parent 6857dd2 commit 33b2358
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 79 deletions.
16 changes: 9 additions & 7 deletions tracking/getScalePatch.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
function out = getScalePatch(img, pos, target_size, search_size, scale_window, scale_model_sz, hog_scale_cell_size)
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen wang.chen@zoho.com Nanyang Technological University
% Zhang Le zhang.le@adsc.com Advanced Digital Sciences Center
% This program is free software: you can redistribute it and/or modify
%
% This file is part of KCC.
%
% KCC 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,
%
% KCC 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 = getScalePatch(img, pos, target_size, search_size, scale_window, scale_model_sz, hog_scale_cell_size)
% along with KCC. If not, see <http://www.gnu.org/licenses/>.

% code from DSST
padding=0;
if size(img,3)>1
img= single(rgb2gray(img))/255.0;
Expand Down
23 changes: 21 additions & 2 deletions tracking/getScaleSubwindow.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
function out = getScaleSubwindow(im, pos, base_target_sz, scale_factors, scale_window, scale_model_sz, hog_scale_cell_size)

% code from DSST

% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen wang.chen@zoho.com Nanyang Technological University
% Zhang Le zhang.le@adsc.com Advanced Digital Sciences Center
%
% This file is part of KCC.
%
% KCC 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.
%
% KCC 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 KCC. If not, see <http://www.gnu.org/licenses/>.
num_scales = length(scale_factors);

for s = 1:num_scales
Expand Down
23 changes: 21 additions & 2 deletions tracking/getScaleSubwindow_v1.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
function out = getScaleSubwindow_v1(img, pos, target_size, search_size, scale_window, scale_model_sz, hog_scale_cell_size)

% code from DSST
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen wang.chen@zoho.com Nanyang Technological University
% Zhang Le zhang.le@adsc.com Advanced Digital Sciences Center
%
% This file is part of KCC.
%
% KCC 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.
%
% KCC 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 KCC. If not, see <http://www.gnu.org/licenses/>.
padding=0;
num_scales = length(search_size);
if size(img,3)>1
Expand Down
22 changes: 21 additions & 1 deletion tracking/run_KCC.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
function results = run_KCC(seq, res_path, bSaveImage)
% Entry point for the Wu - CVPR2013 benchmark
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen wang.chen@zoho.com Nanyang Technological University
% Zhang Le zhang.le@adsc.com Advanced Digital Sciences Center
%
% This file is part of KCC.
%
% KCC 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.
%
% KCC 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 KCC. If not, see <http://www.gnu.org/licenses/>.

%% Read params.txt
params = readParams('params.txt');
Expand Down
23 changes: 22 additions & 1 deletion tracking/trackerMain_otb_wangchen.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
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
% KCC: Kernel Cross-Correlator
% Visual Tracking Using KCC
%
% Copyright (C) 2017
% Author: Wang Chen wang.chen@zoho.com Nanyang Technological University
% Zhang Le zhang.le@adsc.com Advanced Digital Sciences Center
%
% This file is part of KCC.
%
% KCC 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.
%
% KCC 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 KCC. If not, see <http://www.gnu.org/licenses/>.

%% INITIALIZATION
num_frames = numel(p.img_files);
% used for OTB-13 benchmark
Expand Down
39 changes: 6 additions & 33 deletions tracking/utility/affparam2geom.m
Original file line number Diff line number Diff line change
@@ -1,45 +1,18 @@
function q = affparam2geom(p)
% function q = affparam2geom(p)
%
% 输入 : p,原始参数矩阵;
% 输出 : q,具有几何意义的参数;
% The functions affparam2geom and affparam2mat convert a 'geometric'
% affine parameter to/from a matrix form (2x3 matrix).
%
% affparam2geom converts a 2x3 matrix to 6 affine parameters
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse.
%
% p(6) : [p(1) p(3) p(4); p(2) p(5) p(6)]
%
% x' p(3) p(4) p(1) x
% y' = p(5) p(6) p(2) * y
% 1 0 0 1 1
%
% p(3) p(4)
% A =
% p(5) p(6)
%
% q(6) : [dx dy sc th sr phi]
% dx,dy : 平移变换
% sc,sr : 尺度变换
% th : 旋转变换
% phi : 错切变换
%
% Reference "Multiple View Geometry in Computer Vision" by Richard
% Hartley and Andrew Zisserman.

% Copyright (C) Jongwoo Lim and David Ross. All rights reserved.

A = [ p(3), p(4); p(5), p(6) ];
%% A = USVt = (UVt)(VSVt) = R(th)R(-phi)SR(phi)

[U,S,V] = svd(A);
if (det(U) < 0)
U = U(:,2:-1:1); V = V(:,2:-1:1); S = S(2:-1:1,2:-1:1);
end
%%*******平移变换*******%%


q(1) = p(1);
q(2) = p(2);
%%*******平移变换*******%%


q(4) = atan2(U(2,1)*V(1,1)+U(2,2)*V(1,2), U(1,1)*V(1,1)+U(1,2)*V(1,2));

Expand All @@ -53,10 +26,10 @@
R = [c -s; s c]; V = V * R; S = R'*S*R;
end

%%*******尺度变换*******%%

q(3) = S(1,1);
q(5) = S(2,2)/S(1,1);
%%*******尺度变换*******%%

q(6) = atan2(V(1,2),V(1,1));

q = reshape(q, size(p));
16 changes: 0 additions & 16 deletions tracking/utility/affparam2mat.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
function q = affparam2mat(p)
% function q = affparam2mat(p)
%
% The functions affparam2geom and affparam2mat convert a 'geometric'
% affine parameter to/from a matrix form (2x3 matrix).
%
% 输入 : q,具有几何意义的参数;
% 输出 : p,原始参数矩阵;
%
% affparam2geom converts a 2x3 matrix to 6 affine parameters
% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse.
%
% p(6,n) : [dx dy sc th sr phi]'
% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)]
%
% Reference "Multiple View Geometry in Computer Vision" by Richard
% Hartley and Andrew Zisserman.

% Copyright (C) Jongwoo Lim and David Ross. All rights reserved.

Expand Down
6 changes: 3 additions & 3 deletions tracking/utility/box_to_p.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
[w,h] = deal(varargin{1:2});
varargin(1:2) = [];
end
%%***********获得宽,高***********%%


if (length(varargin) < 1 )%|| any(length(varargin{1}) ~= 2))
M = [0,1,0; 0,0,1];
else
corners = cell2mat(varargin{1});
varargin(1) = [];
% M = [p(1) p(3) p(4); p(2) p(5) p(6)]; %%affine变换参数
% M = [p(1) p(3) p(4); p(2) p(5) p(6)];
end

%----------------------------------------------------------
Expand All @@ -33,7 +33,7 @@
W = [ 1,-w/2,-h/2; 1,w/2,-h/2; 1,w/2,h/2; 1,-w/2,h/2; 1,-w/2,-h/2 ]';
M = corners/W;

p = [M(1,1), M(2,1),M(1,2),M(1,3),M(2,2),M(2,3) ]; %%中心
p = [M(1,1), M(2,1),M(1,2),M(1,3),M(2,2),M(2,3) ];

end

8 changes: 4 additions & 4 deletions tracking/utility/p_to_box.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[w,h] = deal(varargin{1:2});
varargin(1:2) = [];
end
%%***********获得宽,高***********%%


if (length(varargin) < 1 || any(length(varargin{1}) ~= 6))
M = [0,1,0; 0,0,1];
Expand All @@ -27,12 +27,12 @@
else
varargin(1) = [];
end
M = [p(1) p(3) p(4); p(2) p(5) p(6)]; %%affine变换参数
M = [p(1) p(3) p(4); p(2) p(5) p(6)];
end

%----------------------------------------------------------
% Draw the box.
%----------------------------------------------------------
corners = [ 1,-w/2,-h/2; 1,w/2,-h/2; 1,w/2,h/2; 1,-w/2,h/2; 1,-w/2,-h/2 ]';
corners = M * corners; %%顶点
center = mean(corners(:,1:4),2); %%中心
corners = M * corners;
center = mean(corners(:,1:4),2);
13 changes: 3 additions & 10 deletions tracking/utility/warpimg.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
function wimg = warpimg(img, p, sz)
% function wimg = warpimg(img, p, sz)
%
% img(h,w) : 原始图像
% p(6,n) : 仿射参数 mat format
% sz(th,tw) : 提取块大小
%

%% Copyright (C) 2005 Jongwoo Lim and David Ross.
%% All rights reserved.

Expand All @@ -20,9 +13,9 @@
pos = reshape(cat(2, ones(h*w,1),x(:),y(:)) ...
* [p(1,:) p(2,:); p(3:4,:) p(5:6,:)], [h,w,n,2]);
wimg = squeeze(interp2(img, pos(:,:,:,1), pos(:,:,:,2)));
%%pos(:,:,:,1) : x坐标矩阵
%%pos(:,:,:,2) : y坐标矩阵
wimg(find(isnan(wimg))) = 0; %%去掉个别坏点


wimg(find(isnan(wimg))) = 0;

% B = SQUEEZE(A) returns an array B with the same elements as
% A but with all the singleton dimensions removed. A singleton
Expand Down

0 comments on commit 33b2358

Please sign in to comment.