Skip to content

Car detection

NotGayBut5CentsAre5Cents edited this page Jun 7, 2018 · 2 revisions

Uses a predefined model from tensorflow, for image clasification.

The function we use from the file car_detection.py is get_object(screen). (we should probably rename the function to get_detected_cars_bboxes() as it describes better what this function does)

In output_dict we save all the information for the detected objects classified from tensorflows model.

then we append all the objects that are cars with above 50% certainty to a lsit

(the magic number is 3 here as from the tensorflow documentation, this is the class number for a car)

for i, dc in enumerate(output_dict['detection_classes']):
    if dc == 3:
    .
    .
    .

and the function returns the list

drive3 from ai.py

drive3 uses the above function to get all the cars bboxes to determine whether

they are too close and a call to the model should be made. here is a code peak:

    car_bboxes = cd.get_object(screen)
    collision_warning = False
    for car_bbox in car_bboxes: #we iterate over all the cars
        #and determine whether the width of the bbox is bigger 
        #then 35% of the total screen 
        if length_of_bounding_box(car_bbox, WIDTH) >= (WIDTH * 0.35):
            #then we check if the mid point is in the center
            #of the screen
            mid_point_x = mid_point(car_bbox)[0]
            if mid_point_x > 0.33 and mid_point_x < 0.66:
Clone this wiki locally