コード例 #1
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__),
                  level=logging.DEBUG,
                  write_to_file=False)

    proc = TopHudProcessor()

    agent_paths = [
        os.path.join(
            "C:/Users/simon/overtrack_2/valorant_images/top_hud_agents",
            agent_name.lower() + ".png",
        ) for agent_name in agents
    ]
    agent_frames = [
        agent_path for agent_path in agent_paths if os.path.exists(agent_path)
    ]
    # util.test_processor(agent_frames, proc, 'valorant.top_hud', test_all=False, wait=True)

    # util.test_processor([
    #     r'C:/Users/simon/overtrack_2/valorant_images/ingame\00-41-617.image.png'
    # ], TopHudProcessor(), 'valorant.top_hud', test_all=False, wait=True)
    #
    test_processor(proc, "valorant.top_hud", test_all=False, wait=True)
コード例 #2
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__), level=logging.DEBUG, write_to_file=False)

    test_processor(HomeScreenProcessor(), "valorant.home_screen")
コード例 #3
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__),
                  level=logging.DEBUG,
                  write_to_file=False)
    test_processor(AgentSelectProcessor(),
                   "valorant.agent_select",
                   test_all=False)
コード例 #4
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__),
                  level=logging.DEBUG,
                  write_to_file=False)
    proc = KillfeedProcessor()

    test_processor(proc, "valorant.killfeed", wait=True, test_all=False)
    test_processor(proc, "valorant.killfeed", wait=True, test_all=False)
コード例 #5
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__),
                  level=logging.DEBUG,
                  write_to_file=False)
    p = PostgameProcessor()
    test_processor(p,
                   "valorant.postgame",
                   "valorant.scoreboard",
                   test_all=False)
    test_processor(p,
                   "valorant.postgame",
                   "valorant.scoreboard",
                   test_all=False)
コード例 #6
0
def main() -> None:
    config_logger("shmem_source", logging.DEBUG, False)

    cap = SharedMemoryCapture(debug_frames=True)
    cap.start()
    while True:
        frame = cap.get()
        if not frame:
            print("x")
            time.sleep(4)
            continue
        elif isinstance(frame, Exception):
            raise frame

        cv2.imshow("frame", frame.debug_image)
        print(frame.source)
        cv2.waitKey(1000)
コード例 #7
0
def main() -> None:
    convert_tflite_model()

    config_logger("big_noodle", logging.DEBUG, False)

    # from tensorflow.python.keras import Input
    # from tensorflow.python.keras.layers import Reshape, Conv2D
    # from tensorflow.python.keras import Model
    # from tensorflow.python.keras.layers import Activation
    # from overtrack.util.custom_layers import MaxAlongDims
    # from tensorflow.python.keras.layers import Layer
    # from tensorflow.python.keras.saving import export_saved_model
    #
    # image = Input(shape=(Classifier.HEIGHT, Classifier.WIDTH), name='images', dtype=tf.float32)
    # image_r = Reshape((Classifier.HEIGHT, Classifier.WIDTH, 1))(image)
    # conv1 = Conv2D(
    #     len(Classifier.CHARACTERS),
    #     Classifier.CONV1_SIZE,
    #     activation=None,
    #     name='conv1'
    # )(image_r)
    # logits = MaxAlongDims((1, 2))(conv1)
    # output = Activation(activation='softmax')(logits)
    #
    # model = Model(
    #     inputs=image,
    #     outputs=output
    # )
    # model.compile(
    #     optimizer='adam',
    #     loss='binary_crossentropy'
    # )
    #
    # model.summary()
    #
    # l: Layer = model.layers[2]
    #
    # p = os.path.join(os.path.dirname(__file__), 'data', 'big_noodle.npz')
    # restore_dict = dict(np.load(p))
    # l.set_weights([restore_dict['conv1/kernel:0'], restore_dict['conv1/bias:0']])
    #
    # export_saved_model(model, f'./data/big_noodle', serving_only=True)

    image = cv2.imread("C:/tmp/test.png")
    for _ in range(10):
        print(ocr(image))
コード例 #8
0
def main() -> None:
    convert_tflite_model()

    config_logger("digit", logging.DEBUG, False)

    # from tensorflow.python.keras import Input
    # from tensorflow.python.keras.layers import Reshape
    # from tensorflow.python.keras import Model
    # from tensorflow.python.keras.layers import Layer
    # from tensorflow.python.keras.layers import Dense
    # from tensorflow.python.keras.saving import export_saved_model
    #
    # image = Input(shape=(Classifier.IMSIZE[0], Classifier.IMSIZE[1]), name='images', dtype=tf.float32)
    # image_r = Reshape((np.prod(Classifier.IMSIZE), ))(image)
    #
    # logits = Dense(
    #     len(Classifier.CHARACTERS),
    #     activation='softmax',
    #     name='fc1'
    # )(image_r)
    #
    # model = Model(
    #     inputs=image,
    #     outputs=logits
    # )
    # model.compile(
    #     optimizer='adam',
    #     loss='binary_crossentropy'
    # )
    #
    # model.summary()
    #
    # p = os.path.join(os.path.dirname(__file__), 'data', 'tab_ocr.npz')
    # restore_dict = dict(np.load(p))
    # print({k: v.shape for k, v in restore_dict.items()})
    # l: Layer = model.layers[2]
    # print(l, [w.shape for w in l.get_weights()])
    # l.set_weights([restore_dict['tab_ocr/W_fc_:0'], restore_dict['tab_ocr/b_fc_:0']])
    #
    # os.makedirs('./data/tab', exist_ok=True)
    # export_saved_model(model, f'./data/tab_digit', serving_only=True)

    image = cv2.imread("C:/tmp/test.png")
    for _ in range(10):
        print(ocr(image))
コード例 #9
0
def main() -> None:
    import glob

    config_logger("map_processor", logging.DEBUG, write_to_file=False)

    # find_best_match()
    # exit(0)

    pipeline = MinimapProcessor()
    paths = glob.glob("d:/overtrack/frames_rot/*.json")[1630:]

    # random.shuffle(paths)

    # paths = ['D:/overtrack/frames_rot/1569668416.76_image.png']
    # paths = [
    #    r'd:/overtrack/frames_rot\1569669144.44_frame.json'
    #     r'd:/overtrack/frames_rot\1569670312.41_image.png'
    # ]

    for p in paths:
        print(p)
        imp = p.replace("frame.json", "image.png")
        try:
            frame = Frame.create(
                cv2.resize(cv2.imread(imp), (1920, 1080)),
                float(os.path.basename(p).split("_")[0]),
                True,
                file=imp,
            )
        except:
            logging.exception("")
            continue
        frame.game_time = frame.timestamp - 1569665630

        pipeline.process(frame)
        print(frame)
        cv2.imshow("debug", frame.debug_image)

        cv2.waitKey(0)
コード例 #10
0
def main():
    from overtrack_cv.util.logging_config import config_logger
    from overtrack_cv.util.test_processor import test_processor

    config_logger(os.path.basename(__file__), level=logging.DEBUG, write_to_file=False)
    test_processor(TimerProcessor(), "timer", wait=True)
コード例 #11
0
    elif errorcode in ["0x887A0004", "0x80070057"]:
        return "Unsupported by Graphics Driver:\nYou may need to run OverTrack on the a different GPU, or your device may not be supported"

    return ""


def main() -> None:
    # hwnd, pid = get_hwnd('Overwatch', None)
    # hwnd, pid = get_hwnd(None, 'pycharm64.exe')
    # print(hwnd, pid)
    from overtrack_models.dataclasses.typedload import referenced_typedload

    # d = DisplayDuplicationCapture(window_title='Overwatch', executable='overwatch.exe')
    title = "Apex Legends"
    executable = "r5apex.exe"
    d = DisplayDuplicationCapture(window_title=title, executable=executable)
    while True:
        frame = d.get()
        cv2.imshow("frame", frame.image)
        frame.strip()
        print(frame.valid)
        cv2.waitKey(1000)

        referenced_typedload.dump(frame)


if __name__ == "__main__":

    config_logger("display_duplication", logging.DEBUG, False)
    main()
コード例 #12
0
def test_processor(
    proc: Processor,
    *fields: str,
    show=True,
    test_all=True,
    wait=True,
    warmup=True,
    game=None,
    images=None,
) -> None:
    proc.eager_load()

    if not game:
        game = os.path.basename(
            glob.glob(
                os.path.join(os.path.dirname(inspect.getfile(proc.__class__)),
                             "..", "..", "*_frame_data.py"))[0]).split("_",
                                                                       1)[0]
        print(game)
        print(inspect.getmodule(proc))
        print(proc.__class__.__module__)

    # TODO
    game_data_factory = object
    if game == "apex":
        from overtrack_cv.games.apex.apex_frame_data import ApexFrameData

        game_data_factory = ApexFrameData
    elif game == "valorant":
        from overtrack_cv_private.games.valorant.valorant_frame_data import (
            ValorantFrameData, )

        game_data_factory = ValorantFrameData
    elif game == "overwatch":
        from overtrack_cv_private.games.overwatch.overwatch_frame_data import (
            OverwatchFrameData, )

        game_data_factory = OverwatchFrameData

    import numpy as np

    if warmup:
        for _ in range(10):
            proc.run(
                Frame.create(np.zeros((1080, 1920, 3), dtype=np.uint8),
                             0,
                             warmup=True,
                             **{game: game_data_factory()}))

    if not images:
        images = os.path.join(os.path.dirname(inspect.getfile(proc.__class__)),
                              "samples", "*")

    if isinstance(images, list):
        config_logger("test_processor", logging.DEBUG, False)
        paths = images
    else:
        config_logger(os.path.basename(images), logging.DEBUG, False)
        if "*" in images:
            paths = glob.glob(images)
        elif images.endswith(".png"):
            paths = [images]
        elif images[1] == ":":
            paths = glob.glob(images + "/*")
        else:
            paths = glob.glob(os.path.join(images, "*"))
        paths.sort(key=lambda p: os.path.getmtime(p), reverse=True)

    if test_all:
        paths += glob.glob(
            os.path.join(
                os.path.dirname(__file__),
                "..",
                "games",
                game or ".",
                "**",
                "samples",
                "*.png",
            ))

    for p in paths:
        if not (p.endswith(".png") or p.endswith(".jpg")
                or p.endswith(".jpeg")):
            continue

        time.sleep(0.01)
        print("\n\n" + "-" * 32)
        print(os.path.abspath(p))

        im = cv2.imread(p)

        ratio = im.shape[0] / im.shape[1]
        if round(ratio, 2) != 0.56:
            logger.warning(
                f"Ignoring {p} had invalid aspect ratio - dimensions were {im.shape}"
            )
            continue

        im = cv2.resize(im, (1920, 1080))
        f = Frame.create(im,
                         os.path.getctime(p),
                         debug=True,
                         **{game: game_data_factory()})
        f.source_image = p
        if "game_time=" in p:
            f.game_time = float(
                os.path.basename(p).split("=", 1)[1].rsplit(".", 1)[0])

        f.current_game = CurrentGame()

        stats = proc.run(f)
        debug_image = f.debug_image

        f.strip()

        # print(json.dumps(frameload.frames_dump(f, numpy_support=True), indent=2))

        def getval(f: Frame, n: str):
            v = f
            for p in n.split("."):
                v = getattr(v, p, None)
                if not v:
                    return None
            return v

        if game:
            fields = list(fields)  # + [game]

        # def pformat(v):

        print(
            tabulate.tabulate(
                [("source_image", p), ("processor_result", stats.result)] +
                [(f"{game}.{fl}", getattr(getattr(f, game), fl, None))
                 for fl in fields]
                # +
                # [
                # 	(
                # 		n,
                # 		pformat(getval(f, n))
                # 	)
                # 	for n in fields
                # ]
            ))
        pprint(stats)
        print(stats.duration * 1000)
        # if game:
        #     pprint(getattr(f, game))
        # print()

        if show:
            cv2.imshow("debug", debug_image)
            if wait == "sometimes":
                c = cv2.waitKey(0 if stats.result else 1)
            else:
                c = cv2.waitKey(0 if wait else 1)
            if c == 115:
                os.remove(p)

        print("-" * 32)
コード例 #13
0
def main() -> None:
    config_logger("big_noodle", logging.DEBUG, False)

    # from tensorflow.python.keras import Input
    # from tensorflow.python.keras.layers import Conv2D
    # from tensorflow.python.keras import Model
    # from tensorflow.python.keras.layers import Layer
    # from tensorflow.python.keras.saving import export_saved_model
    # from tensorflow.python.keras.layers import Lambda
    #
    # image = Input(shape=(Decoder.IMAGE_HEIGHT, Decoder.IMAGE_WIDTH, 3), name='images', dtype=tf.float32)
    # image_norm = Lambda(lambda i: i / 255.0 - 0.5)(image)
    # conv1 = Conv2D(
    #     Decoder.CONV1_LAYERS,
    #     Decoder.CONV1_SIZE,
    #     activation='relu',
    #     padding='same',
    #     name='conv1'
    # )(image_norm)
    # conv1_pad = Pad(
    #     ((0, 0), (0, 0), (0, Decoder.CONV2_WIDTH - 1), (0, 0))
    # )(conv1)
    # conv2 = Conv2D(
    #     len(Decoder.CHARACTERS) + 1,
    #     (Decoder.IMAGE_HEIGHT - 2, Decoder.CONV2_WIDTH),
    #     activation=None,
    #     padding='valid',
    #     name='conv2'
    # )(conv1_pad)
    # logits = MaxAlongDims(dims=(1, ))(conv2)
    #
    # model = Model(
    #     inputs=image,
    #     outputs=logits
    # )
    # model.compile(
    #     optimizer='adam',
    #     loss='binary_crossentropy'
    # )
    # model.summary()
    #
    # p = os.path.join(os.path.dirname(__file__), 'data', 'big_noodle_ctc.npz')
    # restore_dict = dict(np.load(p))
    # print({k: v.shape for k, v in restore_dict.items()})
    #
    # l: Layer = model.layers[2]
    # print(l, [w.shape for w in l.get_weights()])
    # l.set_weights([restore_dict['conv1/kernel:0'], restore_dict['conv1/bias:0']])
    #
    # l: Layer = model.layers[4]
    # print(l, [w.shape for w in l.get_weights()])
    # l.set_weights([restore_dict['conv2/kernel:0'], restore_dict['conv2/bias:0']])
    #
    # os.makedirs('./data/big_noodle_ctc')
    # export_saved_model(model, f'./data/big_noodle_ctc', serving_only=True)

    image = cv2.imread("C:/tmp/test.png")
    for _ in range(10):
        print(ocr(image))
    for _ in range(10):
        print(ocr_all([image, np.hstack((image, image))]))