Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
sampleAerielleVideoDemoPIX -- uses pixel toolbox to make pixel insts. Various tweaks and some new functions to deal with this.
  • Loading branch information
jstanleyx authored Mar 17, 2017
1 parent c0e6822 commit fbfd8a6
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 32 deletions.
6 changes: 4 additions & 2 deletions Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
%
% Support minor routines
% findUVnDOF - find U,V for any xyz using n dof geometry
% DJIFindXYZ6dof - find XYZ for any UV using 6 dof geometry
% DJIUndistort - convert from distorted to undistorted coords
% findXYZ6dof - find XYZ for any UV using 6 dof geometry
% undistort - convert from distorted to undistorted coords
% distort - convert from undistorted to distorted
% makeUAVPn - create good pathnames for CIL expectations
% makefr - used in distortion, f(r).
% makeRadDist - radial distance for distortion calcs
% makeTangDist - tangential distance for distortion calcs
% lcpBeta2P - build a P matrix from lcp and beta (angles)
%
% CILroutines that are called
% findXYZ - find XYZ for any UV
Expand Down
2 changes: 2 additions & 0 deletions buildRectProducts.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
images.dark(:,:,i) = bar;
end
images.N(good) = images.N(good)+1;

end

%
% Copyright (C) 2017 Coastal Imaging Research Network
Expand Down
4 changes: 4 additions & 0 deletions demoInputFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
inputs.gcpFn = [pwd, filesep, 'demoGCPFile.mat'];
inputs.instsFn = [pwd, filesep,'demoInstsFile']; % instrument m-file location

inputs.pnIn = '/tmp/foo/UAV-Processing-Toolbox-master/demoMovies';
inputs.dayFn = '271_Oct.01';
inputs.pncx = inputs.pnIn;

% 2. Geometry solution Inputs:
% The six extrinsic variables, the camera location and viewing angles
% in the order [ xCam yCam zCam Azimuth Tilt Roll].
Expand Down
49 changes: 49 additions & 0 deletions distortCaltech.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function [ud,vd] = distortCaltech(u,v,lcp)
% [ud,vd] = DJIDistort(u,v,lcp)
%
% converts from undistorted to distorted pixel locations for a DJI phantom.
% This is based on equations from the Caltech lens distortion manuals.
% lcp contains all the relevant intrinsic as well as radial and tangential
% distortion coefficients.

% written Dec 2015, updated from a now obsolete version that used a single
% lens calibration for the largest (chip size) image while converting from
% smaller image types. This was found not to work for phantom 3s.

% find the range dependent correction factor, fr.
x = (u(:)-lcp.c0U)/lcp.fx; % normalize to tanAlpha
y = (v(:)-lcp.c0V)/lcp.fy;
r2 = x.*x + y.*y; % distortion found based on Large format units
fr = interp1(lcp.r,lcp.fr,sqrt(r2));
dx = interp2(lcp.x,lcp.y,lcp.dx,x,y);
dy = interp2(lcp.x,lcp.y,lcp.dy,x,y);
x2 = x.*fr + dx;
y2 = y.*fr + dy;
ud = x2*lcp.fx+lcp.c0U; % answer in chip pixel units
vd = y2*lcp.fy+lcp.c0V;


%
% Copyright (C) 2017 Coastal Imaging Research Network
% and Oregon State University

% This program is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, version 3 of the
% License.

% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.

% You should have received a copy of the GNU General Public License
% along with this program. If not, see
% <http://www.gnu.org/licenses/>.

% CIRN: https://coastal-imaging-research-network.github.io/
% CIL: http://cil-www.coas.oregonstate.edu
%
%key UAVProcessingToolbox
%

4 changes: 4 additions & 0 deletions findCOMRefObj.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
uv = round(findUVnDOF(beta,xyz(i,:),meta.globals));
URef = [uv(1)-dUV(1,1): uv(1)+dUV(1,1)];
VRef = [uv(2)-dUV(1,2): uv(2)+dUV(1,2)];
% you may not go off the edge!
VRef = VRef( find(VRef>0)); VRef = VRef( find(VRef<size(I,1)+1));
URef = URef( find(URef>0)); URef = URef( find(URef<size(I,2)+1));

I2 = I(VRef,URef);
[U,V] = meshgrid(URef,VRef);
good = find(I2>thresh(i));
Expand Down
11 changes: 2 additions & 9 deletions findUVnDOF.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,12 @@
end
lcp = globs.lcp;

K = [lcp.fx 0 lcp.c0U;
0 -lcp.fy lcp.c0V;
0 0 1];

R = angles2R(b2(4), b2(5), b2(6));
IC = [eye(3) -b2(1:3)'];
P = K*R*IC;
P = P/P(3,4); % unnecessary since we will also normalize UVs
P = lcpBeta2P( lcp, b2 );

UV = P*[xyz'; ones(1,size(xyz,1))];
UV = UV./repmat(UV(3,:),3,1);

[U,V] = DJIDistort(UV(1,:),UV(2,:),lcp);
[U,V] = distort(UV(1,:),UV(2,:),lcp);
UV = [U; V];

%
Expand Down
12 changes: 3 additions & 9 deletions findXYZ6dof.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
% extrinsic parameters [xyzCam azimuth tilt roll] where angles are in
% radians. lcp and image size NU, NV are also needed.

[u2,v2] = DJIUndistort(U(:),V(:),lcp); % undistort
[u2,v2] = undistort(U(:),V(:),lcp); % undistort

% build projection matrix in chip pixels
K = [lcp.fx 0 lcp.c0U; % chip scale K
0 -lcp.fy lcp.c0V;
0 0 1];

R = angles2R(b(4), b(5), b(6));
IC = [eye(3) -b(1:3)'];
P = K*R*IC;
P = P/P(3,4); % unnecessary since we will also normalize UVs
P = lcpBeta2P( lcp, b );

m = P2m(P);
xyz = findXYZ(m,[u2 v2], z, 3);

Expand Down
48 changes: 48 additions & 0 deletions lcpBeta2GeomCamIp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function [geom, cam, ip] = lcpBeta2GeomCamIp( lcp, beta )

% function [cam, geom, ip] = lcpBeta2GeomCamIp( lcp, beta )
%
% use the lcp and beta values to create the cam, geom, and ip structs
% that the PIXEL toolbox uses to build a collect (findUV, findXYX).

% step 1, make a P, then get the m from it.
P = lcpBeta2P( lcp, beta );
m = P2m( P );

cam.cameraNumber = 1;
cam.x = beta(1);
cam.y = beta(2);
cam.z = beta(3);
cam.lcp = lcp;

geom.m = m;
geom.azimuth = beta(4);
geom.fov = -1;

ip.width = lcp.NU;
ip.height = lcp.NV;


%
% Copyright (C) 2017 Coastal Imaging Research Network
% and Oregon State University

% This program is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, version 3 of the
% License.

% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.

% You should have received a copy of the GNU General Public License
% along with this program. If not, see
% <http://www.gnu.org/licenses/>.

% CIRN: https://coastal-imaging-research-network.github.io/
% CIL: http://cil-www.coas.oregonstate.edu
%
%key UAVProcessingToolbox
%
44 changes: 44 additions & 0 deletions lcpBeta2P.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function P = lcpBeta2P( lcp, beta )

% function P = lcpBeta2P( lcp, beta )
%
% create a P matrix from the lcp and beta
%
% used by findUV6DOF and findXYZnDOF and to make things
% for pixel toolbox geometry.

K = [lcp.fx 0 lcp.c0U;
0 -lcp.fy lcp.c0V;
0 0 1];

R = angles2R(beta(4), beta(5), beta(6));
IC = [eye(3) -beta(1:3)'];
P = K*R*IC;
P = P/P(3,4); % unnecessary since we will also normalize UVs

return;


%
% Copyright (C) 2017 Coastal Imaging Research Network
% and Oregon State University

% This program is free software: you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation, version 3 of the
% License.

% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.

% You should have received a copy of the GNU General Public License
% along with this program. If not, see
% <http://www.gnu.org/licenses/>.

% CIRN: https://coastal-imaging-research-network.github.io/
% CIL: http://cil-www.coas.oregonstate.edu
%
%key UAVProcessingToolbox
%
67 changes: 67 additions & 0 deletions makePixelInstsDemo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function r = makePixelInstsDemo( )

% Make pixel instruments using pixel toolbox. duplicate of demoInstsFile.

PIXForget;
PIXSetStation('aerielle');

zmsl = 0;

instID = [];

% vbar insts
y = [450 700];
x = [125:25:225];

for ii=1:length(x)

name = ['vbar' num2str(x(ii))];
tid = PIXMakeVBAR( x(ii), y(1), x(ii), y(2), zmsl, name);
instID = [instID tid];

end

% runup
xshore = 125;
xdune = 70;
y = 60:50:650;
rot = 0;

for ii=1:length(y)
[xr, yr, zr] = runupPIXArray( xshore, xdune, y(ii), zmsl, rot );
name = ['runup' num2str(fix(y(ii)))];
tid = PIXCreateInstrument( name, 'runup', PIXFixedZ+PIXUniqueOnly );
PIXAddPoints( tid, xr, yr, zr, name );
instID = [instID tid];
end

% cBathy
dx = 5;
dy = 5;
x1 = 80;
x2 = 400;
y1 = 450;
y2 = 900;

tid = PIXCreateInstrument( 'mBW', 'matrix', PIXFixedZ+PIXDeBayerStack );
PIXAddMatrix( tid, x1, y1, x2, y2, zmsl, dx, dy );
instID = [instID tid];

% stability slices
tid = PIXCreateInstrument( 'x300Slice', 'line', PIXFixedZ+PIXUniqueOnly );
PIXAddLine( tid, 300, 500, 300, 540, 7, .1, 'x300Slice' );
instID = [instID tid];
tid = PIXCreateInstrument( 'y517Slice', 'line', PIXFixedZ+PIXUniqueOnly );
PIXAddLine( tid, 100, 520, 115, 520, 7, .1, 'y517Slice' );
instID = [instID tid];


% make a package of all insts
pid = PIXCreatePackage('AerielleDemo', instID);
e = matlab2Epoch(now);

% build the initial r
r = PIXCreateR( pid, e, zmsl, 'none' );

end

Loading

0 comments on commit fbfd8a6

Please sign in to comment.