我是一名 R 用户,在 Python 中进行图像分析时遇到了麻烦。计算图像中心建筑物面积的有效方法是什么?目标是将边缘算法应用于谷歌地图静态图像并计算地址屋顶的表面积。
from pygeocoder import Geocoder
import urllib
import numpy as np
from scipy import ndimage
from skimage import filter, io, measure
import matplotlib.pyplot as plt
def getMap(address):
"""Geocode address and retreive image centered
around lat/long"""
results = Geocoder.geocode(address)
lat, lng = results[0].coordinates
zip_code = results[0].postal_code
map_url = 'https://maps.googleapis.com/maps/api/staticmap?center={0},{1}&size=640x640&zoom=19&sensor=false&maptype=roadmap&&style=visibility:simplified|gamma:0.1'
request_url = map_url.format(lat, lng)
req = urllib.urlopen(request_url)
return(req)
def mapEdge(req):
"""Convert img to bytearray and do edge detection
on centered building"""
img = io.imread(req.geturl(),flatten=True)
labels, numobjects = ndimage.label(img)
edges = filter.canny(img, sigma=3)
plt.imshow(edges, cmap=plt.cm.gray)
plt.show()
map_tmp = getMap('1403 Elmwood Ave., Evanston, IL')
mapEdge(map_tmp)