Created
March 3, 2020 11:14
-
-
Save johanjohan/ab25d92920c1353c317b1f638dbc8df4 to your computer and use it in GitHub Desktop.
convert equirectangular panoramas into cubemap tiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#----------------------------------------------------------------------------- | |
# | |
# ██████╗ ██╗ | |
# ╚════██╗ ██║ | |
# █████╔╝ ██║ | |
# ╚═══██╗██ ██║ | |
# ██████╔╝╚█████╔╝ | |
# ╚═════╝ ╚════╝ | |
# | |
# @johanjohan | |
# version 20200303 | |
# loop over dirs looking for equirectangular panoramic png files | |
# and convert these equirectangular panoramas into cubemap tiles | |
# | |
# erect2cubic --erect=equi.png --ptofile=cubic.pto | |
# nona -v -o cubicBasename cubic.pto | |
# | |
# 0000 front | |
# 0001 right | |
# 0002 back | |
# 0003 left | |
# 0004 top | |
# 0005 bottom | |
# | |
# https://metacpan.org/release/Panotools-Script | |
# erect2cubic - creates a hugin .pto file for converting equirectangular to cubic | |
# erect2mercator - Extract a mercator projection from an equirectangular image | |
# erect2planet - Extract a stereographic 'little planet' from an equirectangular image | |
# erect2qtvr - Assemble a Quicktime QTVR file from an equirectangular image | |
# | |
# http://standard-input.blogspot.com/2009/09/convert-rectilinear-panoramas-to-cubic.html | |
# sudo apt-get update | |
# sudo apt-get update --fix-missing | |
# sudo apt-get upgrade | |
# sudo apt install hugin-tools | |
# sudo apt install libgraphviz-perl | |
# | |
# sudo cpan install CPAN | |
# sudo cpan App::cpanminus | |
# | |
# sudo perl -MCPAN -e shell | |
# install Term::ReadLine::Perl | |
# install Term::ReadKey | |
# install Panotools::Script | |
# | |
#----------------------------------------------------------------------------- | |
### script path | |
# cd /mnt/v/00shared/dev8/OF/of_v0.9.8_vs_release/apps/STAUB_098/023-erect2cubic-linux | |
### pano path | |
# cd /mnt/s/GSV/trbovlje/data/sqlite/ofx3jGoogleStreetViewPanos/centerOnly_z4/t_panos_geoSpiral_hot2Chimney_5_00_m/google | |
# function to convert passed list "$@" | |
foo() { | |
for fullpath in "$@" | |
do | |
filename="${fullpath##*/}" # Strip longest match of */ from start | |
dir="${fullpath:0:${#fullpath} - ${#filename}}" # Substring from 0 thru pos of filename | |
base="${filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end | |
ext="${filename:${#base} + 1}" # Substring from len of base thru end | |
if [[ -z "$base" && -n "$ext" ]]; then # If we have an extension and no base, it's really the base | |
base=".$ext" | |
ext="" | |
fi | |
echo -e "$fullpath:\n\tdir = \"$dir\"\n\tbase = \"$base\"\n\text = \"$ext\"" | |
# create pto | |
pto=$dir$base".pto" | |
echo -e "\tpto = $pto\n" | |
erect2cubic --erect=$fullpath --ptofile=$pto | |
# create cubics -v | |
cubicbase=$dir$base"_cubic_" | |
nona -v -o $cubicbase $pto | |
done | |
} | |
export -f foo | |
SEARCH_DIR="/mnt/s/GSV/trbovlje/data/sqlite/ofx3jGoogleStreetViewPanos/centerOnly_z4/t_panos_geoSpiral_hot2Chimney_5_00_m/google" | |
echo "SEARCH_DIR: $SEARCH_DIR" | |
# duration | |
SECONDS=0 | |
# find pano .png files (exclude depth maps and cubics) and execute foo() with list of filenames | |
find \ | |
$SEARCH_DIR \ | |
-iname '*.png' \ | |
-not -name '*_depthMap*' \ | |
-not -name '*_cubic*' \ | |
-exec bash -c 'foo "$@"' bash {} + | |
#----------------------------------------------------------------------------- | |
# takes about 8 seconds per pano of resolution 6k | |
duration=$SECONDS | |
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed." | |
#----------------------------------------------------------------------------- | |
echo "" | |
echo "all done. press return..." | |
read input_variable | |
exit 0 | |
#----------------------------------------------------------------------------- | |
#----------------------------------------------------------------------------- | |
#----------------------------------------------------------------------------- | |
#----------------------------------------------------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment