-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatImage.m
152 lines (129 loc) · 4.8 KB
/
heatImage.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
clear;
clc;
D = 12.2;
H = 4.8;
global com;
com = serial('COM10','BaudRate',250000,'Terminator','CR');
com.InputBufferSize = 10000;
fopen(com);
% for n = 1:20
raw = fscanf(com);
cell = split(raw,",");
img = zeros(24,64);
imgL = zeros(24,32);
imgR = zeros(24,32);
for i = 0:23
for j = 1:32
imgR(i+1, j) = str2num(cell2mat(cell(64*i+j+1,1)));
end
for k = 33:64
imgL(i+1, k-32) = str2num(cell2mat(cell(64*i+k+1,1)));
end
end
senRight = axes(figure(1));
imagesc(imgR, 'Parent', senRight);
% colorbar;
title(senRight, 'Sensor right');
drawnow;
FR = getframe;
senLeft = axes(figure(2));
imagesc(imgL, 'Parent', senLeft);
% colorbar;
title(senLeft, 'Sensor left');
drawnow;
FL = getframe;
imgL = imresize(imgL,[360 480]);
imgR = imresize(imgR,[360 480]);
sigma = 5;
imageL = imgaussfilt(frame2im(FL),sigma);
imageR = imgaussfilt(frame2im(FR),sigma);
imageL = imresize(imageL,[360 480]);
imageR = imresize(imageR,[360 480]);
figure(3);
imageL = imadjust(imageL,[0.55 1],[]);
imageR = imadjust(imageR,[0.55 1],[]);
% imageL = imsharpen(imageL,'Radius',2,'Amount',10);
% imageR = imsharpen(imageR,'Radius',2,'Amount',10);
% imshowpair(imageL, imageR,'montage');
% title('Image 1 (left); Image 2 (right)');
Lgray = rgb2gray(imageL);
Rgray = rgb2gray(imageR);
% Lgray = edge(Lgray,'Roberts');
% Rgray = edge(Rgray,'Roberts');
imshowpair(Lgray, Rgray,'montage');
title('Image 1 (left); Image 2 (right)');
blobs1 = detectSURFFeatures(Lgray, 'MetricThreshold', 2000);
blobs2 = detectSURFFeatures(Rgray, 'MetricThreshold', 2000);
figure(4);
imshow(Rgray);
hold on;
plot(selectStrongest(blobs2, 30));
title('Thirty strongest SURF features in right sensor');
figure(5);
imshow(Lgray);
hold on;
plot(selectStrongest(blobs1, 30));
title('Thirty strongest SURF features in left sensor');
[features1, validBlobs1] = extractFeatures(Lgray, blobs1);
[features2, validBlobs2] = extractFeatures(Rgray, blobs2);
indexPairs = matchFeatures(features1, features2, 'Metric', 'SAD', ...
'MatchThreshold', 100);
matchedPoints1 = validBlobs1(indexPairs(:,1),:);
matchedPoints2 = validBlobs2(indexPairs(:,2),:);
figure(6);
showMatchedFeatures(imageL, imageR, matchedPoints1, matchedPoints2);
legend('Putatively matched points in left', ...
'Putatively matched points in right');
title('Putatively matched points');
if matchedPoints1.Count > 0 && matchedPoints2.Count > 0
xL = round(matchedPoints1.Location(1,1));
yL = round(matchedPoints1.Location(1,2));
xR = round(matchedPoints2.Location(1,1));
yR = round(matchedPoints2.Location(1,2));
temp = (imgL(round(yL),round(xL))+imgR(round(yR),round(xR)))/2;
alphaL = (xL - 240)*(55/480);
alphaR = (xR - 240)*(55/480);
beta = ((yR+yL)/2 - 180)*(35/360);
if alphaR >= 0 && alphaL <= 0
aL = 90 - abs(alphaL);
aR = 90 - alphaR;
x = ((D*tand(aR))/(tand(aL) + tand(aR)));
fx = x*tand(aL)
elseif alphaR >= 0 && alphaL >= 0
aL = 90 - alphaL;
aR = 90 - alphaR;
x = ((D*tand(aR))/(tand(aL) - tand(aR)));
fx = x*tand(aL)
else
aL = 90 - abs(alphaL);
aR = 90 - abs(alphaR);
x = ((D*tand(aR))/(tand(aR) - tand(aL)));
fx = x*tand(aL)
end
if beta < 0
fy = H + fx*tand(abs(beta))
else
fy = H - fx*tand(beta)
end
fx = fx/cosd(abs(beta))
% temperature = (temp+50)*(fx/30)*(fx/30)
temperature = temp*fx/10
end
% if matchedPoints1.Count > 0 && matchedPoints2.Count > 0
% xL = round(matchedPoints1.Location(1,1));
% yL = round(matchedPoints1.Location(1,2));
% xR = round(matchedPoints2.Location(1,1));
% yR = round(matchedPoints2.Location(1,2));
% end
% [fMatrix, epipolarInliers, status] = estimateFundamentalMatrix(...
% matchedPoints1, matchedPoints2, 'Method', 'RANSAC', ...
% 'NumTrials', 10000, 'DistanceThreshold', 0.1, 'Confidence', 99.99);
% if status ~= 0 || isEpipoleInImage(fMatrix, size(imageL)) ...
% || isEpipoleInImage(fMatrix', size(imageR))
% error(['Either not enough matching points were found or '...
% 'the epipoles are inside the images. You may need to '...
% 'inspect and improve the quality of detected features ',...
% 'and/or improve the quality of your images.']);
% end
% end
fclose(com);