示例#1
0
def classification_score():
    """
    Test the classificarion score on the basic CNN
    """
    basic = BasicCNN()
    model = basic.get_model()
    data_training, labels = get_dataset_classification_only(1000)

    evaluation = basic.evaluate_model(np.array(data_training))
    evaluation = [Image(i, np.argmax(j[0]), 0, 0, 0, 0) for i, j in enumerate(evaluation)]
    labels = [Image(i, j, 0, 0, 0, 0) for i, j in enumerate(labels)]
    metric = calculate_metric_classification(evaluation, labels)
    return metric
示例#2
0
    def create_randomImages(self, number):
        images = []
        for i in range(number):
            classification = random.randint(0, 2)
            if classification == 0:
                images.append(Image(i, 0, 0, 0, 0, 0))
            elif classification == 1:
                images.append(
                    Image(i, 1,
                          random.random() * 24,
                          random.random() * 24, 0, 0))
            else:
                images.append(Image(i, 1, random.random() * 24, random.random() * 24, \
                    random.random() * 24, random.random() * 24))

        return images
示例#3
0
def generate_img_8a(C=400):
    '''Image "Węzeł z pięcioma prądami"'''
    image = Image((int(C * 2), int(C * 2)), line_width=6, vector_arrow_size=30)
    image.draw_point((C, C), width=20)
    out_param_list = [
        (0, [190, 0, 0]),
        (40, [190, 0, 0]),
        (320, [190, 0, 0]),
    ]
    in_param_list = [
        (140, [0, 20, 190]),
        (180, [0, 20, 190]),
        (220, [0, 20, 190]),
    ]
    for rotation, arrow_color in out_param_list:
        vector = Vector.from_rotation((C, C), rotation, int(C * 0.5))
        vector2 = Vector.from_rotation((C, C), rotation, int(C * 0.5))
        vector2.scale(1.3)
        line = Line.from_vector(vector2)
        image.draw_line(line)
        image.draw_vector(vector, arrow_color=arrow_color)
    for rotation, arrow_color in in_param_list:
        vector = Vector.from_rotation((C, C), rotation, int(C * 0.5))
        vector = Vector.from_reversed(vector)
        vector.scale(1 - (1 / 1.3))
        vector2 = Vector.from_rotation((C, C), rotation, int(C * 0.5))
        vector2.scale(1.3)
        line = Line.from_vector(vector2)
        image.draw_line(line)
        image.draw_vector(vector, arrow_color=arrow_color)
    image.save('img/img_8a.png')
示例#4
0
def main():
    args = parse_args()

    proxy = setup_proxy(args.proxy_url, args.proxy_auth)


    if not args.QR_text == "":
        args.file = "./img/QRcode.png"
        Image.create_QR_image(args.QR_text, args.QR_scale)

    image = Image(args.file, args.round_sensitive, args.image_brightness)

    bot = Bot(image, args.fingerprint, args.start_x, args.start_y, args.mode_defensive, args.colors_ignored, args.colors_not_overwrite, args.min_range, args.max_range, proxy,
              args.draw_strategy, args.xreversed, args.yreversed)

    bot.init()

    def run():
        try:
            bot.run()
        except NeedUserInteraction as exception:
            alert(str(exception))
            try:
                if raw_input(I18n.get('token_resolved')).strip() == 'y':
                    run()
            except NameError as e:
                if input(I18n.get('token_resolved')).strip() == 'y':
                    run()

    run()
示例#5
0
文件: gui.py 项目: menshiva/ascii-art
    def __preview_art(self, name: str, path: str, contrast: bool,
                      negative: bool, sharpen: bool, emboss: bool,
                      grayscale: str) -> None:
        """
        Qt slot for image previewing.

        Args:
            name: str
                Image's name.
            path: str
                Path to image file.
            contrast: bool
                Image's contrast flag.
            negative: bool
                Image's negative flag.
            sharpen: bool
                Image's sharpen flag.
            emboss: bool
                Image's emboss flag.
            grayscale: str
                Image's grayscale level.

        Returns:
            None.
        """

        self.on_preview_art(
            self,
            Image(name, path, contrast, negative, sharpen, emboss, grayscale))
示例#6
0
 def create_1_images(self, number):
     images = []
     for i in range(number):
         images.append(
             Image(i, 1,
                   random.random() * 24,
                   random.random() * 24, 0, 0))
     return images
示例#7
0
文件: dead.py 项目: jtietema/pyrio
 def get_image(self):
     """Returns the source image if we are still in still phase, otherwise returns
     a rotated and scaled image."""
     if self.still:
         return self.image
     else:
         surface = pygame.transform.rotozoom(self.image.get_surface(),
                                             self.angle, self.scale)
         offset_x, offset_y = self.image.get_offset()
         return Image(surface, (offset_x, offset_y))
示例#8
0
def main():
    args = parse_args()

    proxy = setup_proxy(args.proxy_url, args.proxy_auth)

    image = Image(args.file)

    bot = Bot(image, args.fingerprint, args.start_x, args.start_y, args.mode_defensive, args.colors_ignored, proxy, args.draw_strategy)

    bot.run()
示例#9
0
def generate_img_2b(C=400):
    '''Image "Linie pola ekektr wokół 2 punktowych ładunków jednoimiennych"'''
    image = Image((C * 4, C * 2), line_width=3)
    # left
    image.draw_circle(Circle((C, C), int(C * 0.4)), fill=[190, 0, 0], width=10)
    image.draw_line(Line((C, int(C + (C * 0.1))), (C, int(C - (C * 0.1)))),
                    fill=[190, 0, 0])
    image.draw_line(Line((int(C + (C * 0.1)), C), (int(C - (C * 0.1)), C)),
                    fill=[190, 0, 0])
    # right
    image.draw_circle(Circle((3 * C, C), int(C * 0.4)),
                      fill=[190, 0, 0],
                      width=10)
    image.draw_line(Line((3 * C, int(C + (C * 0.1))),
                         (3 * C, int(C - (C * 0.1)))),
                    fill=[190, 0, 0])
    image.draw_line(Line((int(3 * C + (C * 0.1)), C),
                         (int(3 * C - (C * 0.1)), C)),
                    fill=[190, 0, 0])
    # vertical
    image.draw_line(Line((2 * C, 0), (2 * C, 2 * C)), width=1)
    # vectors
    image.draw_vector(
        Vector((int(C * 1.5), int(C * 1.1)), (int(C * 0.25), int(C * 0.3))))
    image.draw_vector(
        Vector((int(C * 1.5), int(C * 0.9)), (int(C * 0.25), -int(C * 0.3))))
    image.draw_vector(Vector((int(C * 1.8), int(C * 1.5)), (0, int(C * 0.4))))
    image.draw_vector(Vector((int(C * 1.8), int(C * 0.5)), (0, -int(C * 0.4))))
    image.draw_vector(
        Vector((int(C * 2.5), int(C * 1.1)), (-int(C * 0.25), int(C * 0.3))))
    image.draw_vector(
        Vector((int(C * 2.5), int(C * 0.9)), (-int(C * 0.25), -int(C * 0.3))))
    image.draw_vector(Vector((int(C * 2.2), int(C * 1.5)), (0, int(C * 0.4))))
    image.draw_vector(Vector((int(C * 2.2), int(C * 0.5)), (0, -int(C * 0.4))))
    #
    image.draw_vector(
        Vector((int(C * 1.4), int(C * 1.25)), (int(C * 0.20), int(C * 0.40))))
    image.draw_vector(
        Vector((int(C * 1.4), int(C * 0.75)), (int(C * 0.20), -int(C * 0.40))))
    image.draw_vector(
        Vector((int(C * 2.6), int(C * 1.25)), (-int(C * 0.20), int(C * 0.40))))
    image.draw_vector(
        Vector((int(C * 2.6), int(C * 0.75)),
               (-int(C * 0.20), -int(C * 0.40))))
    #
    image.draw_vector(
        Vector((int(C * 1.2), int(C * 1.4)), (int(C * 0.1), int(C * 0.5))))
    image.draw_vector(
        Vector((int(C * 1.2), int(C * 0.6)), (int(C * 0.1), -int(C * 0.5))))
    image.draw_vector(
        Vector((int(C * 2.8), int(C * 1.4)), (-int(C * 0.1), int(C * 0.5))))
    image.draw_vector(
        Vector((int(C * 2.8), int(C * 0.6)), (-int(C * 0.1), -int(C * 0.5))))
    image.save('img/img_2b.png')
示例#10
0
def factory():
    from src.factory import ArtFactory
    from src.image import Image
    factory = ArtFactory()
    for i in range(10):
        factory += Image(
            f"Lenna{i}", "",
            False, False, False, False,
            ""
        )
    return factory
示例#11
0
def generate_img_1b(C=400):
    '''Image "Linie pola ekektr wokół punktowego ładunku ujemnego"'''
    image = Image((C * 2, C * 2), line_width=3)
    image.draw_circle(Circle((C, C), int(C * 0.4)), fill=[0, 0, 190], width=10)
    image.draw_line(Line((int(C + (C * 0.1)), C), (int(C - (C * 0.1)), C)),
                    fill=[0, 0, 190])
    for deg in range(0, 360, 360 // 12):
        prevector = Vector.from_rotation((C, C), deg, int(C * 0.95))
        vector = Vector.from_reversed(prevector)
        vector.scale(0.45)
        vector.round()
        image.draw_vector(vector)
    image.save('img/img_1b.png')
示例#12
0
def generate_img_5a(C=400):
    '''Image "Symbol ogólny kondensatora"'''
    image = Image((int(C * 2), int(C * 2)), line_width=6)
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 0.5)), (int(C * 5 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 0.5)), (int(C * 7 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 1)), (int(C * 1 / 4), int(C * 1))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 1)), (int(C * 7 / 4), int(C * 1))))
    image.draw_point((int(C * 1 / 4), int(C * 1)), width=20)
    image.draw_point((int(C * 7 / 4), int(C * 1)), width=20)
    image.save('img/img_5a.png')
示例#13
0
    def run(self):
        while True:
            try:
                quote = quotes_generator.generate()[0]

                quote = self.clean_quote(quote)

                self.logger.info('Quote: %s' % quote)

                if len(quote) > self.max_quote_length:
                    self.logger.warning('Quote too long!')
                    continue

                quote_vector = self.similarity.get_vector(text=quote)
                keywords = self.similarity.get_keywords(
                    text=quote, num=config.NUMBER_OF_KEYWORDS)
                self.logger.info('Keywords: %s' % ','.join(keywords))

                photos = self.unsplash.get_photos(
                    query=','.join(keywords),
                    num=config.UNSPLASH_PHOTOS_TO_ANALYSE)
                self.logger.info('Unsplash found photos: %s' % len(photos))

                if not photos:
                    self.logger.warning('No Unsplash photos found!')
                    continue

                photo = self.get_best_photo(photos=photos,
                                            quote_vector=quote_vector)
                self.logger.info(photo)

                image = Image(url=photo[1])
                image.draw_text(text=quote)
                image_file_path = image.save(
                    file_path=config.QUOTES_IMAGES_PATH)

                self.reddit.post(text='<...>%s<...> %s, %s' %
                                 (quote, '\n', photo[3]),
                                 image_path=image_file_path)

                self.logger.info('Posted to reddit!')

                time.sleep(config.GENERATION_TIMEOUT)
            except KeyboardInterrupt:
                self.logger.info('Stoping!')
                break
            except:
                self.logger.exception(traceback.format_exc())
                time.sleep(60)
示例#14
0
def generate_img_5b(C=400):
    '''Image "Symbol kondensatora regulowanego"'''
    image = Image((int(C * 2), int(C * 2)), line_width=6)
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 0.5)), (int(C * 5 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 0.5)), (int(C * 7 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 1)), (int(C * 1 / 4), int(C * 1))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 1)), (int(C * 7 / 4), int(C * 1))))
    image.draw_point((int(C * 1 / 4), int(C * 1)), width=20)
    image.draw_point((int(C * 7 / 4), int(C * 1)), width=20)
    image.draw_vector(Vector((int(C * 0.5), int(C * 1.5)),
                             (int(C * 1), -int(C * 1))),
                      width=8)
    image.save('img/img_5b.png')
示例#15
0
def generate_img_2a(C=400):
    '''Image "Linie pola ekektr wokół 2 punktowych ładunków różnoimiennych"'''
    image = Image((C * 4, C * 2), line_width=3)
    # pos
    image.draw_circle(Circle((C, C), int(C * 0.4)), fill=[190, 0, 0], width=10)
    image.draw_line(Line((C, int(C + (C * 0.1))), (C, int(C - (C * 0.1)))),
                    fill=[190, 0, 0])
    image.draw_line(Line((int(C + (C * 0.1)), C), (int(C - (C * 0.1)), C)),
                    fill=[190, 0, 0])
    # neg
    image.draw_circle(Circle((3 * C, C), int(C * 0.4)),
                      fill=[0, 0, 190],
                      width=10)
    image.draw_line(Line((int(3 * C + (C * 0.1)), C),
                         (int(3 * C - (C * 0.1)), C)),
                    fill=[0, 0, 190])
    # straight vectors
    image.draw_vector(Vector((int(C * 1.5), C), (int(C * 0.4), 0)))
    image.draw_vector(Vector((int(C * 1.5), int(C * 1.2)), (int(C * 0.4), 0)))
    image.draw_vector(Vector((int(C * 1.5), int(C * 0.8)), (int(C * 0.4), 0)))
    image.draw_vector(Vector((int(C * 2.1), C), (int(C * 0.4), 0)))
    image.draw_vector(Vector((int(C * 2.1), int(C * 1.2)), (int(C * 0.4), 0)))
    image.draw_vector(Vector((int(C * 2.1), int(C * 0.8)), (int(C * 0.4), 0)))
    # slightly curved vectors
    image.draw_vector(
        Vector((int(C * 1.5), int(C * 1.4)), (int(C * 0.4), int(C * 0.05))))
    image.draw_vector(
        Vector((int(C * 2.1), int(C * 1.45)), (int(C * 0.4), int(C * -0.05))))
    image.draw_vector(
        Vector((int(C * 1.5), int(C * 0.6)), (int(C * 0.4), int(C * -0.05))))
    image.draw_vector(
        Vector((int(C * 2.1), int(C * 0.55)), (int(C * 0.4), int(C * 0.05))))
    # curved 3-part vectors
    image.draw_vector(
        Vector((int(C * 1.1), int(C * 1.5)), (int(C * 0.4), int(C * 0.1))))
    image.draw_vector(Vector((int(C * 1.8), int(C * 1.65)), (int(C * 0.4), 0)))
    image.draw_vector(
        Vector((int(C * 2.5), int(C * 1.6)), (int(C * 0.4), int(C * -0.1))))
    image.draw_vector(
        Vector((int(C * 1.1), int(C * 0.5)), (int(C * 0.4), int(C * -0.1))))
    image.draw_vector(Vector((int(C * 1.8), int(C * 0.35)), (int(C * 0.4), 0)))
    image.draw_vector(
        Vector((int(C * 2.5), int(C * 0.4)), (int(C * 0.4), int(C * 0.1))))
    image.save('img/img_2a.png')
示例#16
0
def get_csv_training():
    """
    Get the annotations for
    all images contained in a particular
    csv file
    :return: list of all the annotations (id, c ???, x coordinate of the
    first spot, y coordinate of the first sport and then the coordinates
    of the second spot).
    """
    list_images = []
    with open('DataChallenge/descriptions_training.csv', 'r') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        for row in spamreader:
            row = row[0].split(",")
            _id, c, xf, yf, xs, ys = row
            i = Image(_id, c, xf, yf, xs, ys)
            list_images.append(i)

    return list_images
示例#17
0
def main():
    args = parse_args()

    proxy = setup_proxy(args.proxy_url, args.proxy_auth)

    image = Image(args.file, args.round_sensitive, args.image_brightness)

    bot = Bot(image, args.fingerprint, args.start_x, args.start_y, args.mode_defensive, args.colors_ignored, proxy, args.draw_strategy)

    bot.init()

    def run():
        try:
            bot.run()
        except NeedUserInteraction as exception:
            alert(exception.message)
            if raw_input(I18n.get('token_resolved')) == 'y':
                run()
    run()
示例#18
0
def generate_img_5c(C=400):
    '''Image "Symbol kondensatora elektrolitycznego"'''
    image = Image((int(C * 2), int(C * 2)), line_width=6)
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 0.5)), (int(C * 5 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 0.5)), (int(C * 7 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 8 / 6), int(C * 0.5)), (int(C * 8 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 0.5)), (int(C * 8 / 6), int(C * 0.5))))
    image.draw_line(
        Line((int(C * 7 / 6), int(C * 1.5)), (int(C * 8 / 6), int(C * 1.5))))
    image.draw_line(
        Line((int(C * 5 / 6), int(C * 1)), (int(C * 1 / 4), int(C * 1))))
    image.draw_line(
        Line((int(C * 8 / 6), int(C * 1)), (int(C * 7 / 4), int(C * 1))))
    image.draw_point((int(C * 1 / 4), int(C * 1)), width=20, fill=[0, 0, 190])
    image.draw_point((int(C * 7 / 4), int(C * 1)), width=20, fill=[190, 0, 0])
    image.save('img/img_5c.png')
    def render_isometric(
            self,
            scene: Base,
            origin: Vector3 = (0, 0, -5),
            direction: Vector3 = (0, 0, 1),
            width: int = 6,
            height: int = 6,
    ):
        origin = Vec3(origin)
        direction = Vec3(direction)

        raymarcher = Raymarcher(scene)
        image = Image(width, height)
        raymarcher.render(image, lambda p: (p + origin, direction), aa=4)

        file = StringIO()
        image.dump_bw(file=file, black=".", white="#", threshold=.3)
        file.seek(0)
        #image.dump()
        return file.read()
示例#20
0
def generate_img_3a(C=400):
    '''Image "Pole elektryczne pomiędzy odładami kondensatora płaskiego"'''
    image = Image((C * 2, C * 2), line_width=3)
    image.draw_line(Line((int(C*2/3), int(C*0.5)),(int(C*2/3), int(C*1.5))),\
        fill=[190,0,0], width=10)
    image.draw_line(Line((int(C * 2 / 3), C), (int(C * 1 / 3), C)),
                    fill=[190, 0, 0],
                    width=3)
    image.draw_point((int(C * 1 / 3), int(C)), fill=[190, 0, 0], width=10)
    image.draw_line(Line((int(C*4/3), int(C*0.5)),(int(C*4/3), int(C*1.5))),\
        fill=[0,0,190], width=10)
    image.draw_line(Line((int(C * 4 / 3), C), (int(C * 5 / 3), C)),
                    fill=[0, 0, 190],
                    width=3)
    image.draw_point((int(C * 5 / 3), int(C)), fill=[0, 0, 190], width=10)
    len = 2 / 3 - 2 * (0.75 - 2 / 3)
    image.draw_vector(Vector((int(C * 0.75), int(C * 0.6)), (int(C * len), 0)))
    image.draw_vector(Vector((int(C * 0.75), int(C * 0.8)), (int(C * len), 0)))
    image.draw_vector(Vector((int(C * 0.75), int(C * 1)), (int(C * len), 0)))
    image.draw_vector(Vector((int(C * 0.75), int(C * 1.2)), (int(C * len), 0)))
    image.draw_vector(Vector((int(C * 0.75), int(C * 1.4)), (int(C * len), 0)))
    image.save('img/img_3a.png')
示例#21
0
def parse_current_images(current_image_points, index):
    if not current_image_points:
        image_out = Image(index - 1, 0, 0, 0, 0, 0)
    elif len(current_image_points) == 1:
        if is_spot_possible(current_image_points[0][1]/float(RESIZE_FACTOR), \
            current_image_points[0][2]/float(RESIZE_FACTOR), \
            current_image_points[0][3]/float(RESIZE_FACTOR), \
            current_image_points[0][4]/float(RESIZE_FACTOR)):
            spot = ((current_image_points[0][1] + current_image_points[0][2])/float(2 * RESIZE_FACTOR), \
                (current_image_points[0][3] + current_image_points[0][4])/float(2 * RESIZE_FACTOR))
            image_out = Image(index - 1, 1, spot[0], spot[1], 0, 0)
        else:
            image_out = Image(index - 1, 0, 0, 0, 0, 0)
    else:
        # Reverse sort the mostr likely images
        current_image_points.sort(key=lambda x: -x[0])
        spots = []
        if is_spot_possible(current_image_points[0][1]/float(RESIZE_FACTOR), \
            current_image_points[0][2]/float(RESIZE_FACTOR), \
            current_image_points[0][3]/float(RESIZE_FACTOR), \
            current_image_points[0][4]/float(RESIZE_FACTOR)):
            spot1 = ((current_image_points[0][1] + current_image_points[0][2])/float(2 * RESIZE_FACTOR), \
                (current_image_points[0][3] + current_image_points[0][4])/float(2 * RESIZE_FACTOR))
            spots.append(spot1)
        if is_spot_possible(current_image_points[1][1]/float(RESIZE_FACTOR), \
            current_image_points[1][2]/float(RESIZE_FACTOR), \
            current_image_points[1][3]/float(RESIZE_FACTOR), \
            current_image_points[1][4]/float(RESIZE_FACTOR)):
            spot2 = ((current_image_points[1][1] + current_image_points[1][2])/float(2 * RESIZE_FACTOR), \
                (current_image_points[1][3] + current_image_points[1][4])/float(2 * RESIZE_FACTOR))
            spots.append(spot2)
        if len(spots) == 0:
            image_out = Image(index - 1, 0, 0, 0, 0, 0)
        elif len(spots) == 1:
            image_out = Image(index - 1, 1, spots[0][0], spots[0][1], 0, 0)
        else:
            image_out = Image(index - 1, 2, spot1[0], spot1[1], spot2[0],
                              spot2[1])

    return image_out
示例#22
0
from src.image import Image
import sys

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print('Argument error')

    img = Image(sys.argv[1])
    size = len(img.data) // 2
    img.data = img.data[:size, :size]
    img.save('img/penguin128.png')
示例#23
0
 def create_2_images(self, number):
     images = []
     for i in range(number):
         images.append(Image(i, 2, random.random() * 24, random.random() * 24, \
             random.random() * 24, random.random() * 24))
     return images
示例#24
0
def lenna():
    from src.image import Image
    return Image("Lenna", relative_path("tests/data/lenna.png"), False, False,
                 False, False, consts.uiConsts["DefaultGrayscaleLevel"])
示例#25
0
 def create_0_images(self, number):
     images = []
     for i in range(number):
         images.append(Image(i, 0, 0, 0, 0, 0))
     return images
 def __init__(self, emotion, pixels, partition):
     self.emotion = emotion
     self.image = Image(pixels)
     self.partition = partition
示例#27
0
 def import_key_points(self):
     self.first_img = Image(self.first_img_name)
     self.first_img.import_key_points()
     self.second_img = Image(self.second_img_name)
     self.second_img.import_key_points()