Exemplo n.º 1
0
    def set_trap(self, type):
        '''(StaticTile, Surface) -> NoneType
        '''
        self.trap = True

        if (type == "FIRE"):
            self.trapimg = load_img("Fire2.png")
        elif (type == "SPIKE"):
            self.trapimg = load_img("Spike.png")
        elif (type == "POOP"):
            self.trapimg = load_img("Poop.png")
        else:
            self.trapimg = load_img("Poop.png")
def load_cont_img(image='./data/img/file.jpg', scale=0.1):
    content = img.load_img(image)
    height, width, _ = content.shape
    height = int(height * scale)
    width = int(width * scale)
    content = img.resize_img(content, height, width)
    return np.array([img.convert_img(content)])
Exemplo n.º 3
0
 def __init__(self, X, Y):
     '''(Player, int, int) -> NoneType
     (X,Y) are the coordinates (in tiles) of the player
     '''
     self.x = X
     self.y = Y
     self.rect = None
     self.update_rect()
     self.img = load_img("Bob.png")
     self.sum = 0
     self.keys = 0 # Number of keys in inventory
     self.win = False # Wins when reaches exit
Exemplo n.º 4
0
 def load_trapimg(self, IMG):
     '''(Tile, str) -> NoneType
     Load IMG into self.trapimg. Assumes we want a trap here.
     '''
     self.trapimg = load_img(IMG)
Exemplo n.º 5
0
 def load_img(self, IMG_N):
     '''(Tile, str) -> NoneType
     Loads img given by IMG_N into self.img as Surface. Assumes
     IMG_N valid.'''
     self.img = load_img(IMG_N)
Exemplo n.º 6
0
The original caffemodel:
	www.robots.ox.ac.uk/~vgg/research/very_deep/
has been translated in to numpy's ndarray:
	https://mega.nz/#!xZ8glS6J!MAnE91ND_WyfZ_8mvkuSa2YcA7q-1ehfSm-Q1fxOvvs
This implementation is adapted from :
	https://github.com/machrisaa/tensorflow-vgg.git
'''
import sys
sys.path.append('./utils')
import numpy as np
import tensorflow as tf
import img
import vgg

# load images and vgg19 coefficients
bgr = np.array([
    img.convert_img(img.resize_img(img.load_img('./data/img/tiger.jpg'))),
    img.convert_img(img.resize_img(img.load_img('./data/img/file.jpg'))),
])
vgg19 = vgg.VGG19('./data/vgg19.npy')

# build vgg19
_, height, width, _ = bgr.shape
x_bgr = vgg19.input_bgr(height, width)
vgg19.build_upto(x_bgr, 'prob')

# object classification
with tf.Session() as sess:
    prob = vgg19.layers['prob'].eval(feed_dict={x_bgr: bgr})
vgg19.predict(prob)
def load_sty_imgs(imgs=['./data/img/art1.jpg']):
    sty_imgs = []
    for image in imgs:
        sty_imgs.append(np.array([img.convert_img(img.load_img(image))]))
    return sty_imgs
Exemplo n.º 8
0
    end_time = time.time()
    if loss < best_loss:
        best_loss = loss  # updating best loss
        best_img = deprocess_img(init_image.numpy())  # updating best image
    if i % display_interval == 0:  # getting numpy array for images
        plot_img = deprocess_img(init_image.numpy())
        imgs.append(plot_img)
        IPython.display.clear_output(wait=True)
        IPython.display.display_png(PIL.Image.fromarray(plot_img))
print('\nTotal time: {:.4f}s'.format(time.time() - global_start))

# displaying results
IPython.display.clear_output(wait=True)
plt.figure(figsize=(14, 4))
for i, img in enumerate(imgs):
    plt.subplot(num_rows, num_cols, i + 1)
    plt.imshow(img)
    plt.xticks([])
    plt.yticks([])
PIL.Image.fromarray(best_img)
plt.figure(figsize=(10, 5))
content, style = load_img(content_path), load_img(style_path)
plt.subplot(1, 2, 1)
imshow(content, 'Content Image')
plt.subplot(1, 2, 2)
imshow(style, 'Style Image')
plt.figure(figsize=(10, 10))
plt.imshow(best_img)
plt.title('Output Image')
plt.show()
Exemplo n.º 9
0
    from Tkinter import Tk, Canvas, PhotoImage

    root = Tk()
    root.title('MineSweeper')
    root.geometry(str(size_game[0] * 25) + 'x' + str(size_game[1] * 25 + 45))
    root.resizable(False, False)
    root.protocol('WM_DELETE_WINDOW', e)
    #i=PhotoImage(file='data/ico.png')
    #root.call('wm','iconphoto',root._w,i)

    import main
    from header import header
    from img import load_img
    flag_number = [boom_number[0]]
    game_status = ['normal']
    img = load_img()

    root.call('wm', 'iconphoto', root._w, img['icon'])

    h = header()
    h.frame = [Canvas(root)]
    h.frame[0].place(x=0, y=10, height=25, relwidth=1.0)
    h.flag_number = flag_number
    h.img = img
    h.exit = exit
    h.status = game_status
    h.list_cell = main.list_cell
    h.size_game = size_game

    main.frame = [Canvas(root)]
    main.frame[0].place(x=0, y=45, height=size_game[1] * 25, relwidth=1.0)
Exemplo n.º 10
0
    # init rendering
    update_queue = deque() # Queue of rects specifying areas of display to update

    background = Background(WINDOW_WIDTH, WINDOW_HEIGHT, GREY)
    background.render(screen, update_queue)

    # draw a bunch of garbage cans (debug)
    gbg_can_size = IMG_SIZES["garbage_can"]

    x_coord = TILE_SIZE * 3
    while x_coord < TILE_SIZE * 10:
        y_coord = TILE_SIZE * 3
        while y_coord < WINDOW_HEIGHT:
            gbg_can = Obj(x_coord, y_coord, gbg_can_size[0], gbg_can_size[1])

            gbg_can.img = load_img(GBG_CAN_N)
            gbg_can.render(screen, update_queue)

            env_obj_list.append(gbg_can)

            y_coord += TILE_SIZE * 2

        x_coord += TILE_SIZE * 2

    # Draw player (debug)
    player_size = IMG_SIZES["man_standing"]
    player = Player(WINDOW_WIDTH, WINDOW_HEIGHT, player_size[0], player_size[1])
    player.img = load_img(MAN_STAND_N)
    player.render(screen, update_queue)

    # create a capture bot (debug)
Exemplo n.º 11
0
    def load(self, ZONE_N):
        '''(Zone, str) -> NoneType
        Loads Zone from Zone given in ZONE_N. Assumes success. Format for
        map files:

        min <int_value>
        max <int_value>
        img <index> <img_name>
        ...
        map
        XYZ ...
        ...

        min, max - optional entries to specific inclusive range for randomly
                   generated integers for tile values, which is used if given
                   a ? character
        img      - optional entry or entries to specify images for tiles
                   (images are not required by tiles). <img_name> is added to
                   a list, and <index> corresponds with the index in the list.
        map      - an array of tile entries, which are X,Y,Z,U , separated by spaces.
                   X is the type of tile to be loaded: 0 for default tile, 1
                   for trap, 2 is wall, 3 is key, 4 is lock, 5 is exit. Y is
                   the img index for the primary img to be used, where 0 means
                   no img. Z is the value
                   to be given to the tile, where ? means a random value
                   generated using min, max. U is the secondary img to be used, 0
                   for no img.'''
        TILE_SIZE = get_tile_size()

        # Seed random in case random values are to be generated
        random.seed()

        PATH = _get_zone_path(ZONE_N)
        with open(PATH) as FILE:
            min = None
            max = None
            img_list = [None] # None there for use of 0 for no img

            line = FILE.readline()
            while line:
                data = line.split()
                if data[0] == "min":
                    min = int(data[1])
                elif data[0] == "max":
                    max = int(data[1])
                elif data[0] == "start":
                    coord = (int(data[1]), int(data[2]))
                elif data[0] == "img":
                    img_list.append(data[2])
                elif data[0] == "map":
                    # Map is rest of file
                    line = FILE.readline()
                    for i in range(self.num_tiles_h): # Row number of data
                        data = line.split()
                        for j in range(self.num_tiles_w): # Column number of data
                            tile = data[j].split(",")

                            tile_s = Tile(j * TILE_SIZE, i * TILE_SIZE)
                            img_index = int(tile[1])
                            sec_img_index = int(tile[3])

                            #loads the image of the tile
                            if img_index:
                                tile_s.load_img(img_list[img_index])

                            #gives the tile a value
                            if tile[2] == "?":
                                # Randomize value given by min, max
                                tile_s.value = random.randint(min, max)
                            else:
                                tile_s.value = int(tile[2])

                            # Determine tile type
                            if tile[0] == "0": # Normal
                                pass
                            elif tile[0] == "1": # Trap
                                tile_s.trap = True
                                tile_s.load_trapimg(img_list[sec_img_index])
                            elif tile[0] == "2": # Wall
                                tile_s.wall = True
                                tile_s.wall_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "3": # Key
                                tile_s.key = True
                                tile_s.key_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "4": # Lock
                                tile_s.lock = True
                                tile_s.lock_img = load_img(img_list[sec_img_index])
                            elif tile[0] == "5": # Exit
                                tile_s.exit = True
                                tile_s.exit_img = load_img(img_list[sec_img_index])

                            self.map[j][i] = tile_s

                        line = FILE.readline()

                line = FILE.readline()

        self.player = Player(*coord) # Starting coords