|
#!/bin/bash |
|
|
|
if [ "$1" = "" ]; then |
|
path=./ |
|
else |
|
path=$1 |
|
fi |
|
|
|
if [ "$2" = "" ]; then |
|
settings=settings.opts |
|
else |
|
settings=$2 |
|
fi |
|
|
|
if [ "$3" = "" ]; then |
|
opt=*.opts |
|
else |
|
opt=$3 |
|
fi |
|
|
|
cd "$path" |
|
|
|
while read line |
|
do |
|
vars=`echo $line | awk '{match($1,"(.+)=(.+)",a)}END{print a[1]}'` |
|
if [ "$vars" != "" ]; then |
|
eval ${vars}=`echo $line | awk '{match($1,"(.+)=(.+)",a)}END{print a[2]}'` |
|
fi |
|
done < $settings |
|
|
|
# fa la media dei dark frame, se presenti |
|
if [ -d dark ]; then |
|
convert dark/* -colorspace RGB -average master-dark.$extout |
|
fi |
|
|
|
for opts in `ls $opt`; do |
|
while read line |
|
do |
|
vars=`echo $line | awk '{match($1,"(.+)=(.+)",a)}END{print a[1]}'` |
|
if [ "$vars" != "" ]; then |
|
eval ${vars}=`echo $line | awk '{match($1,"(.+)=(.+)",a)}END{print a[2]}'` |
|
fi |
|
done < $opts |
|
|
|
# ci spostiamo nella dir che contiene le immagini grezze |
|
# e le rinominiamo con numeri consecutivi |
|
lowerext=$(echo $ext | awk '{print tolower($0)}') |
|
if [ -d base ]; then |
|
filesize=`ls base/$dir -m | wc -w` |
|
mkdir -p light/$dir |
|
echo "elaborazione di ${filesize} immagini nella directory ${dir}" |
|
ls base/$dir/*.$ext -tr | nl -nrz -w5 | while read newname oldname |
|
do |
|
cp $oldname light/$dir/$newname.$lowerext |
|
done |
|
else |
|
echo "La cartella non esiste" |
|
exit 1 |
|
fi |
|
|
|
if [ $elaborate = "true" ]; then |
|
mkdir -p elaborate/$dir |
|
for image in `ls light/$dir` |
|
do |
|
trans=$(echo $image | awk '{match($1, "(.*)\\.(.*)",a)}END{print a[1]}') |
|
if [ ! -d dark ]; then |
|
convert light/$dir/$image -colorspace RGB -level $level -gamma $gamma -unsharp $unsharp -quality 100 elaborate/$dir/$trans.$extout |
|
else |
|
convert master-dark.$extout light/$dir/$image -colorspace RGB -compose minus -composite -level $level -gamma $gamma -unsharp $unsharp -quality 100 elaborate/$dir/$trans.$extout |
|
fi |
|
done |
|
fi |
|
|
|
if [ $crop = "true" ]; then |
|
mkdir -p cropped/$dir |
|
if [ $timelapse = "true" ]; then |
|
mkdir -p timelapse |
|
fi |
|
filesize=`ls elaborate/$dir -m | wc -w` |
|
for image in `ls elaborate/$dir` |
|
do |
|
distx=$(($endx-$startx)) |
|
disty=$(($endy-$starty)) |
|
offsetx=$(($distx/$filesize)) |
|
offsety=$(($disty/$filesize)) |
|
coox=$(($startx-($sizex/2))) |
|
cooy=$(($starty-($sizey/2))) |
|
# calcolare gravity in base alla posizione immagine: |
|
gravity=Center |
|
# bordo basso per più della metà altezza nuova immagine: North |
|
if [ "$(($originalsizey-$starty))" -lt "$(($sizey/2))" ] && [ "$startx" -gt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -gt "$(($sizex/2))" ]; then |
|
gravity=North |
|
fi |
|
# bordo alto per più della metà altezza nuova immagine: South |
|
if [ "$starty" -lt "$(($sizey/2))" ] && [ "$startx" -gt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -gt "$(($sizex/2))" ]; then |
|
gravity=South |
|
fi |
|
# bordo sinistro per più della metà larghezza nuova immagine: East |
|
if [ "$startx" -lt "$(($sizex/2))" ] && [ "$starty" -gt "$(($sizey/2))" ] && [ "$(($originalsizey-$starty))" -gt "$(($sizey/2))" ]; then |
|
gravity=East |
|
fi |
|
# bordo destro per più della metà larghezza nuova immagine: West |
|
if [ "$(($originalsizex-$startx))" -lt "$(($sizex/2))" ] && [ "$starty" -gt "$(($sizey/2))" ] && [ "$(($originalsizey-$starty))" -gt "$(($sizey/2))" ]; then |
|
gravity=West |
|
fi |
|
# basso-sinistro: NorthEast |
|
if [ "$(($originalsizey-$starty))" -lt "$(($sizey/2))" ] && [ "$startx" -lt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -gt "$(($sizex/2))" ]; then |
|
gravity=NorthEast |
|
fi |
|
# alto-sinistro: SudEast |
|
if [ "$starty" -lt "$(($sizey/2))" ] && [ "$startx" -lt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -gt "$(($sizex/2))" ]; then |
|
gravity=SouthEast |
|
fi |
|
# alto-destro: SudWest |
|
if [ "$starty" -lt "$(($sizey/2))" ] && [ "$startx" -gt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -lt "$(($sizex/2))" ]; then |
|
gravity=SouthWest |
|
fi |
|
# basso-destro: NorthWest |
|
if [ "$(($originalsizey-$starty))" -lt "$(($sizey/2))" ] && [ "$startx" -gt "$(($sizex/2))" ] && [ "$(($originalsizex-$startx))" -lt "$(($sizex/2))" ]; then |
|
gravity=NorthWest |
|
fi |
|
|
|
trans=$(echo $image | awk '{match($1, "(.*)\\.(.*)",a)}END{print a[1]}') |
|
convert elaborate/$dir/$image -colorspace RGB -crop ${sizex}x$sizey+$coox+$cooy -background black -compose Copy -gravity $gravity -extent ${sizex}x$sizey -quality 100 cropped/$dir/$trans.$extout |
|
filesize=$(($filesize-1)) |
|
startx=$(($startx+$offsetx)) |
|
starty=$(($starty+$offsety)) |
|
echo "ancora ${filesize} immagini da elaborare" |
|
if [ $timelapse = "true" ]; then |
|
videosize=`ls video/ -m | wc -w` |
|
videosize=$(($videosize+1)) |
|
videofilename=`seq -f "%05g" $videosize $videosize` |
|
cp cropped/$dir/$trans.$extout timelapse/$videofilename.$extout |
|
fi |
|
done |
|
fi |
|
done |
|
|
|
if [ $timelapse = "true" ]; then |
|
cd timelapse |
|
ls *.$extout -tr | nl -nrz -w5 | while read newname oldname |
|
do |
|
cp $oldname $newname.$extout |
|
done |
|
videocom=`command -v avconv || command -v ffmpeg` |
|
echo "Creo il timelapse nel formato ${videoformat} con ${frame} al secondo" |
|
$videocom -r ${frame} -i "%05d.${extout}" -r ${frame} -s ${videoformat} -vcodec $vcodec -qscale 1 -y $videoname |
|
# if you want to "stabilize" the resulting video |
|
# you can use melt and vid.stab |
|
# instructions: |
|
# http://bernaerts.dyndns.org/linux/74-ubuntu/329-ubuntu-trusty-rotate-stabilize-video-melt-vidstab |
|
# http://public.hronopik.de/vid.stab/features.php?lang=en |
|
# install with: |
|
# sudo add-apt-repository ppa:sunab/kdenlive-release |
|
# sudo apt-get update |
|
# sudo apt-get install x264 melt |
|
if [ `command -v melt` ]; then |
|
melt $videoname -filter vidstab $vidstabParameter -consumer xml:input.mlt all=1 |
|
melt input.mlt -consumer avformat:stabilized-$videoname vcodec=libx264 b=$videobitrate acodec=aac ab=$audiobitrate tune=film preset=slow $meltCustomParameter |
|
fi |
|
fi |