示例#1
0
def makeCircleMaskImage(width, height):
    center = (width / 2, height / 2)
    smallerDimension = min(width, height)
    image = Image.new('1', (width, height))
    draw = ImageDraw(image)
    draw.ellipse(boundingBoxSquare(center, smallerDimension), fill='white')
    return image
示例#2
0
def draw_eye_vector(drawer: ImageDraw.ImageDraw, eye_3d_vector: np.ndarray,
                    solver: PNP_solver.PoseEstimator,
                    rotation: np.ndarray, translation: np.ndarray, eye_pos: str) -> None:
    """Draw gaze vector eye from eye on a picture drawer

    :param drawer: where to draw
    :param eye_3d_vector: what vector(in camera coordinate system)
    :param solver:
    :param rotation: head rotation
    :param translation: head translation
    :param eye_pos: "l" for left, "r" for right
    :return:
    """
    if eye_pos == "l":
        eye_pos = (solver.model_points_68[36] + solver.model_points_68[39]) / 2.
    else:
        eye_pos = (solver.model_points_68[42] + solver.model_points_68[45]) / 2.

    eye_3d_vector = copy.deepcopy(eye_3d_vector) * -50

    # eye coordinate in camera coordinate system is determined
    to_camera_matrix = get_world_to_camera_projection_matrix(solver, rotation, translation)
    eye_pos = np.matmul(to_camera_matrix, [*eye_pos, 1])

    no_rot_vector, _ = cv2.Rodrigues(np.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
    vect_start, _ = cv2.projectPoints(eye_pos, no_rot_vector, [0, 0, 0], solver.camera_matrix,
                                      solver.dist_coeefs)
    vect_finish, _ = cv2.projectPoints(eye_3d_vector + eye_pos, no_rot_vector, [0, 0, 0],
                                       solver.camera_matrix, solver.dist_coeefs)

    drawer.line([*vect_start, vect_start[0] + vect_finish[0], vect_start[1] + vect_finish[1]], fill=(0, 255, 0))
    drawer.ellipse([vect_start[0] - 2, vect_start[1] - 2, vect_start[0] + 2, vect_start[1] + 2])
示例#3
0
    def __init__(self, *args, **kwargs):
        global src, dst
        self.g = TPS_generate(src, dst)

        self.img = Image.new("L", (500, 500), 255)
        draw = ImageDraw(self.img)
        for d in xrange(10, 250, 10):
            draw.ellipse((d, d, 500 - d, 500 - d))

        return super(TestImages, self).__init__(*args, **kwargs)
示例#4
0
 def draw(self, features: List, osm_helper: OsmHelper, camera: Camera,
          image_draw: ImageDraw):
     if self.draws_at_zoom(None, camera, osm_helper):
         for points in features:
             for x, y in transform_shapes([points], camera)[0]:
                 x1, x2 = x - self.width / 2, x + self.width / 2
                 y1, y2 = y - self.width / 2, y + self.width / 2
                 image_draw.ellipse([(x1, y1), (x2, y2)],
                                    fill=self.fill,
                                    width=0)
示例#5
0
 def draw(self, canvas: ImageDraw.ImageDraw, color='red'):
     canvas.ellipse((self.x - self.hr, self.y - self.hr, self.x + self.hr, self.y + self.hr), fill=color)
     if self.down:
         canvas.line(((self.x, self.y), (self.x, self.y + self.tail)), 'blue')
     if self.up:
         canvas.line(((self.x, self.y), (self.x, self.y - self.tail)), 'blue')
     if self.left:
         canvas.line(((self.x, self.y), (self.x - self.tail, self.y)), 'blue')
     if self.right:
         canvas.line(((self.x, self.y), (self.x + self.tail, self.y)), 'blue')
示例#6
0
 def draw_noes(draw: ImageDraw.ImageDraw, members: list[PartyMember]):
     columns = math.ceil(len(members) / 10)
     draw.text((100, 120), "Noes", font=title_font, fill=(0, 0, 0))
     for column in range(columns + 1):
         for j, member in enumerate(members[10 * (column - 1):10 * column]):
             party = parliament.get_party_by_id(member._get_party_id())
             draw.ellipse([
                 (80 + ((20 * column) + (2 * column)), 180 + (20 * j) +
                  (2 * j)),
                 (100 + ((20 * column) + ((2 * column) - 2)), 200 +
                  (20 * j) + ((2 * j) - 2))
             ], f"{PartyColour.from_id(member._get_party_id()).value['colour']}"
                          )
示例#7
0
def draw_map(test_img, pix_map_normlized, outline=None):
    if outline is None:
        outline = (0, 0, 0)
    draw_api = ImageDraw(test_img)
    for pixel in pix_map_normlized:
        coordinate_from = (
            int(pixel[0] * IMG_SIZE) - DOT_RADIUS,
            int(pixel[1] * IMG_SIZE) - DOT_RADIUS
        )
        coordinate_to = (
            int(pixel[0] * IMG_SIZE) + DOT_RADIUS,
            int(pixel[1] * IMG_SIZE) + DOT_RADIUS
        )
        draw_api.ellipse([coordinate_from, coordinate_to], outline=outline)
示例#8
0
 def draw_keys(draw: ImageDraw.ImageDraw, parties: dict):
     for i, key in enumerate(parties.keys()):
         name = parties[key]["name"]
         w, h = draw.textsize(name)
         draw.text(
             (1600, 120 + (60 * i)),
             f"{name}",
             font=key_font,
             fill="#ffffff",
             anchor="lt",
         )
         draw.ellipse(
             [(1520, 110 + (60 * i)), (1570, 150 + (60 * i))],
             fill=f"{parties[key]['colour']}",
         )
示例#9
0
    def draw_keys(draw: ImageDraw.ImageDraw, division: Union[CommonsDivision,
                                                             LordsDivision]):
        parties = get_parties(division)

        for i, party in enumerate(parties):
            name = party.get_name()
            w, h = draw.textsize(name)
            draw.text((1600, 120 + (60 * i)),
                      f"{name}",
                      font=key_font,
                      fill='#ffffff',
                      anchor='lt')
            draw.ellipse(
                [(1520, 110 + (60 * i)), (1570, 150 + (60 * i))],
                fill=
                f"{PartyColour.from_id(party.get_party_id()).value['colour']}")
示例#10
0
def dot(draw: ImageDraw, coord: Coordinate, color: str, size: int = 2):
    """Draws a dot at the given map Coordinate with the given color.

    Arguments:
        draw {ImageDraw} -- The ImageDraw to draw on
        coord {Coordinate} -- Where to the place the dot
        color {str} -- Pillow color to make the dot

    Keyword Arguments:
        size {int} -- Size of the dot (default: {2})
    """
    pos = coord.coord_2d
    x = (pos[0] - size, pos[1] - size)
    z = (pos[0] + size, pos[1] + size)

    draw.ellipse([x, z], fill=color)
示例#11
0
 def wireframe(ipse, margin=150):
     mx, my = ipse.bbox()
     sz = int(sum(mx)) + margin * 2, int(sum(my)) + margin * 2
     im = Image.new(mode="RGB", size=sz, color=(255, 255, 255))
     draw = ImageDraw(im)
     draw.rectangle(xy=(margin, margin, int(sum(mx)) + margin,
                        int(sum(my)) + margin),
                    outline=(0, 0, 255))
     p = DParse()
     x, y = 0, 0
     for q in p(ipse.path):
         cmd = q[0]
         x0, y0 = x, y
         if cmd.lower() == "m":
             if cmd.islower():
                 x, y = x + q[-2], y + q[-1]
             else:
                 x, y = q[-2:]
             m = x, y
             continue
         elif cmd.lower() == "z":
             x, y = m
         elif cmd.lower() == "h":
             if cmd.islower():
                 x = x + q[-1]
             else:
                 x = q[-1]
         elif cmd.lower() == "v":
             if cmd.islower():
                 y = y + q[-1]
             else:
                 y = q[-1]
         else:
             if cmd.islower():
                 x, y = x + q[-2], y + q[-1]
             else:
                 x, y = q[-2:]
         draw.line((x + margin, y + margin, x0 + margin, y0 + margin),
                   fill=(0, 0, 0))
     draw.ellipse(xy=(x - 2 + margin, y - 2 + margin, x + 2 + margin,
                      y + 2 + margin),
                  fill=(0, 255, 0))
     x, y = ipse.origin
     draw.ellipse(xy=(x - 2 + margin, y - 2 + margin, x + 2 + margin,
                      y + 2 + margin),
                  fill=(255, 0, 0))
     return im
示例#12
0
    def draw(self, draw: ImageDraw.ImageDraw, offset: Tuple[int, int],
             colors: Dict[PlayerType, Tuple[int, int]], stone_width: int):
        fill, outline = colors[self.player]

        x, y = offset
        if self.type == StoneType.FLAT:
            rectangle = [x, y, x + stone_width, y + stone_width]
            draw.rectangle(rectangle, fill=fill, outline=outline, width=3)
        if self.type == StoneType.STANDING:
            rectangle = [
                x + stone_width // 3, y, x + stone_width * 2 // 3,
                y + stone_width
            ]
            draw.rectangle(rectangle, fill=fill, outline=outline, width=3)
        if self.type == StoneType.CAPSTONE:
            rectangle = [x, y, x + stone_width, y + stone_width]
            draw.ellipse(rectangle, fill=fill, outline=outline, width=3)
示例#13
0
 def draw_noes(draw: ImageDraw.ImageDraw, members: dict):
     columns = math.ceil(len(members) / 10)
     draw.text((100, 120), "Noes", font=title_font, fill=(0, 0, 0))
     member_keys = list(members.keys())
     for column in range(columns + 1):
         for j, key in enumerate(member_keys[10 * (column - 1):10 *
                                             column]):
             colour = members[key]
             draw.ellipse(
                 [
                     (
                         80 + ((20 * column) + (2 * column)),
                         180 + (20 * j) + (2 * j),
                     ),
                     (
                         100 + ((20 * column) + ((2 * column) - 2)),
                         200 + (20 * j) + ((2 * j) - 2),
                     ),
                 ],
                 f"{colour}",
             )
示例#14
0
def draw_avatar(
    img: Image,
    draw: ImageDraw.ImageDraw,
    username: str,
    points_balloon: Box,
    avatar_path: str,
):
    y0 = points_balloon.bottom_right.y - AVATAR_SIZE
    y1 = points_balloon.bottom_right.y
    points = Box(MARGIN, y0, MARGIN + AVATAR_SIZE, y1)
    box_position = tuple(a - 2 for a in points.top_left.to_tuple())
    size = AVATAR_SIZE + 4
    if avatar_path == '':
        draw.ellipse(points.to_list(), fill=TITLE_COLOR)
        avatar_center = points.center().to_tuple()
        draw.text(
            avatar_center,
            username[0],
            anchor='mm',
            font=FONTS['avatar'],
            fill='#FFFFFF',
        )
        return

    avatar = Image.open(avatar_path).convert(mode='RGBA')
    if avatar.width == avatar.height:
        avatar = avatar.resize((size, size), resample=Image.ANTIALIAS)
    elif avatar.width > avatar.height:
        ratio = size / avatar.width
        avatar = avatar.resize((size, int(ratio * avatar.height)),
                               resample=Image.ANTIALIAS)
    else:
        ratio = size / avatar.height
        avatar = avatar.resize((int(ratio * avatar.width), size),
                               resample=Image.ANTIALIAS)

    avatar_mask = generate_avatar_mask(img.size, points)
    tmp = Image.new('RGBA', img.size)
    tmp.paste(avatar, box=box_position)
    img.paste(tmp, mask=avatar_mask)