Skip to content
NotGayBut5CentsAre5Cents edited this page Jun 5, 2018 · 1 revision

Ai.py

In this file the driving logic is implemented.

There are 3 methods (drive, drive2, drive3) each incorporating various ways of driving the car.

drive method

The param you pass to the function is the screen you have captured using openCv

def drive(screen):

Then the drive method calls the image processing function detect_lanes to get the two lines representing the road from the screen image you have given it. The logic of this method is to get the two lanes of the road and calculate their slope after which based on the slope a command is issued using the keyboardPress methods.

drive2 method

The param you pass to the function is the same as in drive.

The drive2 method calls the image processing function get_lines to get all the lines on the screen image. Then based on the slope of the line each line is given a weight. All the weights are added together and based on the resulting number a command is issued using the keyboardPress methods.

drive3 method

The params are:

screen #The screen image to be processed 
model #A trained model used for determining actions
WIDTH, HEIGHT # Width and height used in the model, the screen will be resized based on the values
# The model return percentages for the forward and sides actions
fw_threshold=50    # By default the values are set to 50% 
left_threshold=50 
right_threshold=50

First the method gets all the bounding boxes of the cars it sees on the screen. Then for each of the bounding boxes we calculate its position and closeness to the car. If its too close we call the model to determine what action the car should take. If its not close we simply just call drive2.

Clone this wiki locally