# Pipe Line

1. RGB to GRAY
2. Gauss Blur
3. Canny Edges
4. Hough Transform
5. Dram Lines

Canny Edges：

# Gray

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import cv2

# Read in and grayscale the image
gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)

Y←0.299⋅R+0.587⋅G+0.114⋅B

Y←0.299⋅R+0.587⋅G+0.114⋅B

# Gauss Blur

• 原理：重新计算图片中每个点的值，计算的时候取该点与周围点的加权平均，权重符合高斯分布。
• 作用：降低图片噪声和减少细节（增强图片在不同scale下的structure），并保留边界。同时Gauss FIlter是一种低通滤波器，只允许低频部分通过，限制高频部分（例如像素值剧烈升高或降低的早点）。
• 效果：像通过半透明的玻璃看图片一样。
# Define a kernel size and apply Gaussian smoothing
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)

# Canny Edges

## Double threshold

• low_threshold < gradient < high_threshold: 当且仅当其存在相连点的梯度大于high_threshold才保留
# Define our parameters for Canny and apply
low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)

# ROI(Region of Interest) Based Edge Filtering

# Next we'll create a masked edges image using cv2.fillPoly()

# This time we are defining a four sided polygon to mask
imshape = image.shape
vertices = np.array([[(50,imshape[0]),(420, 280), (550, 280), (950,imshape[0])]], dtype=np.int32)

# Hough Transform

## 车道线

Hough变换的代码如下，其参数的含义见注释

rho = 2 # distance resolution in pixels of the Hough grid
theta = np.pi/180 # angular resolution in radians of the Hough grid
threshold = 15     # minimum number of votes (intersections in Hough grid cell)
min_line_length = 40 #minimum number of pixels making up a line
max_line_gap = 20    # maximum gap in pixels between connectable line segments
line_image = np.copy(image)*0 # creating a blank to draw lines on

# Run Hough on edge detected image
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]), min_line_length, max_line_gap)

# Lane Extrapolation

1. 将所有直线按照斜率分成左右两部分。
2. 每部分求平均或者median得到加权的直线参数。
3. 根据原图片的位置描绘出新参数的直线。

# 参考

99 篇文章32 人订阅

0 条评论

## 相关文章

1083

3258

### 零示例学习中的映射域迁移 (projection domain shift) 问题

AI 科技评论按：本文由上海交通大学副教授牛力为 AI 科技评论提供的独家稿件，未经许可不得转载。

1023

2520

1414

### Probabilistic decoder, Bayesian neural network, Probabilistic encoder

Probabilistic decoder, Bayesian neural network, Probabilistic encoder 最近在看概率模型，看...

17910

5874

4058

### ICCV 2017：训练GAN的16个技巧，2400+星（PPT）

【新智元导读】本文来自ICCV 2017的Talk：如何训练GAN，FAIR的研究员Soumith Chintala总结了训练GAN的16个技巧，例如输入的规范...

4057