程序员程序员首页投稿首页投稿(暂停使用,暂停投稿)

新手向——通过街头图像评估纽约市自行车道的质量

2017-07-28  本文已影响246人  treelake

Measuring the quality of NYC Bike Lanes through street imagery

检测车道标记

import scipy.ndimage as nd
photoName = 'path'
img = nd.imread(photoName)

import matplotlib.pylab as plt
def plti(im, **kwargs):
    """
    画图的辅助函数
    """
    plt.imshow(im, interpolation="none", **kwargs)
    plt.axis('off') # 去掉坐标轴
    plt.show() # 弹窗显示图像
plti(img)
#图片的行数和列数
nrow, ncol = img.shape[:2]
#从行数的一半开始 直到 0.9行数
img = img[nrow//2:(nrow-nrow//10),:,:]

plti(img)
#分离出三层色彩
red, grn, blu = img.transpose(2, 0, 1)
#应用阈值处理
thrs = 200
wind = (red > thrs) & (grn > thrs) & (blu > thrs)

plti(wind)
# 使用高斯滤波模糊白色区块
gf = nd.filters.gaussian_filter
blurPhoto = gf(1.0 * wind, 40)

plti(blurPhoto)
# 阈值位于黑白之间的灰色区域
# 像素值大于阈值为1,小于为0
threshold = 0.16
wreg = blurPhoto > threshold

plti(wreg)

于是得到该车道标记的最终得分:在最后一张图中白色区域(即车道标记)的占比(wreg.mean())。这里是13.2%。

检测可见道路缺陷

import scipy.ndimage as nd
photoName = r'path'
img = nd.imread(photoName)

plti(img)
#图片的行数和列数
nrow, ncol = img.shape[:2]
#从行数的一半开始 直到 0.9行数
img = img[nrow//2:(nrow-nrow//10),:,:]

plti(img)
md = nd.filters.median_filter
# 模糊图像
md_blurPhoto = md(img, 5)
plti(md_blurPhoto)
import cv2
lower = np.array([0, 10, 50])
upper = np.array([360, 100, 100])
hls = cv2.cvtColor(md_blurPhoto, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hls, lower, upper)
res = cv2.bitwise_and(hls, hls, mask = mask)
edges_cv = cv2.Canny(res, 200, 400)
#模糊边缘
blurred_edges = cv2.GaussianBlur(edges_cv,(3,3),0) 
# 只想保留这样的裂缝:邻近其他裂缝或大于某个最小阈值
bdilation = nd.morphology.binary_dilation
berosion = nd.morphology.binary_erosion
edges_2 = bdilation(berosion(blurred_edges, iterations=2), iterations=2)
defect_score = edges_2.mean()
到现在,团队骑行超过50英里,收集了4500个街景
上一篇 下一篇

猜你喜欢

热点阅读