Sorry for the mess of files (probably should have used git properly, opps) - the latest / final file is andre_vision.py (https://github.com/tomiam8/DRC-2019-team1/blob/master/andre_vision.py)
- Camera continuously takes pictures (See Camera class) Is a blocking process with lot's of I/O, so theading used so can process images while picture is being taken
- Process a picture (see HandCodedLaneFollower.follow_lane)
- Resize to a very small resolution - Makes it run much faster
- Convert image to HSV - Makes thresholding for blue/yellow work much better
- Threshold to get a seperate blue/yellow lane lines
- Use cv2.HoughLinesP to get lines in each image
- Split lines for image into three seperate collections, for top / middle / bottom sections of image
- For each section, create an 'average' line
- Originally, just averaged gradient and intercept
- Later, found averaging angle instead of gradient and perpendicular distance from (originally origin, but later used) an x-value of 0, but y-value of middle of section worked better (e.g. for vertical or horizontal lines)
- From the equation for the average line (found above), find a point on the line (use y-value of middle of section)
- Find the midpoints for the lines
- If both the yellow and blue points were found for a section, use the midpoint between them for that section
- Otherwise compare the change in x with a midpoint in another section (eg top has blue and yellow points, middle just has a blue point. Use change from top to middle in blue point as change in the midpoint, to get a middle midpoint. Bottom dosen't have any midpoint), or just use a constant offset (if only one line found)
- Do PID control-theory stuff to calculate an angle and a speed to drive at
- Send angle and speed to arduino constantly
- Another team found using multiprocessing instead of threading for this thread ran faster