Ejemplo n.º 1
0
def main():
    paused = False
    while not paused:
        #image_org = cv2.imread(file_paths[0])
        image_org = grab_screen(region=(0, 30, 1250, 750))
        #speed, speed_img = get_speed(image_org)
        points = get_3_points(image_org)
        image = process_image(image_org)
        point_colour_value, image_org = get_point_data(image, points, 50)
        #print(type(speed))
        process_data(point_colour_value)
        #
        color = (0, 0, 0)
        image_org = cv2.rectangle(image_org, (1120, 635), (1185, 670), color,
                                  5)
        #cv2.imshow("window",  cv2.resize(image_org, (500, 300)))
        #cv2.imshow("window",  cv2.resize(speed_img, (500, 300)))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
        keys = key_check()
        if 'T' in keys:
            print("son")
            if paused:
                paused = False
                print('unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)
Ejemplo n.º 2
0
def main(file_name, starting_value):

    file_name = file_name
    starting_value = starting_value
    paused = False
    timer = True
    training_data = []

    if timer:
        for i in range(4)[::-1]:
            print(i + 1, "sec left")
            time.sleep(1)
        print("Starting Rec")

    last_time = time.time()

    while True:
        if not paused:
            screen = grab_screen(region=(0,30,1250,750))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
            screen = cv2.resize(screen, (500,288))
            screen = roi(screen, [vertices])
            screen = screen[110:270, 0:480]
            #cv2.imshow("fens", screen)
            #cv2.imshow("crop", crop)


            keys = key_check()

            output = keys_to_output(keys)
            training_data.append([screen/255,output])
            last_time = time.time()
            #print(output)


            if len(training_data) % 250 == 0:
                print(len(training_data))

                if len(training_data) == 4000:
                    np.save(file_name,training_data)
                    print('SAVED')
                    training_data = []
                    starting_value += 1
                    file_name = 'D:/Projects/self_driving_car/Final_data/training_data_9_final-{}.npy'.format(starting_value)


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

        keys = key_check()
        if 'T' in keys:
            if paused:
                paused = False
                print('unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)
Ejemplo n.º 3
0
def main(file_name, starting_value):
    """
    file_name = file_name
    starting_value = starting_value
    training_data = []
    print("test 1")
    '''
    for i in list(range(4))[::-1]:
        print(i+1)
        time.sleep(1)
        '''

    print('STARTING!!!')
    last_time = time.time()
    """
    paused = False
    ten_fps = True
    while (True):
        screen = grab_screen(region=(0, 30, 1010, 800))
        screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
        screen = cv2.resize(screen, (480, 270))
        screen = roi(screen, [vertices])
        cv2.imshow("fens", screen)

        if not paused:

            keys = key_check()
            #print('loop took {} seconds'.format(time.time()-last_time))
            '''
            if (time.time() - last_time >= 0.1):
                output = keys_to_output(keys)
                training_data.append([screen,output])
                last_time = time.time()

                if len(training_data) % 100 == 0:
                    print(len(training_data))

                    if len(training_data) == 1000:
                        np.save(file_name,training_data)
                        print('SAVED')
                        training_data = []
                        starting_value += 1
                        file_name = 'D:/Projects/self_driving_car/Training_data/training_data-{}.npy'.format(starting_value)
            #cv2.imshow('window',cv2.resize(screen,(640,360)))
            #if cv2.waitKey(25) & 0xFF == ord('q'):
            #    cv2.destroyAllWindows()
            #    break
            '''

    keys = key_check()
    if 'T' in keys:
        if paused:
            paused = False
            print('unpaused!')
            time.sleep(1)
        else:
            print('Pausing!')
            paused = True
            time.sleep(1)
Ejemplo n.º 4
0
def main():
    while True:
        img = grab_screen(region=(0,30,1250,750))
        screen = cv2.resize(img, (500, 300))
        R = 1
        screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
        #image = Image.fromarray(img.astype('uint8'), 'RGB')
        screen = entropy(screen, disk(R))
        cv2.imshow("sss",screen)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
Ejemplo n.º 5
0
def main():
    paused = False
    while True:
        if not paused:
            screen = grab_screen(region=(0,30,1250,750))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
            org_image = screen
            screen = cv2.resize(screen,(input_w, input_h))
            screen = img_to_array(screen)
            screen /= 255.0
            screen = expand_dims(screen, 0)
            #screen = cv2.resize(screen,(1, 416, 416, 3))
            yhat = model.predict(screen)
            boxes = list()
            for i in range(len(yhat)):
            	boxes += decode_netout(yhat[i][0], anchors[i], class_threshold,nms_threshold, input_h, input_w)
            correct_yolo_boxes(boxes, image_h, image_w, input_h, input_w)
            do_nms(boxes, 0.5)
            draw_boxes(org_image, boxes, labels, class_threshold)
            cv2.imshow("fens", org_image)
            #cv2.imshow("crop", crop)

            #keys = key_check()

            #output = keys_to_output(keys)
            #training_data.append([screen/255,output])
            #last_time = time.time()


            #if len(training_data) % 250 == 0:
            #    print(len(training_data))

            #    if len(training_data) == 2500:
            #        np.save(file_name,training_data)
            #        print('SAVED')
            #        training_data = []
            #        starting_value += 1
            #        file_name = 'D:/Projects/self_driving_car/Training_data/training_data_final-{}.npy'.format(starting_value)

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

        keys = key_check()
        if 'T' in keys:
            if paused:
                paused = False
                print('unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                time.sleep(1)
Ejemplo n.º 6
0
def main():
    last_time = time.time()
    for i in list(range(4))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    #prob_output_normal_final = []
    while (True):

        if not paused:
            # 800x600 windowed mode
            #screen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
            screen = grab_screen(region=(0, 30, 1250, 750))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
            screen = cv2.resize(screen, (480, 270))
            screen = roi(screen, [vertices])
            screen = screen[110:270, 0:480]
            screen = screen.reshape(WIDTH, HEIGHT, 1)
            prediction = model.predict([screen])[0]
            Drive(prediction)
            keys = key_check()
            #print("%.4f" % prediction[0], "%.4f" % prediction[1], "%.4f" % prediction[2], "%.4f" % prediction[3])
            #prob_output_normal_final.append(prediction)
            #if (len(prob_output_normal_final) % 250 == 0):
            #    print(len(prob_output_normal_final))

            #if(len(prob_output_normal_final) % 5000 == 0):
            #    prob_output_normal_final = np.array(prob_output_normal_final)
            #    file_name = 'D:/Projects/self_driving_car/Training_data/output-probs-normal-{}.npy'.format(4)
            #    np.save(file_name,prob_output_normal_final)
            #    print("Saved")

        keys = key_check()

        # p pauses game and can get annoying.
        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                ReleaseKey(S)
                time.sleep(1)
Ejemplo n.º 7
0
        break


def roi(img, vertices):
    mask = np.zeros_like(img)
    cv2.fillPoly(mask, vertices, 255)
    masked = cv2.bitwise_and(img, mask)
    return masked


vertices = np.array(
    [[0, 120], [150, 110], [350, 110], [480, 120], [480, 270], [0, 270]],
    np.int32)

while (True):
    screen = grab_screen(region=(0, 30, 1010, 800))
    screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
    screen = cv2.resize(screen, (480, 270))
    screen = roi(screen, [vertices])
    cv2.imshow("fens", screen)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break


def main(file_name, starting_value):
    """
    file_name = file_name
    starting_value = starting_value
    training_data = []
    print("test 1")