-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtracking_tongue.m
51 lines (43 loc) · 1.2 KB
/
tracking_tongue.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
close all
clear variables
opticFlow = opticalFlowFarneback;
%Different views have different ROIs. Uncomment in order to track the required view.
r = [367.5 350.5 361 365]; %midtest
%r = [135.5 479.5 367 261]; %ltest
%r= [595.5 431.5 412 302]; %rtest
frameRGB = readFrame(vidReader);
frameRGB = imcrop(frameRGB,r);
frameGray = rgb2gray(frameRGB);
pointTracker = vision.PointTracker('MaxBidirectionalError',1);
cp=1;
rp=1;
initialize(pointTracker,[cp rp],frameGray);
count=1;
while hasFrame(vidReader)
frameRGB1 = readFrame(vidReader);
frameRGB = imcrop(frameRGB1,r);
frameGray = rgb2gray(frameRGB);
frameGray=imsharpen(frameGray);
flow = estimateFlow(opticFlow,frameGray);
[row,col]=find(flow.Magnitude == max(flow.Magnitude(:)));
imshow(frameGray)
if max(flow.Magnitude(:))>=6
cp=col;
rp=row;
release(pointTracker);
initialize(pointTracker,[cp rp],frameGray)
else
[pt,point_validity] = pointTracker(frameGray);
cp=pt(1);
rp=pt(2);
end
hold on
plot(cp, rp, 'ro', 'MarkerSize', 30);
hold off
drawnow
prevc=cp;
prevr=rp;
mpoints(count,1)=cp;
mpoints(count,2)=rp;
count=count+1;
end