Advertisement
daredevil82

Panorama Generation Script

Apr 29th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.17 KB | None | 0 0
  1.  
  2. #!/bin/bash
  3. #This is an automatically generated script that will generate
  4. #panoramas from images
  5.  
  6. #If these locations are incorrect, execute the buildScripts script again
  7.  
  8.  
  9. #imagePath is where images are stored to be stitched together.  WebPath
  10. #is the server location for panoramas
  11. imagePath=/home/jason/Pictures/Panos
  12. webPath=/var/www/JMCTour/panos/
  13.  
  14. #check if specified folders exist and user input is valid
  15. if [ ! -d "$imagePath" ]; then
  16.   echo ""
  17.   Images per folder:
  18.  
  19.   find . -maxdepth 1 -type f | sort -n -t _ -k 2 | while read -r file
  20.   do
  21.     echo "Current image: $curImage"
  22.     echo "Current Stop: $curStop"
  23.       mkdir $directory
  24.     fi
  25.  
  26.     #if current image counter is less than the number of frames to be stitched
  27.     #together, move current file to current stop directory
  28.     if [[ $curImage -le $1 ]]; then
  29.       mv $file $directory
  30.       curImage=$((curImage+1))
  31.     fi  
  32.  
  33.     #if current image counter equals the number of frames to be stitched,
  34.     #reset image counter and increment stop counter
  35.     if [[ $curImage -eq $1 ]]; then
  36.       curStop=$((curStop+1))
  37.       curImage=0
  38.     fi
  39.  
  40.   done
  41.  
  42.   #get the individual directories in the image storage folder
  43.   dirlist=$(find . -mindepth 1 -maxdepth 1 -type d \( ! -name completed\)| sort -n)
  44.   for dir in $dirlist
  45.   do
  46.     cd
  47.     echo "Downsizing $(ls *.JPG| wc -l) images
  48.    "
  49.  
  50.     curTime=$(date +"%T")
  51.     echo "Current directory: $dir"
  52.  
  53.     #find all the JPG files
  54.     fileList=$(find . -type f -name "*.JPG")
  55.  
  56.     #convert them to lower resolution
  57.     for i in $fileList
  58.     do
  59.       echo "Converting $i to 1600 pixels wide" >> "$imagePath/$dir/log.txt"
  60.       #convert $i -geometry 1600x $i
  61.     done
  62.  
  63.     #stitch the panorama together
  64.     ################################################################
  65.     #Generate project file
  66.     echo "Building project file" >> "$imagePath/$dir/log.txt"
  67.     match-n-shift -o project.pto *.JPG >> "$imagePath/$dir/log.txt"
  68.  
  69.     #Find control points and ignore clouds
  70.     echo "Searching for Control Points" >> "$imagePath/$dir/log.txt"
  71.     cpfind -o project.pto --multirow project.pto >> "$imagePath/$dir/log.txt"
  72.     ptoclean -v --output project.pto project.pto >> "$imagePath/$dir/log.txt"
  73.  
  74.  
  75.     #Clean up control points
  76.     echo "Cleanin gup points" >> "$imagePath/$dir/log.txt"
  77.     cpclean -o project.pto project.pto >> "$imagePath/$dir/log.txt"
  78.  
  79.     #Find vertical lines
  80.     echo "Verical Line Search" >> "$imagePath/$dir/log.txt"
  81.     linefind -o project.pto project.pto >> "$imagePath/$dir/log.txt"
  82.  
  83.     #optimize position, straighten, photometric optimization and output projection
  84.     echo "Optimizing, Straigntening File"  >> "$imagePath/$dir/log.txt"
  85.     autooptimiser -a -m -l -s -o project.pto project.pto >> "$imagePath/$dir/log.txt"
  86.  
  87.     #Calculate crop and size
  88.     pano_modify --canvas=AUTO -o project.pto project.pto >> "$imagePath/$dir/log.txt"
  89.  
  90.     #Generate stitch makefile
  91.     echo "Generating makefile"
  92.     pto2mk -o project.mk -p pano project.pto >> "$imagePath/$dir/log.txt"
  93.  
  94.     make -j 4 -f project.mk all >> "$imagePath/$dir/log.txt"
  95.  
  96.     echo "Panorama Done\n" >> "$imagePath/$dir/log.txt"
  97.  
  98.     #Downsize and convert panorama
  99.     #######################################################################
  100.     image="pano.tif"
  101.  
  102.     #convert pano to jpg and get count of images in photo folder
  103.     mogrify -format jpg $image >> "$imagePath/$dir/log.txt"
  104.     num=$(ls -l "$webPath/photos" | wc -l)
  105.     prefix=$((num+1))
  106.  
  107.     #convert full size pano to 1000 pixels high and rename with prefix number
  108.     #move to /photos folder
  109.     convert pano.jpg -geometry x1000 "$prefix-pano.jpg" >> "$imagePath/$dir/log.txt"
  110.     mv "$prefix-pano.jpg" "$webPath/photos" >> "$imagePath/$dir/log.txt"
  111.  
  112.     #convert full size pano to 600 pixels wide and rename with prefix number
  113.     #move to /thumbs folder
  114.     convert pano.jpg -geometry 600x "$prefix-pano.jpg" >> "$imagePath/$dir/log.txt"
  115.     mv "$prefix-pano.jpg" "$webPath/thumbs"  >> "$imagePath/$dir/log.txt"
  116.  
  117.     #cleanup
  118.     rm *.tif >> "$imagePath/$dir/log.txt"
  119.  
  120.   done
  121.  
  122.   #rinse and repeat
  123.   for dir in $dirlist
  124.   do
  125.     mv $dir "completed"
  126.   done
  127.   cd ../
  128. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement