Ejemplo n.º 1
0
def main():

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    sess = tf.Session(config=config)

    # Train model
    loaded_model = load()
    last_time = time.time()
    for i in list(range(4))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False
    while True:

        if not paused:
            # 800x600 windowed mode
            # screen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
            screen = grab_screen(region=(0, 40, 800, 640))
            print('loop took {} seconds'.format(time.time() - last_time))
            last_time = time.time()
            screen = cv2.resize(screen, (299, 299))

            prediction = loaded_model.predict([screen.reshape(1, 299, 299, 3)])
            print(prediction)

            turn_thresh = .75
            fwd_thresh = 0.70

            if prediction[0][1] > fwd_thresh:
                straight()
            elif prediction[0][0] > turn_thresh:
                left()
            elif prediction[0][2] > turn_thresh:
                right()
            elif prediction[0][3] > turn_thresh:
                stop()
            else:
                straight()

        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.º 2
0
def main():

    for i in list(range(4))[::-1]:
        print(i+1)
        time.sleep(1)

    paused = False
    c=0
    last_time = time.time()
    laspos=0
    while(True):
        if not paused:
            # 800x600 windowed mode
            screen = grab_screen(title='FCEUX 2.2.2: Arkanoid (USA)')
            if c%10==0:
               print('Recording at ' + str((10 / (time.time() - last_time)))+' fps')
            last_time = time.time()
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
            screen=k(screen)

            processed,original,platform,platformpos,ballpos=process_img(screen)
            screen = cv2.resize(screen, (160,90))

            try:
                if (platformpos[0] - ballpos[0] > 0):
                    left()
                    print('moving left')
                else:
                    right()
                    print('moving right')
            except:
                pass



            cv2.imshow('window',processed)
            cv2.imshow('window1',original)
            cv2.imshow('window2',platform)

            #cv2.imshow('window',cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
            if cv2.waitKey(25) & 0xFF == ord('q'):
                cv2.destroyAllWindows()
                break
Ejemplo n.º 3
0
def main():
    last_time = time.time()

    while True:
        screen = grab_screen(region=(0, 40, 800, 640))
        print('Frame took {} seconds'.format(time.time() - last_time))
        last_time = time.time()
        new_screen, original_image, m1, m2 = process_img(screen)
        # cv2.imshow('window', new_screen)
        cv2.imshow('window2', cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))

        if m1 < 0 and m2 < 0:
            right()
        elif m1 > 0 and m2 > 0:
            left()
        else:
            straight()

        # cv2.imshow('window',cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
Ejemplo n.º 4
0
import os
import keyboard
from utils.grabscreen import grab_screen

count = 0
pic = 1

# Point to where we want the images to be saved
my_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(my_path, "img\\")

# Collets images until you press e
while not keyboard.is_pressed("e"):

    # You need to define the pixels you want to grab here!
    image = grab_screen(region=(85, 350, 715, 500))
    #Covert to grayscale
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    # Cover to black or white pixel
    (thresh, image) = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
    cv2.imshow('Bot View', image)
    cv2.waitKey(1)

    # Can adjust to save more or less pictures.
    # Currently save one pic every 50 times through loop
    if count % 50 == 0:
        cv2.imwrite(f"{path}BotView{pic}.jpg", image)
        print(f"Saved Picture numder: {pic}")
        pic += 1

    count += 1
Ejemplo n.º 5
0
# Wait for me to push B to start.
keyboard.wait('B')
time.sleep(sleepy)

# Hold down W no matter what!
keyboard.press('w')

# Randomly pick action then sleep.
# 0 do nothing release everything ( except W )
# 1 hold left
# 2 hold right
# 3 Press Jump

while True:

    image = grab_screen(region=(50, 100, 799, 449))
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    image = cv2.Canny(image, threshold1=200, threshold2=300)
    image = cv2.resize(image, (224, 224))
    # cv2.imshow("Fall", image)
    # cv2.waitKey(1)
    start_time = time.time()
    result = learn_inf.predict(image)
    action = result[0]
    #print(result[2][0].item(), result[2][1].item(), result[2][2].item(), result[2][3].item())

    #action = random.randint(0,3)

    if action == "Jump" or result[2][0] > .1:
        print(f"JUMP! - {result[1]}")
        keyboard.press("space")
Ejemplo n.º 6
0
def detect():
    """
    Takes GameScreen as input, and is processed in YOLOv5 Object Detection Architecture, moves cursor through
    Interception driver, shoots enemy, resulting in ==> D3ADSH0T
    """
    weights, imgsz = \
        opt.weights, opt.img_size

    # -------------------------------------------------------------------------------------------------------------------
    # Initialize :

    device = torch_utils.select_device(opt.device)
    half = device.type != 'cpu'  # Half precision only supported on CUDA

    # -------------------------------------------------------------------------------------------------------------------
    # Load Model :

    model = attempt_load(weights, map_location=device)  # Load FP32 model
    imgsz = check_img_size(imgsz, s=model.stride.max())  # Check img_size
    if half:
        model.half()  # To FP16

    # -------------------------------------------------------------------------------------------------------------------
    # Get Names and Colors :

    names = model.module.names if hasattr(model, 'module') else model.names
    colors = [[0, 255, 0], [0, 0, 255]]  # (Ally, Enemy) = (Green, Red)

    # -------------------------------------------------------------------------------------------------------------------
    # Set DataLoader & Run D3ADSH0T :

    img = torch.zeros((1, 3, imgsz, imgsz), device=device)  # init Img
    _ = model(img.half() if half else img) if device.type != 'cpu' else None  # Run once

    print('\n Running d3adsh0t Aimbot...!!')

    while True:
        img = grab_screen()  # Make sure you mention the 'region=' parameter of GameScreen, else 'Whole Screen' will be taken.
        if img is not None:
            t1 = torch_utils.time_synchronized()
            im0 = img
            img = letterbox(img, new_shape=imgsz)[0]
            img = img[:, :, ::-1].transpose(2, 0, 1)  # BGR to RGB, to 3x416x416
            img = np.ascontiguousarray(img)
            img = torch.from_numpy(img).to(device)
            img = img.half() if half else img.float()  # uint8 to fp16/32
            img /= 255.0  # 0 - 255 to 0.0 - 1.0
            if img.ndimension() == 3:
                img = img.unsqueeze(0)

            # ---
            # Interface :
            pred = model(img, augment=opt.augment)[0]

            # ---
            # Apply NMS :
            pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes,
                                       agnostic=opt.agnostic_nms)

            if pred[0] is not None and len(pred[0]):
                target = \
                    [scale_coords(img.shape[2:], det[:, :4], im0.shape).round()[:, :4] for i, det in enumerate(pred) if
                     det[0, 5] == 1 and det is not None][0]
                target = [int(coor) for coor in torch.stack(sorted(target, key=lambda a: a[3] - a[1], reverse=True))[0]]
                target_d3adsh0t(target, im0)
                ShotTarget.clear()
                ShotTarget.wait()

            t2 = torch_utils.time_synchronized()
            print('FPS = (%.3fs)' % (1 / (t2 - t1)))

            # DeBugging Block: (Note: Comment out the above 'if' block before starting DeBugging for the below block)
            """# ---
Ejemplo n.º 7
0
    def main(self):

        # Unique file name
        file_name = 'Data\\Training Data\\%s.npy' % uuid4()

        logger.info("Training data file created")
        training_data = np.empty(shape=[0, 2])

        region_template, wr, hr = self.load_template(
            zoom_level=-4
        )  # Default value is -4, but it cycles trough. could be from -5 to +5

        # Variáveis de controle:
        # was_fishing: sinaliza se o frame anterior foi ou não um frame da sessão de pescaria. Caso o mini-game seja
        # detectado, isso é setado para True no final do loop. Assim, no frame seguinte, caso não tenha sido detectado a
        # região e was_fishing for True, isso signifca que a pescaria acabou, e deve ser feito o processo de finalização
        # da captura de dados.
        # coords: coordenadas da região reduzida encontrada do mini-game.
        was_fishing = False
        coords = None

        logger.info("Data started")

        while self.run:

            # res_x, res_y = self.res
            screen = grabscreen.grab_screen()  # Return BGR screen

            if screen is not None:
                # Finds the thin area the fish stays at
                if coords is not None:

                    region = fishing_region(
                        screen[coords[0]:coords[1], coords[2]:coords[3]],
                        region_template, wr, hr)

                else:
                    region = fishing_region(screen, region_template, wr, hr)
                    zoom_dict = self.find_zoom(screen)

                    if zoom_dict['Found']:
                        # In subsequent fishing sessions, it will start by trying this zoom level

                        logger.info(f"Zoom used: {zoom_dict['Zoom']}")
                        region_template, wr, hr = self.load_template(
                            zoom_dict['Zoom'])

                if region["Detected"]:
                    # Se a área for detectada, salvar na np.array o frame e a o key-press do jogador.

                    window = region["Region"]

                    key_pressed = key_check(self.key)  # return 1 or 0

                    data = [
                        window, key_pressed
                    ]  # or data = np.array([key_pressed, window], dtype=object)

                    training_data = np.vstack((training_data, data))

                    # Contants for the next loop
                    was_fishing = True
                    bgr_screen_last = region["BGR Region"]

                    # For the first frame of the detected region, get its coordinates to reduce the area to look for it again
                    if coords is None:
                        print("Found")
                        bgr_screen_first = region["BGR Region"]
                        coords = region["Coords"]
                        logger.info("Coordinates found: %s" % coords)
                        initial_time = datetime.datetime.now()

                # If area not detected this frame, but was on the last one, this means fishing is over.
                if not region["Detected"] and was_fishing:
                    logger.info("Fishing finished")
                    final_time = datetime.datetime.now()

                    new_frames = np.float64(len(training_data))

                    print("Frames analysed: %s" % new_frames)

                    # Apenas salva caso houver mais de 75 frames
                    if new_frames >= 75:

                        validated = self.validate(bgr_screen_first,
                                                  bgr_screen_last)
                        verified = verify_too_similar_frames(training_data)

                        if validated and verified:
                            np.save(file_name, training_data)

                            # Sinaliza ao main_thread que deve enviar os dados coletados
                            self.send_data.emit()
                            print("Session saved!")

                    # Necessary to reset the region coordinates after every fishing session.
                    training_data = np.empty(shape=[0, 2])
                    file_name = 'Data\\Training Data\\%s.npy' % uuid4()
                    coords = None
                    was_fishing = False

                    # Measurements (debug):
                    time_delta = (final_time - initial_time).total_seconds()
                    median_fps = round(new_frames / time_delta, 2)
                    print(f"FPS: {median_fps}\n")
                    method = 'np.vstack'
                    w_img, h_img = window.shape[::-1]

                    with open("Data\\log.txt", 'a') as f:
                        f.write(
                            f"Method: {method}\nMedian FPS: {median_fps}\ndTime: {time_delta}s\n"
                            f"Frames: {new_frames}\nSize: ({w_img}, {h_img})\n\n"
                        )

        # Caso o usuário clique em "Stop" na GUI
        self.finished.emit()