-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathdemo_objectFlow.m
79 lines (66 loc) · 2.91 KB
/
demo_objectFlow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
% demo for video object segmentation in the paper: "Video Segmentation via Object Flow",
% Y.-H. Tsai, M.-H. Yang and M. J. Black, CVPR 2016.
clear all;
%% setups
setup_all;
para.seeResult = 1; % visualize results
para.saveResult = 0; % save binary masks as mat files
%% video data information
% change below for different videos
dataInfo.videoPath = 'Videos/';
dataInfo.videoName = 'aeroplane_001/';
dataInfo.gtName = 'gt/';
dataInfo.videoFormat = 'jpg';
dataInfo.gtFormat = 'jpg';
dataInfo.objId = 1; % choose to track which object according to the format of ground truths (can track multiple objects at the same time)
dataInfo.gtAll = 0; % select '0' if the ground truths are not available for all the frames (but at least require the first one)
%% pre-process data
dataInfo = preprocess_video(dataInfo, dirInfo, para);
inputPath = dataInfo.inputPath;
totalFrame = dataInfo.totalFrame;
%% load ground truths
gtPath = [inputPath dataInfo.gtName sprintf('%02d/', dataInfo.objId) '*.' dataInfo.gtFormat];
gtMask = cell(totalFrame,1);
list = dir(gtPath);
if dataInfo.gtAll == 1
% for complete ground truths (e.g., segTrack v2 dataset)
for ff = 1:totalFrame
tmp = imread([inputPath dataInfo.gtName sprintf('%02d/', dataInfo.objId) list(ff).name]);
% change below according to different ground truth formats
tmp = rgb2gray(tmp);
gtMask{ff} = (tmp>128);
end
else
% for incomplete ground truths (e.g., Youtube-Objects dataset)
for ff = 1:length(list)
tmp = imread([inputPath dataInfo.gtName sprintf('%02d/', dataInfo.objId) list(ff).name]);
% change below according to different ground truth formats
frame = str2double(list(ff).name(1:end-4));
gtMask{frame} = (double(tmp)>128);
end
end
dataInfo.gtMask = gtMask;
%% build the initial model
tic
fprintf('Build initial models...\n');
onlineModel = build_initial_model(dataInfo, dirInfo, para);
%% track segments from frame t to t+1
onlineModel.iou = 0;
fprintf('Start tracking segments...\n');
for ff = 1:totalFrame-1
%% build the online model
onlineModel.ff = ff;
onlineModel = build_online_model(onlineModel, dataInfo, dirInfo, para);
%% estimate the object location
onlineModel.video = dataInfo.videoAll(ff:ff+1); onlineModel.flows = dataInfo.flowsAll(ff); onlineModel.flowsInv = dataInfo.flowsInvAll(totalFrame-ff);
onlineModel = estimateObjectLoc(onlineModel, para);
%% track object segment
% 1) build the multi-level graph
% 2) compute potentials
% 3) solved by graph cut
onlineModel = objectSegmentTracking(onlineModel, para);
%% plot results
fprintf('Finish segmentating frame %d/%d in %f seconds.\n', ff, totalFrame-1, toc);
onlineModel = plotResult(onlineModel, dataInfo, dirInfo, para);
end
fprintf('finish segmetnting video: %s obj %d, average IOU: %f.\n\n',dataInfo.videoName(1:end-1), dataInfo.objId, onlineModel.iou/(totalFrame-1));