Esempio n. 1
0
 def __init__(self, init_x, init_y, index_nav):
     super().__init__()
     self.x = init_x
     self.y = init_y
     self.status = random.randint(0, 2)
     self.IMAGES = [
         loader.load_image("green_light.png"),
         loader.load_image("yellow_light.png"),
         loader.load_image("red_light.png")
     ]
     self.image = self.IMAGES[self.status]
     self.remaining_time = self.cal_remain_time()
     self.index_nav = index_nav
     self.rect = self.image.get_rect()
     self.rect.center = self.x, self.y
Esempio n. 2
0
    def generate(self, source, destination = None, samples = 20, grid_width=480, grid_height=240):
        # Load the input and output of the graph
        input  = self.graph.get_tensor_by_name("en_input:0"        )
        output = self.graph.get_tensor_by_name("decoder/main_out:0")

        # For generating a single image for a source image
        if os.path.isfile(source):
            image = loader.load_image(source, self.image_size, self.image_size)
            batch = np.asarray([image for _ in range(self.batch_size)])
            preds = self.session.run(output, feed_dict = {input: batch})
            batch[0] = utils.add_border(batch[0],color = [1.0,0.0,0.0])
            grid  = np.concatenate((batch[0], preds[0]), axis=1)
            grid  = (grid * 255.0).astype(np.uint8)
        # For generating a grid of images from a directory of images
        elif os.path.isdir(source):
            data = loader.DataSet(images_dir = source,
                                  hard_load  = False,
                                  width      = self.image_size,
                                  height     = self.image_size)
            batch,_= data.next_batch(self.batch_size)

            preds  = self.session.run(output, feed_dict={input: batch})
            for i in range(samples):
                batch[i] = utils.add_border(batch[i],color = [1.0,0.0,0.0])
            grid = self.construct_image_grid(batch,preds,samples,grid_width,grid_height)
        else:
            print(source,"must be an image pathname or a directory of images")
            sys.exit()

        if destination:
            cv2.imwrite(destination, grid)
        else:
            cv2.imshow("images", grid)
            cv2.waitKey()
Esempio n. 3
0
    def __init__(self, init_x, init_y):
        super().__init__()
        self.image = loader.load_image("map.png")
        self.rect = self.image.get_rect()
        self.x = init_x
        self.y = init_y

        self.get_map_nav()
        self.get_edges()
        self.shortest_paths = self.find_shortest_paths()
        self.get_light_pos()
Esempio n. 4
0
 def __init__(self, init_x, init_y, index_nav):
     super().__init__()
     self.x = init_x
     self.y = init_y
     self.image_ori = loader.load_image('stone.png')
     self.image = self.image_ori
     self.rect = self.image.get_rect()
     self.rect.center = self.x, self.y
     self.index_nav = index_nav
     self.status = config.HIDDEN
     self.time_appearance = 0
Esempio n. 5
0
    def __init__(self, image, label=""):
        """
        Initialize the detector with an image an a label

        :type image: numpy.ndarray
        :param image: Image to be processed
        :type label: str
        :param label: Optional label for the image
        """

        self.image = loader.load_image(image)
        self.label = label
    def __init__(self, image, label=""):
        """
        Initialize the detector with an image an a label

        :type image: numpy.ndarray
        :param image: Image to be processed
        :type label: str
        :param label: Optional label for the image
        """

        self.image = loader.load_image(image)
        self.label = label
Esempio n. 7
0
    def predict(self, image_path, label=4, max_labels=10):
        image = loader.load_image(image_path, self.image_size, self.image_size)
        x_batch = np.asarray([image for _ in range(self.batch_size)])

        labels = np.zeros(max_labels)
        labels[label] = 1.0
        y_batch = np.asarray([labels for _ in range(self.batch_size)])

        output = self.graph.get_tensor_by_name("decoder/main_out:0")
        input = self.graph.get_tensor_by_name("en_input:0")
        label = self.graph.get_tensor_by_name("labels:0")

        preds = self.session.run(output,
                                 feed_dict={
                                     input: x_batch,
                                     label: y_batch
                                 })

        return x_batch[0], preds[0]
Esempio n. 8
0
    def __init__(self):
        super().__init__()
        self.fuzzy_monitor = fuzzy_controller.FuzzyController()
        self.path = []
        self.image = loader.load_image("car.png", False)
        self.image_ori = self.image
        self.color = config.BLACK
        self.x = MAP_NAVS[0][0] - config.PARA
        self.y = MAP_NAVS[0][1] + config.PARA

        self.dir = 90.0
        self.speed = 0.3
        self.deviation = 0.0
        self.angle_deviation = 0.0
        self.acceleration = 0
        self.lights = []

        self.desired_dir = 90.0
        self.cur_nav = 0
        self.turn = config.STRAIGHT
        self.central_point = (0, 0)
        self.rect = self.image.get_rect(center=(self.x, self.y))
        self.image, self.rect = rot_center(self.image_ori, self.rect, self.dir)
Esempio n. 9
0
from utils.options import parser
from utils.loader import load_model, load_image, tensor2im
from PIL import Image

if __name__ == "__main__":
    args = parser.parse_args()
    model = load_model(args.model)
    model.setup()

    image = load_image(args.image, args.model)

    model.set_input(image)
    model.test()

    fake = model.get_generated()
    fake = tensor2im(fake)

    image_pil = Image.fromarray(fake)
    image_pil.save(f'{args.save_to}/{args.model}.jpg')
 def __init__(self, image):
     self.image = loader.load_image(image)