1 Star 6 Fork 2

wycjl/kcf_matlab_apce

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
load_video_info.m 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
wycjl 提交于 2020-05-14 11:37 . 第一次提交
function [img_files, pos, target_sz, ground_truth, video_path] = load_video_info(base_path, video)
%LOAD_VIDEO_INFO
% Loads all the relevant information for the video in the given path:
% the list of image files (cell array of strings), initial position
% (1x2), target size (1x2), the ground truth information for precision
% calculations (Nx2, for N frames), and the path where the images are
% located. The ordering of coordinates and sizes is always [y, x].
%
% Joao F. Henriques, 2014
% http://www.isr.uc.pt/~henriques/
%see if there's a suffix, specifying one of multiple targets, for
%example the dot and number in 'Jogging.1' or 'Jogging.2'.
if numel(video) >= 2 && video(end-1) == '.' && ~isnan(str2double(video(end))),
suffix = video(end-1:end); %remember the suffix
video = video(1:end-2); %remove it from the video name
else
suffix = '';
end
%full path to the video's files
if base_path(end) ~= '/' && base_path(end) ~= '\',
base_path(end+1) = '/';
end
video_path = [base_path video '/'];
%try to load ground truth from text file (Benchmark's format)
filename = [video_path 'groundtruth_rect' suffix '.txt'];
f = fopen(filename);
assert(f ~= -1, ['No initial position or ground truth to load ("' filename '").'])
%the format is [x, y, width, height]
try
ground_truth = textscan(f, '%f,%f,%f,%f', 'ReturnOnError',false);
catch %#ok, try different format (no commas)
frewind(f);
ground_truth = textscan(f, '%f %f %f %f');
end
ground_truth = cat(2, ground_truth{:});
fclose(f);
%set initial position and size
target_sz = [ground_truth(1,4), ground_truth(1,3)];
pos = [ground_truth(1,2), ground_truth(1,1)] + floor(target_sz/2);
if size(ground_truth,1) == 1,
%we have ground truth for the first frame only (initial position)
ground_truth = [];
else
%store positions instead of boxes
ground_truth = ground_truth(:,[2,1]) + ground_truth(:,[4,3]) / 2;
end
%from now on, work in the subfolder where all the images are
video_path = [video_path 'img/'];
%for these sequences, we must limit ourselves to a range of frames.
%for all others, we just load all png/jpg files in the folder.
frames = {'David', 300, 770;
'Football1', 1, 74;
'Freeman3', 1, 460;
'Freeman4', 1, 283};
idx = find(strcmpi(video, frames(:,1)));
if isempty(idx),
%general case, just list all images
img_files = dir([video_path '*.png']);
if isempty(img_files),
img_files = dir([video_path '*.jpg']);
assert(~isempty(img_files), 'No image files to load.')
end
img_files = sort({img_files.name});
else
%list specified frames. try png first, then jpg.
if exist(sprintf('%s%04i.png', video_path, frames{idx,2}), 'file'),
img_files = num2str((frames{idx,2} : frames{idx,3})', '%04i.png');
elseif exist(sprintf('%s%04i.jpg', video_path, frames{idx,2}), 'file'),
img_files = num2str((frames{idx,2} : frames{idx,3})', '%04i.jpg');
else
error('No image files to load.')
end
img_files = cellstr(img_files);
end
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Matlab
1
https://gitee.com/19910509/kcf_matlab_apce.git
git@gitee.com:19910509/kcf_matlab_apce.git
19910509
kcf_matlab_apce
kcf_matlab_apce
master

搜索帮助