Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@

script to map 6 skybox cubemap faces into an equirectangular projection with ffmpeg v360 filter. This script adds automatically exif tags of 360 equirectangular pano view, this allows to view the pano in viewers like Ricoh Theta https://play.google.com/store/apps/details?id=com.theta360&hl=en&gl=US

this script is also able to convert a skybox into a cubemap in cross or strip layout, compatible with Unity and other engines.

the default size of equirectangular image result is 4 * (cube face width) width.
height of equirectangular image is the half of width.

`sky2equi.sh` is the main tool
`sky2cross.sh` and `sky2strip.sh` are also available

`mattersky2equi.sh` is a tool to simplify the conversion for matterport skybox downloaded with https://github.com/fdd4s/matterport-downloader
e.g: to convert all skybox downloaded to a equirectangular:

$ ls -1 pan*skybox1*jpg | awk ' { print "\"" $0 "\""; } ' | xargs -n 1 ./mattersky2equi.sh
$ ls -1 pan*skybox1*jpg | awk ' { print "\"" $0 "\" equi"; } ' | xargs -n 2 ./matterskyconv.sh

or just

$ ls -1 pan*skybox1*jpg | awk ' { print "\"" $0 "\""; } ' | xargs -n 2 ./matterskyconv.sh

to convert all skybox downloaded to a cross cubemap:

$ ls -1 pan*skybox1*jpg | awk ' { print "\"" $0 "\" cross"; } ' | xargs -n 2 ./matterskyconv.sh

to convert all skybox downloaded to a strip cubemap:

$ ls -1 pan*skybox1*jpg | awk ' { print "\"" $0 "\" strip"; } ' | xargs -n 2 ./matterskyconv.sh

(both sh scripts and skyboxs must be in the same folder)

Expand All @@ -26,18 +41,22 @@ this code is designed to work over linux (as /dev/shm ram tmpfs)

## Usage

$ ./sky2equi.sh <front> <back> <right> <left> <top> <bottom> <equirectangular> [<width>]
$ ./sky2equi.sh <front> <back> <right> <left> <top> <bottom> <equirectangular> [<width>]
$ ./sky2cross.sh <front> <back> <right> <left> <top> <bottom> <cross> [<width>]
$ ./sky2strip.sh <front> <back> <right> <left> <top> <bottom> <strip> [<width>]

## Examples

$ ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg
$ ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg 4096
$ ./sky2cross.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg cross.jpg
$ ./sky2strip.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg strip.jpg

## Known issues

"montage-im6.q16: cache resources exhausted " can be resolved changing ImageMagick configuration, more info here: https://github.com/ImageMagick/ImageMagick/issues/396

## Viewers
## Equirectangular Viewers

Android: Ricoh Theta App https://play.google.com/store/apps/details?id=com.theta360&hl=en&gl=US

Expand Down
20 changes: 0 additions & 20 deletions mattersky2equi.sh

This file was deleted.

54 changes: 54 additions & 0 deletions matterskyconv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

if [ "$#" -lt "1" ] || [ "$#" -gt "3" ] ; then
echo "usage: ./mattersky2equi.sh <one matterport skybox> [<width>] [<format>]"
echo "e.g: ./mattersky2equi.sh pan-high-1-skybox0.jpg"
echo " ./mattersky2equi.sh pan-high-1-skybox0.jpg 4096"
echo " ./mattersky2equi.sh pan-high-1-skybox0.jpg 4096 strip"
echo "formats: equi (default) | strip | cross"
exit 0
fi

name=$(echo $* | awk -F skybox ' { print $1; } ')

# Parse arguments more flexibly
width=""
format="equi" # default format

# Check if we have a second argument
if [ "$2" != "" ]; then
# If it's numeric, it's the width, otherwise it's the format
if [[ $2 =~ ^[0-9]+$ ]]; then
width=$2
format=${3:-equi}
else
format=$2
width=$3
fi
fi

echo "name is $name"
echo "format is $format"
echo "width is $width"

ts0=$(date +%s)

case $format in
"equi")
./sky2equi.sh "$name"skybox1.jpg "$name"skybox3.jpg "$name"skybox4.jpg "$name"skybox2.jpg "$name"skybox0.jpg "$name"skybox5.jpg "$name"equi.jpg $width
;;
"strip")
./sky2strip.sh "$name"skybox1.jpg "$name"skybox3.jpg "$name"skybox4.jpg "$name"skybox2.jpg "$name"skybox0.jpg "$name"skybox5.jpg "$name"strip.jpg $width
;;
"cross")
./sky2cross.sh "$name"skybox1.jpg "$name"skybox3.jpg "$name"skybox4.jpg "$name"skybox2.jpg "$name"skybox0.jpg "$name"skybox5.jpg "$name"cross.jpg $width
;;
*)
echo "Invalid format: $format. Using default (equi)"
script="./sky2equi.sh"
;;
esac

ts1=$(date +%s)
let "dif = $ts1 - $ts0"
echo "Time elapsed $dif seconds"
35 changes: 35 additions & 0 deletions sky2cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

if [ "$#" -lt "7" ] || [ "$#" -gt "8" ] ; then
echo "usage: ./sky2equi.sh <front> <back> <right> <left> <top> <bottom> <equirectangular> [<width>]"
echo "e.g: ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg"
echo " ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg 4096"
exit 0
fi

if [ -f "$7" ]; then
echo "$7 already exists"
exit 0
fi

if [ "$#" -eq "7" ] ; then
WIDTH_SRC0=$(identify "$1" | awk ' { print $3; } ' | awk -F x ' { print $1; } ')
let "WIDTH = $WIDTH_SRC0 * 4"
else
WIDTH=$8
fi

let "HEIGHT = $WIDTH / 2"

if [ "$HEIGHT" -lt "100" ] || [ "$HEIGHT" -gt "100000" ] ; then
echo "size out of range"
exit 0
fi

convert -size $(identify -format "%wx%h" "$4") xc:none empty.png

montage "empty.png" "$5" "empty.png" "empty.png" "$3" "$1" "$4" "$2" "empty.png" "$6" "empty.png" "empty.png" -tile 4x3 -geometry +0+0 -background none "$7"

echo "$7 created"


33 changes: 33 additions & 0 deletions sky2strip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

if [ "$#" -lt "7" ] || [ "$#" -gt "8" ] ; then
echo "usage: ./sky2equi.sh <front> <back> <right> <left> <top> <bottom> <equirectangular> [<width>]"
echo "e.g: ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg"
echo " ./sky2equi.sh f.jpg b.jpg r.jpg l.jpg t.jpg b.jpg equi.jpg 4096"
exit 0
fi

if [ -f "$7" ]; then
echo "$7 already exists"
exit 0
fi

if [ "$#" -eq "7" ] ; then
WIDTH_SRC0=$(identify "$1" | awk ' { print $3; } ' | awk -F x ' { print $1; } ')
let "WIDTH = $WIDTH_SRC0 * 4"
else
WIDTH=$8
fi

let "HEIGHT = $WIDTH / 2"

if [ "$HEIGHT" -lt "100" ] || [ "$HEIGHT" -gt "100000" ] ; then
echo "size out of range"
exit 0
fi

montage "$4" "$3" "$5" "$6" "$1" "$2" -tile 6x1 -geometry x+0+0 "$7"

echo "$7 created"