forked from luc-girod/MicMacWorkflowsByLucGirod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrone3D.sh
executable file
·190 lines (165 loc) · 7.56 KB
/
Drone3D.sh
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
#Workflow MICMAC for nadir drone survey
#
# Luc Girod, University of Oslo - luc.girod@geo.uio.no
#This file is a workflow for drone images taken at nadir (or close to nadir) containing GNSS location data. It was created and tested using images from a DJI Mavic Pro and should run for all similar drones (other DJI products for instance), and also for more "serious" aerial photography systems.
#I would like to remind users that an along-track overlap of 80% and across track overlap of 60% are the minimum recommended values.
# example:
# ./DroneNadir.sh -e JPG -u "32 +north" -r 0.1
# add default values
EXTENSION=JPG
X_OFF=0;
Y_OFF=0;
utm_set=false
do_ply=true
do_AperiCloud=true
use_Schnaps=true
resol_set=false
ZoomF=2
obliqueFolder=none
regul=0
CleanUp=0
while getopts "e:x:y:u:spcao:r:z:t:h" opt; do
case $opt in
h)
echo "Run the workflow for drone acquisition at nadir (and pseudo nadir) angles)."
echo "usage: DroneNadir.sh -e JPG -x 55000 -y 6600000 -u \"32 +north\" -p true -r 0.05"
echo " -e EXTENSION : image file type (JPG, jpg, TIF, png..., default=JPG)."
echo " -x X_OFF : X (easting) offset for ply file overflow issue (default=0)."
echo " -y Y_OFF : Y (northing) offset for ply file overflow issue (default=0)."
echo " -u UTMZONE : UTM Zone of area of interest. Takes form 'NN +north(south)'"
echo " -s SH : Do not use 'Schnaps' optimised homologous points."
echo " -p do_ply : use to NOT export ply file."
echo " -c regul : use to activate color equalization in mosaicking (only do with good camera, eg NOT DJI)."
echo " -a do_AperiCloud : use to NOT export AperiCloud file."
echo " -o obliqueFolder : Folder with oblique imagery to help orientation (will be entierely copied then deleted during process)."
echo " -r RESOL : Ground resolution (in meters)"
echo " -z ZoomF : Last step in pyramidal dense correlation (default=2, can be in [8,4,2,1])"
echo " -t Clean-up : Remove most temporary files after the process is over (Option 0(default)=no 1=allows for further processing 2=keep only final files"
echo " -h : displays this message and exits."
echo " "
exit 0
;;
e)
EXTENSION=$OPTARG
;;
u)
UTM=$OPTARG
utm_set=true
;;
r)
RESOL=$OPTARG
resol_set=true
;;
s)
use_Schnaps=false
;;
p)
do_ply=false
;;
c)
regul=1
;;
a)
do_AperiCloud=false
;;
o)
obliqueFolder=$OPTARG
;;
x)
X_OFF=$OPTARG
;;
y)
Y_OFF=$OPTARG
;;
z)
ZoomF=$OPTARG
;;
t)
CleanUp=$OPTARG
;;
\?)
echo "DroneNadir.sh: Invalid option: -$OPTARG" >&1
exit 1
;;
:)
echo "DroneNadir.sh: Option -$OPTARG requires an argument." >&1
exit 1
;;
esac
done
if [ "$utm_set" = false ]; then
echo "UTM zone not set"
exit 1
fi
if [ "$use_Schnaps" = true ]; then
echo "Using Schnaps!"
SH="_mini"
else
echo "Not using Schnaps!"
SH=""
fi
#create UTM file (after deleting any existing one)
rm SysUTM.xml
echo "<SystemeCoord> " >> SysUTM.xml
echo " <BSC> " >> SysUTM.xml
echo " <TypeCoord> eTC_Proj4 </TypeCoord> " >> SysUTM.xml
echo " <AuxR> 1 </AuxR> " >> SysUTM.xml
echo " <AuxR> 1 </AuxR> " >> SysUTM.xml
echo " <AuxR> 1 </AuxR> " >> SysUTM.xml
echo " <AuxStr> +proj=utm +zone="$UTM "+ellps=WGS84 +datum=WGS84 +units=m +no_defs </AuxStr> " >> SysUTM.xml
echo " " >> SysUTM.xml
echo " </BSC> " >> SysUTM.xml
echo "</SystemeCoord> " >> SysUTM.xml
#Copy everything from the folder with oblique images
if [ "obliqueFolder" != none ]; then
cp $obliqueFolder/* .
fi
#Convert all images to tif (BW and RGB) for use in AperiCloud (because it otherwise breaks if too many CPUs are used)
if [ "$do_AperiCloud" = true ]; then
DevAllPrep.sh
fi
#Get the GNSS data out of the images and convert it to a txt file (GpsCoordinatesFromExif.txt)
echo "mm3d XifGps2Txt .*$EXTENSION"
mm3d XifGps2Txt .*$EXTENSION
#Get the GNSS data out of the images and convert it to a xml orientation folder (Ori-RAWGNSS), also create a good RTL (Local Radial Tangential) system.
echo "mm3d XifGps2Xml .*$EXTENSION RAWGNSS"
mm3d XifGps2Xml .*$EXTENSION RAWGNSS
#Use the GpsCoordinatesFromExif.txt file to create a xml orientation folder (Ori-RAWGNSS_N), and a file (FileImagesNeighbour.xml) detailing what image sees what other image (if camera is <50m away with option DN=50)
echo "mm3d OriConvert "#F=N X Y Z" GpsCoordinatesFromExif.txt RAWGNSS_N ChSys=DegreeWGS84@RTLFromExif.xml MTD1=1 NameCple=FileImagesNeighbour.xml DN=100"
mm3d OriConvert "#F=N X Y Z" GpsCoordinatesFromExif.txt RAWGNSS_N ChSys=DegreeWGS84@RTLFromExif.xml MTD1=1
#Find Tie points using 1/2 resolution image (best value for RGB bayer sensor)
echo "mm3d Tapioca MulScale .*JPG 500 2000"
mm3d Tapioca MulScale .*JPG 500 2000
if [ "$use_Schnaps" = true ]; then
#filter TiePoints (better distribution, avoid clogging)
echo "mm3d Schnaps .*$EXTENSION MoveBadImgs=1"
mm3d Schnaps .*$EXTENSION MoveBadImgs=1
fi
#Compute Relative orientation (Arbitrary system)
echo "mm3d Tapas FraserBasic .*$EXTENSION Out=Arbitrary SH=$SH"
mm3d Tapas FraserBasic .*$EXTENSION Out=Arbitrary SH=$SH
#Visualize relative orientation, if apericloud is not working, run
if [ "$do_AperiCloud" = true ]; then
echo "mm3d AperiCloud .*$EXTENSION Ori-Arbitrary SH=$SH "
mm3d AperiCloud .*$EXTENSION Ori-Arbitrary SH=$SH
fi
#Transform to RTL system
echo "mm3d CenterBascule .*$EXTENSION Arbitrary RAWGNSS_N Ground_Init_RTL"
mm3d CenterBascule .*$EXTENSION Arbitrary RAWGNSS_N Ground_Init_RTL
#Bundle adjust using both camera positions and tie points (number in EmGPS option is the quality estimate of the GNSS data in meters)
echo "mm3d Campari .*$EXTENSION Ground_Init_RTL Ground_RTL EmGPS=[RAWGNSS_N,5] AllFree=1 SH=$SH"
mm3d Campari .*$EXTENSION Ground_Init_RTL Ground_RTL EmGPS=[RAWGNSS_N,5] AllFree=1 SH=$SH
#Visualize Ground_RTL orientation
if [ "$do_AperiCloud" = true ]; then
echo "mm3d AperiCloud .*$EXTENSION Ori-Ground_RTL SH=$SH"
mm3d AperiCloud .*$EXTENSION Ori-Ground_RTL SH=$SH
fi
#Change system to final cartographic system
echo "mm3d ChgSysCo .*$EXTENSION Ground_RTL RTLFromExif.xml@SysUTM.xml Ground_UTM"
mm3d ChgSysCo .*$EXTENSION Ground_RTL RTLFromExif.xml@SysUTM.xml Ground_UTM
#Print out a text file with the camera positions (for use in external software, e.g. GIS)
echo "mm3d OriExport Ori-Ground_UTM/O.*xml CameraPositionsUTM.txt AddF=1"
mm3d OriExport Ori-Ground_UTM/O.*xml CameraPositionsUTM.txt AddF=1
#Correlation into 3D cloud
echo " mm3d C3DC BigMac ".*.$EXTENSION" Ground_UTM OffsetPly=[$X_OFF,$Y_OFF,0]"
mm3d C3DC BigMac ".*.$EXTENSION" Ground_UTM OffsetPly=[$X_OFF,$Y_OFF,0]