-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpano-smaller.sh
More file actions
executable file
·347 lines (278 loc) · 9.47 KB
/
pano-smaller.sh
File metadata and controls
executable file
·347 lines (278 loc) · 9.47 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/bin/bash
#
# Prepare smaller panorama which does not wrap around
#
#
set -e
set -o pipefail
set -u
# see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
echo -n "Checking available commands:"
for i in nona enblend pto_gen pano_modify cpfind cpclean autooptimiser pto_var vig_optimize convert
do
echo -n " $i"
command -v $i >/dev/null 2>&1 || { echo >&2 " | ERROR: Command $i not found, exiting"; exit 1; }
done
show_pano_layout_py="$(dirname "$0")/show-pano-layout.py"
echo
echo -n " $show_pano_layout_py"
if [ ! -f "$show_pano_layout_py" ] ; then
echo >&2 " | ERROR: script not found, exiting"
exit 1
fi
echo
echo " All commands found"
echo
CONVERTCMD=convert
if command -v magick >/dev/null 2>&1; then
CONVERTCMD=magick
echo "Use $CONVERTCMD for imagemagick convert"
fi
echo
echo
echo
DOBLEND=true
DOSHOWLAYOUT=true
FIRSTANCHOR=false
function usage {
echo
echo "Usage: $0 [-h] [-nb]"
echo
echo " -h Print this usage and exit"
echo " -nb Skip stitching and blending final panorama"
echo " -nl Skip rendering layout image"
echo " -fa Use first image as anchor instead of the middle one"
echo
echo
}
# from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while [[ $# -gt 0 ]]; do
case $1 in
-nb)
DOBLEND=false
echo "Will not stitch / blend"
shift
;;
-fa)
FIRSTANCHOR=true
echo "Will use first image as anchor instead of the middle one"
shift
;;
-nl)
DOSHOWLAYOUT=false
echo "Will not render layout image"
shift
;;
-h)
usage
exit
;;
*)
echo "ERROR! Unknown option \"$1\""
usage
exit 1
;;
esac
done
if [ -f ./p1.jpg ] ; then
echo 'p1.jpg exists; exiting'
exit 0
fi
if compgen -G "*.tif" > /dev/null; then
echo "tif file found; exiting: $(compgen -G "*.tif")"
exit 0
fi
LOG=pano.log
# Initial settings
# PMFOV=""
# PMCRP=""
# PMCTR=""
PMFOV="--fov=AUTO"
PMCRP="--crop=AUTO"
PMCTR="--center"
STARTSEC=$(date "+%s")
function sect {
TS=$(date "+%Y-%m-%d %H:%M:%S")
DT=$(( $(date "+%s") - $STARTSEC ))
DTF=$(printf "%5d" $DT)
echo | tee -a "${LOG}"
echo | tee -a "${LOG}"
echo "+--[ ${TS}, ${DTF} s ]--------------------------------------------------------------------------------------" | tee -a "${LOG}"
echo "|" | tee -a "${LOG}"
while [ $# -gt 0 ] ; do echo "| $1" | tee -a "${LOG}"; shift; done
echo "|" | tee -a "${LOG}"
echo "| DT: ${DT} s" | tee -a "${LOG}"
echo "|" | tee -a "${LOG}" ;
echo "+------------------------------------------------------------------------------------------------------------------------" | tee -a "${LOG}"
echo | tee -a "${LOG}" ;
echo | tee -a "${LOG}"
}
function blprev {
sect "Launch stitch/blend preview" "pwd: $(pwd)" "Input file: $1" "Output basename: $2"
if [ ! -e "$1" ]; then
echo "ERROR! No input pto file specified, exiting"
exit -1
fi
if [ -z "$2" ]; then
echo "ERROR! No output basename specified, exiting"
exit -1
fi
if [ ! -d "workfiles" ] ; then
echo "Create workfiles/ dir"
mkdir workfiles/
fi
# Nona tif prefix
#NONAO=workfiles/`basename "${PO}" ".pto"`-
NONAO="workfiles/${2}-"
# Blended output file
#ENBLO=workfiles/`basename "${PO}" ".pto"`-blend.tif
ENBLO="workfiles/${2}-blend.tif"
JPG="workfiles/${2}-blend.jpg"
if [ ! -f "${ENBLO}" ] && [ ! -f "${JPG}" ] ; then
sect "Stitch with nona" "pwd: $(pwd)" "NONAO: \"${NONAO}\"" "ENBLO: \"${ENBLO}\"" "JPG: \"${JPG}\""
nona -o "${NONAO}" -m TIFF_m "${PO}" -v --ignore-exposure 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
sect "Blend with enblend" "pwd: $(pwd)" "ENBLO: \"${ENBLO}\"" "JPG: \"${JPG}\""
enblend -v -o "${ENBLO}" "${NONAO}"*.tif 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
# enblend -o "${ENBLO}" "${NONAO}"*.tif > /dev/null
sect "Enblend returned"
else
sect "Enblend output already exists, skipping stitch / blend" "pwd: $(pwd)" "ENBLO: \"${ENBLO}\""
fi
if [ ! -f "${JPG}" ] ; then
sect "Create JPG from last stitch" "pwd: $(pwd)" "ENBLO: \"${ENBLO}\"" "JPG: \"${JPG}\""
$CONVERTCMD "${ENBLO}" -quality 100 "${JPG}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
else
sect "JPG already exists; skipping JPG conversion" "pwd: $(pwd)" "ENBLO: \"${ENBLO}\"" "JPG: \"${JPG}\""
fi
}
sect "Prepare panorama initial workflow" " pwd: $(pwd)"
if [ ! -d "sources/" ]
then
echo "Create sources/ dir; move sources"
mkdir sources/
mv *.[jJ][pP][gG] sources/
fi
AUTO_OUT_JPG=./$(basename "$(pwd)")-auto.jpg
if [ -f "$AUTO_OUT_JPG" ] ; then
sect "Final auto out \"${AUTO_OUT_JPG}\" exists, exiting"
exit 0
fi
if [ -f workfiles/p1-blend.jpg ] ; then
# Can be hit when final output created manually
sect "workfiles/p1-blend.jpg exists; skipping PTO building toolchain" "PWD: $(pwd)"
if [ ! -f "$AUTO_OUT_JPG" ] ; then
echo "Copy final out to \"$AUTO_OUT_JPG\""
cp workfiles/p1-blend.jpg "$AUTO_OUT_JPG"
fi
exit 0
fi
# input PTO file
PI=""
PO=""
# panorama out counter
POCT=0;
# roll PTO files
# $1 - short name, will be part of new output file name
# $2 - description, will be printed
function newPto() {
if [ -z "$1" ]; then
echo "ERROR: No short name specified, exiting."
exit -1
fi
if [ -z "$2" ]; then
echo "ERROR: No human readable description specified, exiting."
exit -1
fi
PI="${PO}"
PO="sources/pano-$(printf '%02d' $POCT)-$1.pto"
POCT=$(( $POCT + 1))
sect "$2" " pwd: $(pwd)" " PI: ${PI}" " PO: ${PO}"
}
if [ "$FIRSTANCHOR" = true ] ; then
echo "Use first image as anchor"
ANCHORNUM=0
else
# see https://stackoverflow.com/questions/21143043/find-count-of-files-matching-a-pattern-in-a-directory-in-linux
IMGCOUNT=$(ls -1 sources/*.[jJ][pP][gG] | wc -l)
ANCHORNUM=$(( $IMGCOUNT / 2 ))
echo "Use middle image as anchor. IMGCOUNT=${IMGCOUNT}, ANCHORNUM=${ANCHORNUM}"
fi
newPto "initial" "pto-gen from source JPGs"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pto_gen -o "${PO}" sources/*.[jJ][pP][gG] 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "initial-c" "modify canvas size to fov 360 x 180 4k x 2k"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pano_modify -o "${PO}" --fov=360x180 --canvas=4000x2000 "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "cpfind" "cpfind"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
cpfind -o "${PO}" --multirow "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "celeste" "celeste"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
celeste_standalone -i "${PI}" -o "${PO}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "cpclean" "cpclean"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
cpclean -o "${PO}" "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "anchor" "set anchor image to ${ANCHORNUM}"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pto_var -o "${PO}" "--anchor=${ANCHORNUM}" "--color-anchor=${ANCHORNUM}" "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "pwopted" "do pairwise optimization"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
autooptimiser -p -o "${PO}" "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "pwopted-m" "modify: straighten, center, fov"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pano_modify -o "${PO}" --straighten $PMCTR $PMFOV $PMCRP "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "geomopt" "set geometry optimization"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pto_var -o "${PO}" --opt y,p,r,v,a,b,c "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "geomopted" "do geometry optimization"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
autooptimiser -n -o "${PO}" "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
newPto "geomopted-m" "modify: straighten, center, fov"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pano_modify -o "${PO}" --straighten $PMCTR $PMFOV $PMCRP "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
# newPto "vignopt" "set photometric optimization (vignetting)"
# pto_var -o "${PO}" --modify-opt --opt Ra,Rb,Rc,Rd,Re,Vb,Vc,Vd,Vx,Vy "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
#
# newPto "vignopted" "do photometric optimization"
# vig_optimize -o "${PO}" -v -p 5000 "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
newPto "final" "set final canvas size and crop"
if [ -f "${PO}" ] ; then echo " Output file ${PO} exists; skipping" ; else
pano_modify -o "${PO}" --straighten $PMCTR --canvas=AUTO $PMFOV $PMCRP "${PI}" 2>&1 | sed -ue "s/^/ /" | tee -a "${LOG}"
fi
if [ "$DOSHOWLAYOUT" = true ] ; then
LAYOUT_PNG="${PO%.pto}-layout.png"
sect "Create layout visualization" " pwd: $(pwd)" " input: ${PO}" " Output: ${LAYOUT_PNG}"
if [ -f "${LAYOUT_PNG}" ]; then echo " Output file ${LAYOUT_PNG} exists; skipping" ; else
"$show_pano_layout_py" -i "${PO}" -o "${LAYOUT_PNG}"
fi
else
echo
echo
echo "Skipping layout visualization"
echo
echo
fi
if [ "$DOBLEND" = true ] ; then
# Final blend
blprev "${PO}" p1
sect "Copy output to \"$AUTO_OUT_JPG\""
cp workfiles/p1-blend.jpg "$AUTO_OUT_JPG"
else
echo
echo
echo "Skipping stitch/blend"
echo
echo
fi
sect "All done."