@kaiserb1/

Lane Detection

Pygame

No description

fork
loading
Files
  • main.py
  • 1.3_lines_with_gap.jpg
  • Alea.png
  • nohup.out
  • requirements.txt
  • whiteCar.png
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2
import numpy as np

image = cv2.imread('Alea.png')
grey_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

kernel_size = 5
blur_gray = cv2.GaussianBlur(grey_image, (kernel_size, kernel_size), 0)

low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)

vertices = np.array([[(0, 400), (170, 0), (370, 270)]], dtype=np.int32)
mask = np.zeros_like(edges)
cv2.fillPoly(mask, vertices, 255)
masked_edges = cv2.bitwise_and(edges, mask)

rho = 2  # resolution in pixels
theta = np.pi/180  # resolution in radians
threshold = 15
min_line_length = 40
max_line_gap = 30
line_image = np.copy(image)*0
lines = cv2.HoughLinesP(masked_edges, rho, theta, threshold, np.array([]), 40, 30)

for line in lines:
    for x1, y1, x2, y2 in line:
        cv2.line(line_image, (x1, y1), (x2, y2), (255, 0, 0), 10)
        lines_edges = cv2.addWeighted(image, 0.8, line_image, 1, 0)

cv2.imshow("lines", lines_edges)
cv2.imwrite("1.3_lines_with_gap.jpg", lines_edges)