Created
December 26, 2015 11:54
-
-
Save pachacamac/5784e2772bcf511d4eb0 to your computer and use it in GitHub Desktop.
Photosphere downloader and stitcher
This file contains hidden or 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
module Enumerable | |
# inside the block you can use Thread.exit to stop this execution and Thread.exclusive{...} to synchronize stuff | |
def parallel_map | |
map{|e| Thread.new{ Thread.current[:result] = yield(e) } }.map{|t| t.join; t[:result]} | |
end | |
def parallel_map_in_chunks(chunk_size=8, &block) | |
chunks = each_slice(chunk_size).each_with_index | |
chunks.map{|chunk,i| | |
puts "chunk #{i+1}/#{chunks.size}. chunk_size=#{chunk.size}" | |
chunk.parallel_map(&block) | |
}.flatten(1) | |
end | |
end | |
def get(url, out) `wget -q -O #{out} #{url}` end | |
def download(sphere_base_url) | |
packets = [] | |
(0..27).each do |x| | |
(0..13).each do |y| | |
packets << [x,y] | |
end | |
end | |
packets.parallel_map_in_chunks(8) do |x,y| | |
get("#{sphere_base_url}/x#{x}-y#{y}-z5/p", "sphere/#{y.to_s.rjust(2,'0')}_#{x.to_s.rjust(2,'0')}.jpg") | |
puts "#{x} #{y}" | |
end | |
end | |
def stitch | |
`montage sphere/*.jpg -tile 28x14 -mode Concatenate sphere.jpg` | |
end | |
download('https://lh3.ggpht.com/-F8poV1Q5x7w/VlzTerU51oI/AAAAAAAAArY/2btnk9d72s8') | |
stitch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment