Line detection autopilot using Python + OpenCV.

Feb 2017

Line detection autopilot for DIYRobocars using OpenCV (python port of CompoundEye)

In a previous post I walked through how to create a lane keeping autopilot using an end-to-end neural network. This post shows how to create a lane keeping autopilot using line detection computer vision algorithms.

This is essentially a python port of the C++ computer vision autopilot, written by Haoyang Wang, and Jason Devitt from Compound Eye. It was the only vehicle to complete the first DIYRobocar Race.

"compound eye race"

Load Images

In [1]:
import os
import cv2
import numpy as np
import random
import math

import matplotlib
from matplotlib.pyplot import imshow
from matplotlib import pyplot as plt
%matplotlib inline
In [2]:
dir_path = '/home/wroscoe/donkey_data/sessions/wr_1240/'
images = os.listdir(dir_path)
img_paths = [os.path.join(dir_path, i) for i in images]

#Read images, flip them vertically, and convert them to RGB color order
img_all = np.array([cv2.cvtColor(cv2.imread(p), cv2.COLOR_BGR2RGB) for p in img_paths])

#find image dimensions
<matplotlib.image.AxesImage at 0x7fe445d4c978>