def circle(frame, coordinates, radius, color=default.BACKGROUND_COLOR):

        # Convert frame into image and make it ready to draw
        image = Image.fromarray(frame)
        draw = ImageDraw.Draw(image)

        # Draw
        draw.ellipse(
            (coordinates['left'] - radius, coordinates['top'] - radius,
             coordinates['left'] + radius, coordinates['top'] + radius),
            fill=color)
        # Clear
        del draw

        # Convert image to numpy array (frame) and return
        return Action.image_to_array(image)
Exemple #2
0
    def rectangle(frame,
                  coordinates,
                  text='',
                  solid=False,
                  box_color=default.BOX_COLOR,
                  font_color=default.FONT_COLOR,
                  font=FONT):

        # Convert frame into image and make it ready to draw
        image = Image.fromarray(frame)
        draw = ImageDraw.Draw(image)

        if solid:
            # Draw solid
            draw.rectangle(((coordinates['left'], coordinates['top']),
                            (coordinates['right'], coordinates['bottom'])),
                           fill=box_color,
                           outline=box_color)
        else:
            # Draw hollow
            draw.rectangle(((coordinates['left'], coordinates['top']),
                            (coordinates['right'], coordinates['bottom'])),
                           outline=box_color)

        if text:
            text_width, text_height = draw.textsize(text)
            text_x = ((coordinates['left'] + coordinates['right']) -
                      text_width / 2) / 2 - 12
            text_y = coordinates['bottom'] - text_height - 5

            # Draw solid box
            draw.rectangle(((coordinates['left'],
                             coordinates['bottom'] - text_height - 10),
                            (coordinates['right'], coordinates['bottom'])),
                           fill=box_color,
                           outline=box_color)

            # Draw center aligned text
            draw.text((text_x, text_y), text, font=font, fill=font_color)

        # Clear
        del draw

        # Convert image to numpy array (frame) and return
        return Action.image_to_array(image)
Exemple #3
0
    def text(frame,
             coordinates,
             text,
             font_color=default.FONT_COLOR,
             font=FONT):

        # Convert frame into image and make it ready to draw
        image = Image.fromarray(frame)
        draw = ImageDraw.Draw(image)

        # Draw
        draw.text((coordinates['left'], coordinates['top']),
                  text,
                  font=font,
                  fill=font_color)

        # Clear
        del draw

        # Convert image to numpy array (frame) and return
        return Action.image_to_array(image)