Python+google street view API
- Takeshi Suetani
- 2018年5月15日
- 読了時間: 1分

Googleのstreet view APIを利用して特定地点(orその近傍)のstreet viewの画像をダウンロードしてOpenCVで結合
# Import google_streetview for the api module import google_streetview.api import os import cv2 import numpy as np
# Define parameters for street view api params = [{ 'size': "320x240", # max 640x640 pixels 'location': '34.0308327,132.2170133', #34.0303087,132.217178 'heading': '0.0', #0-360(0=North, 90=East) 'pitch': '-0.80', 'key': 'APIのキーはGoogleで取得' }] ########## Street Viewから4方の画像を取得・ファイルで保存 ##北 params[0]["heading"]=0.0 #print(params[0]["heading"]) # Create a results object results = google_streetview.api.results(params) # Download images to directory 'downloads' results.download_links('North')
##東 params[0]["heading"]=90.0 #print(params[0]["heading"]) # Create a results object results = google_streetview.api.results(params) # Download images to directory 'downloads' results.download_links('East')
##南 params[0]["heading"]=180.0 #print(params[0]["heading"]) # Create a results object results = google_streetview.api.results(params) # Download images to directory 'downloads' results.download_links('South')
##南 params[0]["heading"]=270.0 #print(params[0]["heading"]) # Create a results object results = google_streetview.api.results(params)
# Download images to directory 'downloads' results.download_links('West')
imgNorth = cv2.imread("North/gsv_0.jpg") imgEast = cv2.imread("East/gsv_0.jpg") imgSouth = cv2.imread("South/gsv_0.jpg") imgWest = cv2.imread("West/gsv_0.jpg")
img1 = cv2.hconcat([imgNorth,imgEast]) img2 = cv2.hconcat([imgSouth,imgWest]) imgConv = cv2.hconcat([img1,img2])
cv2.imwrite('imgConv.jpg',imgConv)