forked from DeNardoLab/BehaviorDEPOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoInterface.m
59 lines (53 loc) · 1.77 KB
/
videoInterface.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
function [frame, frame1, frame_idx, P] = videoInterface(video_name, P)
% warn user this may take a while
disp('Loading video. May take some time depending on size of video.')
% Create video object (.avi or .mp4)
vid = VideoReader(video_name);
% Save info to P
P.Video.name = vid.Name;
P.Video.length = vid.Duration;
P.Video.frameRate = vid.FrameRate;
if isempty(P.gapThreshold)
P.gapThreshold = P.Video.frameRate;
end
P.Video.totalFrames = vid.NumFrames;
P.Video.frameWidth = vid.Width;
P.Video.frameHeight = vid.Height;
disp('Video Loaded');
P.Video.location = video_name;
% load frames
frame_idx = randi(vid.numFrame,1); % take random frame to verify tracking
frame = read(vid, frame_idx);
frame1 = read(vid, 1); % take first frame for trajectory plotting
% Draw ROI
P.roi_limits = [];
roi_name = [];
if P.do_ROI
for r = 1:P.number_ROIs
disp(['Select ROI # ' num2str(r)]);
imshow(frame)
title(['Select ROI # ' num2str(r)]);
roi = drawpolygon;
P.roi_limits{r} = roi.Position;
close;
prompt = {'Assign name to ROI'}; % give name to ROI
dlgtitle = 'Input';
dims = [1 40];
definput = {''};
name = inputdlg(prompt,dlgtitle,dims,definput);
name = cleanText(name); % removes non alphanumeric chars
roi_name{r} = char(name);
end
end
P.roi_name = roi_name;
% Draw arena floor
P.arena_floor = [];
if P.do_wallrearing_classifier
figure;
imshow(frame);
title('Select arena floor');
roi = drawpolygon;
P.arena_floor = roi.Position;
close;
end
end