-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathB_gcpSelection.m
216 lines (141 loc) · 6.19 KB
/
B_gcpSelection.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
%% B_gcpSelection
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function initializes the GCP structure for a given camera. The user
% will load a distorted image, click on GCPS, and the function will save
% the distorted UVd coordinates and image metadata for a given camera.
% How to use clicking mechanism: The user can zoom and move the image how
% they please and then hit 'Enter' to begin clicking mode. A left click
% will select a point, a right click will delete the nearest point to the
% click. After a left click, the user will be asked to enter a GCP number
% to identify the GCP in the command window. The user can then zoom again
% until hitting enter to select the next point. To end the collection, hit
% enter to enter clicking mode (the cross hairs) and click below the image
% where it says 'Click Here to End Collection.' Be sure to be zoomed out
% completely when ending a collection. The user can click GCPs in any order
% they would like.
% Input:
% Input is entered by user into the script in Sections 1 and 2. Users will
% then enter information by clicking GCPs and entering an identifying
% number in the command window.
% Output:
% A .mat file saved as directory/filename as specified by the user.
% 'gcpUVdInitial' will be appended to the name. Will contain gcp
% structure.
% Required CIRN Functions:
% None
% Required MATLAB Toolboxes:
% None
% This function is to be run second in the progression for each camera in a
% multi-camera fixed station or UAS flight (or if a recording mode was
% changed midflight). GCP calibration should occur any time a camera has
% moved for a fixed station, the first frame in a new UAS collect, or
% intrinsics have changed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Housekeeping
close all
clear all
% User should make sure that X_CoreFunctions and subfolders are made active
% in their MATLAB path. Below is the standard location for demo, user will
% need to change if X_CoreFunctions is moved and/or the current script.
addpath(genpath('./X_CoreFunctions/'))
%% Section 1: User Input: Saving Information
% Enter the filename of the gcp .mat file that will be saved as. Name
% should be descriptive of the camera/recording mode as well as GCP
% deployment.
oname='uasDemo';
% Enter the directory where the mat file will be saved.
odir= './X_UASDemoData/extrinsicsIntrinsics/InitialValues';
%% Section 2: User Input: GCP Image
% Enter the filepath of the saved image for clicking. For UAS, this should
% be the first image of the collect.For fixed station, it should be any
% frame where GCPs are visible.
imagePath= './X_UASDemoData/collectionData/uasDemo_2Hz/uasDemo_1443742140000.tif';
%% Section 4: Clicking and Saving GCPS:
if isempty(imagePath)==0
% Display Image
f1=figure;
I=imread(imagePath);
[r c t]=size(I);
imagesc(1:c,1:r,I)
axis equal
xlim([0 c])
ylim([0 r])
xlabel({ 'Ud';'Click Here in Cross-Hair Mode To End Collection '})
ylabel('Vd')
hold on
% Clicking Mechanism
x=1;
y=1;
button=1;
UVclick=[];
while x<=c & y<=r % Clicking figure bottom will end clicking opportunity
% Allow User To Zoom
title('Zoom axes as Needed. Press Enter to Initiate Click')
pause
% Allow User to Click
title('Left Click to Save. Right Click to Delete')
[x,y,button] = ginput(1);
% If a left click, ask user for number, store, and display
if button==1 & (x<=c & y<=r)
% Plot GCP in Image
plot(x,y,'ro','markersize',10,'linewidth',3)
title('Enter GCP Number in Command Window')
% User Input for Number
num=input('Enter GCP Number:');
% Store Values
UVclick=cat(1,UVclick, [num x y]);
% Display GCP Number In Image
text(x+30,y,num2str(num),'color','r','fontweight','bold','fontsize',15)
% Display Values
disp(['GCP ' num2str(num) ' [U V]= [' num2str(x) ' ' num2str(y) ']'])
disp(' ')
figure(f1)
zoom out
end
% If a right click, program will delete nearest point, mark UVClick
% Entry as unusable with value -99.
if button==3 & (x<=c & y<=r)
% Find Nearest Marker
Idx = knnsearch(UVclick(:,2:3),[x y]);
% Turn the visual display off.
N=length(UVclick(:,1,1))*2+1; % Total Figure Children (Image+ 1 Text + 1 Marker for each Click)
f1.Children(1).Children(N-(Idx*2)).Visible='off'; % Turn off Text
f1.Children(1).Children(N-(Idx*2-1)).Visible='off'; % Turn off Marker
%Display Deleted GCP
disp(['Deleted GCP ' num2str(UVclick(Idx,1))]);
% Set UVclick GCP number to Unusable Value
UVclick(Idx,1)=-99;
zoom out
end
end
% Filter out values that were to be deleted
IND=find(UVclick(:,1) ~= -99);
UVsave=UVclick(IND,:);
% Sort so GCP Numbers are in order
[ia ic]=sort(UVsave(:,1));
UVsave(:,:)=UVsave(ic,:);
% Place in GCP Format
for k=1:length(UVsave(:,1))
gcp(k).UVd=UVsave(k,2:3);
gcp(k).num=UVsave(k,1);
end
end
%% Section 5: Display Results
close all
disp(['GCPs Entered for ' oname ':'])
disp(' ')
for k=1:length(gcp)
disp(['gcp(' num2str(k) ').num = ' num2str(gcp(k).num(1)) ] )
disp(['gcp(' num2str(k) ').UVd = [' num2str(gcp(k).UVd(1)) ' ' num2str(gcp(k).UVd(2)) ']'])
end
%% Section 6: Save File
% Incorporate imagePath in structure
for k=1:length(gcp)
if isempty(imagePath)==0
gcp(k).imagePath=imagePath;
else
gcp(k).imagePath=imagePath_noclick;
end
end
% Save Results
save([odir '/' oname '_gcpUVdInitial' ],'gcp')