[PYTHON] Get a panoramic image in Google Street View

What i did

The work done in CAPTURING SPHERICAL SCENES FROM GOOGLE STREETVIEW is done with a python script. I tried to make it.

Caution

Please read the Google Street View license carefully before using this script.

environment

python 2.7.10

script

append.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
import re
import sys

class Panorama:

  def __init__(self, url):
    self.path = "./tmp/"
    self.panoid = self.parseID(url)

    #panorama size = 12*25
    self.x = 12
    self.y = 25

  def parseID(self,url):
    dna = "!1s"
    m = url.find(dna)
    if m != -1:
      return url[m+3:m+25]
    else:
      return ""

  def mkdirTmp(self):
    if os.path.exists(self.path):
      pass
    else:
      os.mkdir(self.path)

  def clean(self):
    shutil.rmtree(self.path)

  def downloadImage(self):
    cmd = 'curl http://cbk0.google.com/cbk?output=tile\&panoid=' + self.panoid + '\&zoom=5\&x=[0-25]\&y=[0-12] -o ' + self.path + '"tile_#1-#2.jpg "'
    os.system(cmd)

  def appendImage(self):

    #Connect to the side
    for x in range(0, self.x+1):
      cmd = "convert +append "
      for y in range(0, self.y+1):
        #Input file
        inFile = self.path + "tile_%d-%d.jpg "% (y,x)
        #Concatenate to command string
        cmd += inFile + " "

      #Set output file name
      cmd += self.path + "%d.jpg "%x
      #print cmd

      #Run
      os.system(cmd)

    #Connect vertically
    cmd = "convert -append "
    for x in range(0,self.x):
      cmd += self.path + "%d.jpg "%x + " "

    cmd += "append.jpg "
    #print cmd

    os.system(cmd)


if __name__ == "__main__":
  url = "https://www.google.co.jp/maps/@34.7020532,135.5020237,3a,75y,285h,99t/data=!3m7!1e1!3m5!1sBLX3E8R5JxUJnuHlPGg5kw!2e0!6s%2F%2Fgeo3.ggpht.com%2Fcbk%3Fpanoid%3DBLX3E8R5JxUJnuHlPGg5kw%26output%3Dthumbnail%26cb_client%3Dmaps_sv.tactile.gps%26thumb%3D2%26w%3D203%26h%3D100%26yaw%3D285.21%26pitch%3D9.21!7i13312!8i6656?hl=ja&hl=ja"

  pano = Panorama(url)
  if  len(pano.panoid) > 0:
    pano.mkdirTmp()
    pano.downloadImage()
    pano.appendImage()
    pano.clean()

Recommended Posts

Get a panoramic image in Google Street View
Get Google Image Search images in original size
I get a KeyError in pyclustering.xmeans
Get a Boolean in Flask's request
View image after Data Augmentation in PyTorch
Cut out A4 print in the image
Implement a custom View Decorator in Pyramid
Get Google Fit API data in Python
How to get a stacktrace in python
How to get a namespaced view name from a URL (path_info) in Django
Get a token for conoha in python
[Python] Get the files in a folder with Python
When I get a chromedriver error in Selenium
Get the caller of a function in Python
Get Google Cloud Storage object list in Java
Get only the subclass elements in a list
View drug reviews using a list in Python
Get a glimpse of machine learning in Python
What to do to get google spreadsheet in python
Get a row containing a specific element in np.where
Get the file name in a folder using glob
A list of stumbling blocks in Django's image upload
I get a java.util.regex.PatternSyntaxException when splitting a string in PySpark
Get the image of "Suzu Hirose" by Google image search.
Try loading the image in a separate thread (OpenCV-Python)
BigQuery-If you get a Reason: responseTooLarge error in Python
Display a histogram of image brightness values in python
Get a participant's username and screen name in Slack