Exemplo n.º 1
0
def drive(screen):
    lanes = ip.detect_lanes(screen)
    try:
        left_line = lanes[0]
        right_line = lanes[1]

        slope_left = ip.calc_slope(left_line[0][0], left_line[0][1],
                                   left_line[0][2], left_line[0][3])
        slope_right = ip.calc_slope(right_line[0][0], right_line[0][1],
                                    right_line[0][2], right_line[0][3])
        print(slope_left)
        print(slope_right)

        if slope_left == 0:
            print("crossroad")
            kp.turn_left()
        elif slope_left < 0 and slope_right < 0:
            print("turn right")
            kp.turn_right_f()
        elif slope_left > 0 and slope_right > 0:
            print("turn left")
            kp.turn_left_f()
        else:
            print("forward")
            kp.forward()
    except TypeError:
        return None
Exemplo n.º 2
0
def main():
    global stopped
    print("OH BOY")
    while (True):
        if 'P' in key_check():
            stopped = not stopped
            print('Stopped' if stopped else 'Resumed')
            kp.full_stop()
            time.sleep(1)
        if not stopped:
            screen = np.array(ImageGrab.grab(bbox=(50, 50, 800, 650)))
            screen = cv2.cvtColor(screen, cv2.COLOR_RGB2GRAY)
            #cv2.imshow('window',screen)
            screen = cv2.resize(screen, (WIDTH, HEIGHT))
            prediction = model.predict([screen.reshape(WIDTH, HEIGHT, 1)])[0]
            print(prediction)

            if prediction[1] > fw_threshold:
                kp.forward()
            elif prediction[0] > left_threshold:
                kp.turn_left_f()
            elif prediction[2] > right_threshold:
                kp.turn_right_f()

            if cv2.waitKey(25) & 0xFF == ord('q'):
                cv2.destroyAllWindows()
                break