1 Star 6 Fork 2

wycjl/kcf_matlab_apce

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
show_video.m 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
wycjl 提交于 2020-05-14 11:37 . 第一次提交
function update_visualization_func = show_video(img_files, video_path, resize_image)
%SHOW_VIDEO
% Visualizes a tracker in an interactive figure, given a cell array of
% image file names, their path, and whether to resize the images to
% half size or not.
%
% This function returns an UPDATE_VISUALIZATION function handle, that
% can be called with a frame number and a bounding box [x, y, width,
% height], as soon as the results for a new frame have been calculated.
% This way, your results are shown in real-time, but they are also
% remembered so you can navigate and inspect the video afterwards.
% Press 'Esc' to send a stop signal (returned by UPDATE_VISUALIZATION).
%
% Joao F. Henriques, 2014
% http://www.isr.uc.pt/~henriques/
%store one instance per frame
num_frames = numel(img_files);
boxes = cell(num_frames,1);
%create window
[fig_h, axes_h, unused, scroll] = videofig(num_frames, @redraw, [], [], @on_key_press); %#ok, unused outputs
set(fig_h, 'Name', ['Tracker - ' video_path])
axis off;
%image and rectangle handles start empty, they are initialized later
im_h = [];
rect_h = [];
update_visualization_func = @update_visualization;
stop_tracker = false;
function stop = update_visualization(frame, box)
%store the tracker instance for one frame, and show it. returns
%true if processing should stop (user pressed 'Esc').
boxes{frame} = box;
scroll(frame);
stop = stop_tracker;
end
function redraw(frame)
%render main image
im = imread([video_path img_files{frame}]);
if size(im,3) > 1,
im = rgb2gray(im);
end
if resize_image,
im = imresize(im, 0.5);
end
if isempty(im_h), %create image
im_h = imshow(im, 'Border','tight', 'InitialMag',200, 'Parent',axes_h);
else %just update it
set(im_h, 'CData', im)
end
%render target bounding box for this frame
if isempty(rect_h), %create it for the first time
rect_h = rectangle('Position',[0,0,1,1], 'EdgeColor','g', 'Parent',axes_h);
end
if ~isempty(boxes{frame}),
set(rect_h, 'Visible', 'on', 'Position', boxes{frame});
else
set(rect_h, 'Visible', 'off');
end
end
function on_key_press(key)
if strcmp(key, 'escape'), %stop on 'Esc'
stop_tracker = true;
end
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

搜索帮助