# 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 篇文章33 人订阅

0 条评论

## 相关文章

2756

41910

671

801

1552

1992

8022

902

4816

### 【论文推荐】最新九篇目标检测相关论文—常识性知识转移、尺度不敏感、多尺度位置感知、渐进式域适应、时间感知特征图、人机合作

【导读】专知内容组整理了最近七篇目标检测（Object Detection）相关文章，为大家进行介绍，欢迎查看! 1.Single-Shot Object De...

7227