-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeatureExtractor.m
73 lines (56 loc) · 2.25 KB
/
FeatureExtractor.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
function FeatureExtractor(in_folder, out_folder)
mat_files = GetTrackingInfoFiles(in_folder);
feature_file = fullfile(out_folder, 'MovieFeatures.mat');
if exist(feature_file, 'file')
load(feature_file);
else
features = struct();
end
for ix = 1:length(mat_files)
tracking_info_file = mat_files{ix};
load(tracking_info_file);
% The video file itself will have an .avi extension, which we have to
% replace with .mat.
[file_folder, video_filename, ~] = fileparts(tracker.videoFileName);
video_comments = fullfile(file_folder, [video_filename(1:end-4) '.mat']);
existing_feature = cellfun(@(s) strcmp(s, tracker.name), {features.name});
if any(existing_feature)
% If FPS doesn't exist:
feature_ix = find(existing_feature);
if ~isfield(features, 'fps') || isempty(features(feature_ix).fps)
load(video_comments);
fps = tracker.numberOfFrames / parameters.Duration;
features(feature_ix).fps = fps;
features(feature_ix).pixels_per_mm = ...
features(feature_ix).plate{2} * 2 / 90;
end
continue
end
% Load first image and show it, for the feature extraction to begin.
video_filename = tracker.videoFileName;
video = VideoReader(video_filename);
first_frame = readFrame(video);
if contains(tracking_info_file, '04-Feb-2018-18.42.52-Mic1-N2_-2_A')
% I played with the zoom at the beginning of the video, and it
% stabilized at the 300-th frame.
video = VideoReader(video_filename);
first_frame = read(video, 300);
end
imshow(first_frame);
features(end+1).name = tracker.name;
% We want two things - the plate and its center.
[plate_x, plate_y] = getpts;
[drop_x, drop_y] = getpts;
close;
[R, C, ~] = ExactMinBoundCircle(horzcat(plate_x, plate_y));
features(end).plate = {C R};
[R, C, ~] = ExactMinBoundCircle(horzcat(drop_x, drop_y));
features(end).drop = {C R};
load(video_comments);
fps = tracker.numberOfFrames / parameters.Duration;
features(end).fps = fps;
features(end).pixels_per_mm = ...
features(end).plate{2} * 2 / 90;
end
save(feature_file, 'features');
end