-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawOpticalFlowLK_featrues.m
102 lines (61 loc) · 2.11 KB
/
drawOpticalFlowLK_featrues.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function drawOpticalFlowLK_featrues(imgpyr,features,map_camera_times,cam_id1,cam_id2,frame1,frame2)
img1=imgpyr{frame1}{1};
img2=imgpyr{frame2}{1};
timestamp1=map_camera_times(frame1,1)-map_camera_times(frame1,3);
timestamp2=map_camera_times(frame2,1)-map_camera_times(frame2,3);
allKeys = keys(features);
k=0;
pts1=[];
pts2=[];
for i = 1:length(allKeys)
key = allKeys{i}; % 获取当前键
feat = features(key);
frame1_timestamps=0;
if size(feat.timestamps{cam_id1},1)>1
for j=1:size(feat.timestamps{cam_id1},1)
if timestamp1==feat.timestamps{cam_id1}(j)
frame1_timestamps=j;
end
end
end
frame2_timestamps=0;
if size(feat.timestamps{cam_id2},1)>1
for j=1:size(feat.timestamps{cam_id2},1)
if timestamp2==feat.timestamps{cam_id2}(j)
frame2_timestamps=j;
end
end
end
if frame1_timestamps~=0 && frame2_timestamps~=0
k=k+1;
pts1=[pts1;feat.uvs{cam_id1}(frame1_timestamps,:)];
pts2=[pts2;feat.uvs{cam_id2}(frame2_timestamps,:)];
end
end
colors = jet(6);
figure;
imshow([img1,img2;img2,img2]);
hold on;
s=0;
for k=1:size(pts1,1)
s=s+1;
hold on
plot(pts1(k,1),pts1(k,2),'r+');
if mod(s,2)==0
hold on;
plot(pts2(k,1),pts2(k,2)+size(img1,1),'g+');
hold on;
plot([pts1(k,1),pts2(k,1)],[pts1(k,2),pts2(k,2)+size(img1,1)],'-', 'Color', colors(mod(s,6)+1,:));
else
hold on;
plot(pts2(k,1)+size(img1,2),pts2(k,2),'g+');
hold on;
plot([pts1(k,1),pts2(k,1)+size(img1,2)],[pts1(k,2),pts2(k,2)],'-', 'Color', colors(mod(s,6)+1,:));
end
hold on;
%quiver(pts{1}(j,1)+size(img1,2), pts{1}(j,2)+size(img1,1), pts{n}(k,1)-pts{1}(j,1), pts{n}(k,2)-pts{1}(j,2), 'r', 'LineWidth', 2);
plot([pts1(k,1)+size(img1,2),pts2(k,1)+size(img1,2)],[pts1(k,2)+size(img1,1),pts2(k,2)+size(img1,1)], 'r', 'LineWidth', 2);
end
title(['Optical Flow (Lucas-Kanade) image',num2str(frame1),' to image',num2str(frame2)]);
hold off;
end