def main():
    """
        Profile:
            9522
            8582: Optimized match pixel
            93.22: Find by run, mostly using Numpy

        Iterations:
            6167
            6071
    """
    file_names = glob('data/*')
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}
    indexed = {k: index_sprite(v) for k, v in sprites.items()}
    sprites = {
        #'small_jump': sprites['small_jump'],
        'qblock_1': sprites['qblock_1'],
        #'qblock_2': sprites['qblock_2'],
        #'qblock_3': sprites['qblock_3'],
    }
    # sprite_runs = {k: np_reduce_by_run(v, transparency=True) for k, v in sprites.items()}

    accume = 0
    for fn in range(len(file_names))[1224:1234]:
        cprint('{}: {}'.format(accume, fn), 'cyan')
        fn = 'data/{}.png'.format(fn)
        original = cv2.imread(fn, cv2.IMREAD_COLOR)  # [300:, :]

        image = reduce_image(original)
        find_sprites_by_run(image, sprites, original)
        sys.exit()
Exemple #2
0
def main():
    """
        Profile:
            9522
            8582: Optimized match pixel
            93.22: Find by run, mostly using Numpy

        Iterations:
            6167
            6071
    """
    file_names = glob('data/*')
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}
    indexed = {k: index_sprite(v) for k, v in sprites.items()}
    sprites = {
        #'small_jump': sprites['small_jump'],
        'qblock_1': sprites['qblock_1'],
        #'qblock_2': sprites['qblock_2'],
        #'qblock_3': sprites['qblock_3'],
    }
    # sprite_runs = {k: np_reduce_by_run(v, transparency=True) for k, v in sprites.items()}

    accume = 0
    for fn in range(len(file_names))[1224:1234]:
        cprint('{}: {}'.format(accume, fn), 'cyan')
        fn = 'data/{}.png'.format(fn)
        original = cv2.imread(fn, cv2.IMREAD_COLOR)  # [300:, :]

        image = reduce_image(original)
        find_sprites_by_run(image, sprites, original)
        sys.exit()
Exemple #3
0
def main():
    np.set_printoptions(linewidth=150)

    # Read the code for this file and hash it
    with open('sprite_tree.py', 'r') as fp:
        my_hash_value = sha1(fp.read()).hexdigest()

    # The pickling should really be done in the sprite_tree, but this is less
    # of a PITA
    file_name = 'pickled_sprites/{}'.format(my_hash_value)
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}
    if os.path.exists(file_name):
        cprint('Unpickling SpriteTree', 'green')
        with open(file_name, 'r') as fp:
            st = pickle.load(fp)
    else:
        cprint('Pickling SpriteTree', 'yellow')
        st = SpriteTree(sprites)
        with open(file_name, 'w') as fp:
            pickle.dump(st, fp)

    img_f = ImageFactory(sprites, background_color=(255, 132, 138))

    image = np.zeros((224, 256, 3), dtype='ubyte')
    for row in image:
        for px in row:
            np.copyto(px, img_f._bg_color)

    s = sprites['small_jump']
    # blit(self, image, sprite, mask, x, y):
    image = img_f.blit(image, s[:, :, :3], s[:, :, 3], 50, 50)
    si = SegmentedImage(st, image)
    print(np.nonzero(np.where(si._hashed == si.background_color(), 0, si._hashed)))
    bounding_boxes, names = si.find_sprites()
    cprint(bounding_boxes, 'cyan')
    cprint(names, 'blue')
    sys.exit()

    file_names = glob('data/*')
    images = []
    for fn in range(len(file_names))[1224:3224]:
        fn = 'data/{}.png'.format(fn)
        original = cv2.imread(fn, cv2.IMREAD_COLOR)  # [300:, :]
        image = reduce_image(original)
        images.append(image)

    start = time.time()
    for i, image in enumerate(images):
        si = SegmentedImage(st, image)
        si.find_sprites()
        cprint((time.time() - start) / float(i + 1), 'green')

    cprint((time.time() - start) / 1000.0, 'green')
def main():
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}
    #sprites = {
    #    'small_jump': sprites['small_jump'],
    #    'big_run_1': sprites['big_run_1'],
    #    'big_run_3': sprites['big_run_3'],
    #}
    st = SpriteTree(sprites)

    probs = st.get_horizontal_probability(3, 3)
    named_probs = sorted(zip(st._names, probs), key=lambda a: a[1])

    for n, p in named_probs:
        print('{}: {}'.format(n, p))
    print
def main():
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}
    #sprites = {
    #    'small_jump': sprites['small_jump'],
    #    'big_run_1': sprites['big_run_1'],
    #    'big_run_3': sprites['big_run_3'],
    #}
    st = SpriteTree(sprites)

    probs = st.get_horizontal_probability(3, 3)
    named_probs = sorted(zip(st._names, probs), key=lambda a: a[1])

    for n, p in named_probs:
        print('{}: {}'.format(n, p))
    print
def main():
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}

    img_factory = ImageFactory(sprites, background_color=(255, 132, 138))
    blitted = img_factory.new_image(num_sprites=10)
    show_image(blitted['image'])
def main():
    sprites = {k: reduce_image(v) for k, v in get_sprites('sprites').items()}

    img_factory = ImageFactory(sprites, background_color=(255, 132, 138))
    blitted = img_factory.new_image(num_sprites=10)
    show_image(blitted['image'])