wolffd@0
|
1 % Let the user draw a square with the mouse,
|
wolffd@0
|
2 % and then click on the corners to do a manual segmentation
|
wolffd@0
|
3
|
wolffd@0
|
4 ss = 6;
|
wolffd@0
|
5 Q1 = 1; Q2 = 2; Q3 = 3; obsvel = 6;
|
wolffd@0
|
6 CLOCKWISE = 1; ANTICLOCK = 2;
|
wolffd@0
|
7 LR = 1; UD = 2; RL = 3; DU = 4;
|
wolffd@0
|
8
|
wolffd@0
|
9 % repeat this block manually incrementing the sequence number
|
wolffd@0
|
10 % and setting ori.
|
wolffd@0
|
11 % (since I don't know how to call getmouse as a call-return function).
|
wolffd@0
|
12 seq = 4;
|
wolffd@0
|
13 %ori = CLOCKWISE
|
wolffd@0
|
14 ori = ANTICLOCK;
|
wolffd@0
|
15 clear xpos ypos
|
wolffd@0
|
16 getmouse
|
wolffd@0
|
17 % end block
|
wolffd@0
|
18
|
wolffd@0
|
19 % manual segmentation with the mouse
|
wolffd@0
|
20 startseg(1) = 1;
|
wolffd@0
|
21 for i=2:4
|
wolffd@0
|
22 fprintf('click on start of segment %d\n', i);
|
wolffd@0
|
23 [x,y] = ginput(1);
|
wolffd@0
|
24 plot(x,y,'ro')
|
wolffd@0
|
25 d = dist2([xpos; ypos]', [x y]);
|
wolffd@0
|
26 startseg(i) = argmin(d);
|
wolffd@0
|
27 end
|
wolffd@0
|
28
|
wolffd@0
|
29 % plot corners in green
|
wolffd@0
|
30 %ti = first point in (i+1)st segment
|
wolffd@0
|
31 t1 = startseg(1); t2 = startseg(2); t3 = startseg(3); t4 = startseg(4);
|
wolffd@0
|
32 plot(xpos(t2), ypos(t2), 'g*')
|
wolffd@0
|
33 plot(xpos(t3), ypos(t3), 'g*')
|
wolffd@0
|
34 plot(xpos(t4), ypos(t4), 'g*')
|
wolffd@0
|
35
|
wolffd@0
|
36
|
wolffd@0
|
37 xvel = xpos(2:end) - xpos(1:end-1);
|
wolffd@0
|
38 yvel = ypos(2:end) - ypos(1:end-1);
|
wolffd@0
|
39 speed = [xvel(:)'; yvel(:)'];
|
wolffd@0
|
40 pos_data{seq} = [xpos(:)'; ypos(:)'];
|
wolffd@0
|
41 vel_data{seq} = [xvel(:)'; yvel(:)'];
|
wolffd@0
|
42 T = length(xvel);
|
wolffd@0
|
43 Q1label{seq} = num2cell(repmat(ori, 1, T));
|
wolffd@0
|
44 Q2label{seq} = zeros(1, T);
|
wolffd@0
|
45 if ori == CLOCKWISE
|
wolffd@0
|
46 Q2label{seq}(t1:t2) = LR;
|
wolffd@0
|
47 Q2label{seq}(t2+1:t3) = UD;
|
wolffd@0
|
48 Q2label{seq}(t3+1:t4) = RL;
|
wolffd@0
|
49 Q2label{seq}(t4+1:T) = DU;
|
wolffd@0
|
50 else
|
wolffd@0
|
51 Q2label{seq}(t1:t2) = RL;
|
wolffd@0
|
52 Q2label{seq}(t2+1:t3) = UD;
|
wolffd@0
|
53 Q2label{seq}(t3+1:t4) = LR;
|
wolffd@0
|
54 Q2label{seq}(t4+1:T) = DU;
|
wolffd@0
|
55 end
|
wolffd@0
|
56
|
wolffd@0
|
57 % pos_data{seq}(:,t), vel_data{seq}(:,t) Q1label{seq}(t) Q2label{seq}(t)
|
wolffd@0
|
58 save 'square4' pos_data vel_data Q1label Q2label
|
wolffd@0
|
59
|
wolffd@0
|
60 nseq = 4;
|
wolffd@0
|
61 cases = cell(1,nseq);
|
wolffd@0
|
62 for seq=1:nseq
|
wolffd@0
|
63 T = size(vel_data{seq},2);
|
wolffd@0
|
64 ev = cell(ss,T);
|
wolffd@0
|
65 ev(obsvel,:) = num2cell(vel_data{seq},1);
|
wolffd@0
|
66 ev(Q1,:) = Q1label{seq};
|
wolffd@0
|
67 ev(Q2,:) = num2cell(Q2label{seq});
|
wolffd@0
|
68 cases{seq} = ev;
|
wolffd@0
|
69 end
|
wolffd@0
|
70 save 'square4_cases' cases
|