Skip to content
Snippets Groups Projects
Commit b9463793 authored by kpp55's avatar kpp55
Browse files

First lane detection alg

parent 175b5fcb
No related branches found
No related tags found
No related merge requests found
import numpy as np
import cv2
# from time import sleep
# Converts picture to grayscale and applies filter to picture
# params
# pic : a numpy array of pixel values to represent a picture
def formatImg(pic):
# Convert picture to gray scale
gray = cv2.cvtColor(pic, cv2.COLOR_BGR2GRAY)
# Apply filter to image
img_filter = cv2.GaussianBlur(gray, (5, 5), 0)
return img_filter
# pre-processes and performs edge detection on an image
# params
# pic: a numpy array of pixel values for an image in gray scale
def detect_edge(pic):
# Perform canny edge detection
img_edge = cv2.Canny(pic, 50, 150)
# return new edge image
return img_edge
def ROI(pic):
return 0
def applyLanes(original_pic, edge_pic):
lines = cv2.HoughLinesP(edge_pic, 1, np.pi / 180, 50, maxLineGap=70, minLineLength=10)
for line in lines:
x1, y1, x2, y2 = line[0]
print(x1)
cv2.line(original_pic, (x1, y1), (x2, y2), (0, 255, 0), 3)
return original_pic
video = cv2.VideoCapture("test_data.mp4")
while True:
ret, frame = video.read()
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame_edge = detect_edge(frame)
if not ret:
video = cv2.VideoCapture("test_data.mp4")
continue
new_img = formatImg(frame)
wEdges = detect_edge(new_img)
lanes = applyLanes(frame, wEdges)
cv2.imshow("frame", wEdges)
key = cv2.waitKey(25)
if key == 27:
break
video.release()
cv2.destroyAllWindows()
'''
# Load image
img = cv2.imread('lol_image.jpg')
cv2.imshow("original", img)
new_img = formatImg(img)
wEdges = detect_edge(new_img)
lanes = applyLanes(img, wEdges)
cv2.imshow("edges", wEdges)
cv2.imshow("with lines", lanes)
cv2.waitKey(0)
cv2.destroyAllWindows()
'''
\ No newline at end of file
laneDetection/lol_image.jpg

758 KiB

File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment