-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherc_definewoco_nofigure.m
102 lines (90 loc) · 4.16 KB
/
erc_definewoco_nofigure.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
% DEFINEWOCO_NOFIGURE - calculate the mapping from image to real world coordinates
%
% [comap,A1,world]=definewoco_nofigure(image,coordinatestyle)
%
%
% The final result will be saved to a file in the present work directory.
% The file is named 'worldcoX.mat', where the X is any number specified
% by the user. This option is for the cases where one might have two or
% more different coordinate systems in the same working directory. If this
% is not the case just press <enter> when asked for a number. The file will
% then be named 'worldco.mat'
%
% Copyright, J. Kristian Sveen, 1999-2004, last revision April 16, 2004
% For use with MatPIV 1.6.1
%
%Heavily modified by Damon Turney 2007
disp('Please enter an m x 2 array of [x y] pixel positions.')
disp('The upper left pixel location is [0 0], and bottom right is the largest pixel x,y values.')
disp('x refers to the horizontal direction. y refers to the vertical direction.')
disp('For example, in a 1280 wide x 1024 tall image, the bottom right is [1280 1024].')
camera=input('Enter the array here:');
x=camera(:,1)'+1;
y=camera(:,2)'+1;
%close(2)
fprintf('\n')
disp('Now enter an m x 2 array of real world locations corresponding to the pixel locations.')
world=input(['Enter the array here:']);
% Construct function for fitting.
inpx='inne';
while strcmp(inpx,'inne')
disp('')
disp('Please Enter a Mapping function.')
mapfun=input('(N)onlinear or (L)inear (N/n)/(L/l): ','s');
if strcmp(mapfun,'N')==1 | strcmp(mapfun,'n')==1
if length(world)>=6
camera=[ones(size(camera,1),1) camera(:,1) camera(:,2) (camera(:,1).*camera(:,2)) camera(:,1).^2 camera(:,2).^2];
inpx='ute';
else
disp('Not enough points specified to calculate nonlinear mapping factors.')
disp('Using linear mapping function.');
if length(world)>=3
camera=[ones(size(camera,1),1) camera];
inpx='ute';
elseif length(world)>1 & length(world)<3
disp('Only two points were specified. The linear mapping in the unspecified direction will be')
disp('assumed to be perpedicular and otherwise similar to that of the specified direction.')
camera=[camera ; [ (camera(2,2)-camera(1,2))+camera(1,1) -(camera(2,1)-camera(1,1))+camera(1,2)]];
world= [world ; [(-(world(2,2) -world(1,2)) +world(1,1)) ((world(2,1) -world(1,1)) +world(1,2))]];
camera=[ones(size(camera,1),1) camera];
inpx='ute';
else
disp('Not enough points specified. You need to specify two points at least.')
end
end
elseif strcmp(mapfun,'L')==1 | strcmp(mapfun,'l')==1
if length(world)>=3
camera=[ones(size(camera,1),1) camera];
inpx='ute';
elseif length(world)>1 & length(world)<3
disp('Only two points were specified. The linear mapping in the unspecified direction will be')
disp('assumed to be perpedicular and otherwise similar to that of the specified direction.')
camera=[camera ; [ (camera(2,2)-camera(1,2))+camera(1,1) -(camera(2,1)-camera(1,1))+camera(1,2)]];
world= [world ; [(-(world(2,2) -world(1,2)) +world(1,1)) ((world(2,1) -world(1,1)) +world(1,2))]];
camera=[ones(size(camera,1),1) camera];
inpx='ute';
else
disp('Not enough points specified. You need to specify two points at least.')
end
else
disp('Please specify mapping function (N or n)/(L or l)/(LL or ll):')
end
end
comap=(camera\world); % Fit using a minimization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% test for error
err=norm( (camera*comap-world));
disp(['Error (norm) = ',num2str(err)])
% give a warning if error is larger than a certain threshold
% 1 is just chosen as a test case. This needs testing.
if err>1e-5
disp(['WARNING! The minimized system of equations has a large ', ...
'error.'])
disp('Consider checking your world coordinate input')
if strcmp(mapfun,'L') | strcmp(mapfun,'l')
disp('Also consider using a nonlinear mapping function');
end
end
save('worldco','comap')
close %close window containing the image