Draw Examples

[1]:
from easycv import Image
from easycv.transforms.draw import Draw

For this example we will load an image with random(). For more examples of image loading check Image examples.

[2]:
img = Image.random()
img
[2]:
../../_images/examples_transforms_draw_3_0.png

Ellipse

To draw an ellipse apply the method Draw and select the method ellipse, for more information check reference.

[3]:
img.apply(Draw(method="ellipse",
                ellipse=((200,100),100,60),
                rotation_angle=20,
                start_angle=0,
                end_angle=300,
                filled=False,
                color=(100,200,200),
                thickness=5))
[3]:
../../_images/examples_transforms_draw_6_0.png

A closed ellipse can also be drawn passing filled as True

[4]:
img.apply(Draw(method="ellipse",
                ellipse=((200,100),100,60),
                rotation_angle=20,
                start_angle=0,
                end_angle=300,
                filled=True,
                color=(100,200,200),
                thickness=5,))
[4]:
../../_images/examples_transforms_draw_8_0.png

Line

To draw a line apply the method Draw and select the method line, for more information check reference.

[5]:
img.apply(Draw(method="line",
                pt1=(30,20),
                pt2=(200,150),
                color=(0,200,0),
                thickness=5))
[5]:
../../_images/examples_transforms_draw_11_0.png

Polygon

To draw multiple lines or a polygon apply the method Draw and select the method polygon, for more information check reference.

Not closed and not Filled

[6]:
img.apply(Draw(method = "polygon",
               points=[[50,50],[100,100],[50,100],[100,50]],
               color=(250,0,0),
               thickness=2,
               closed=False,
               filled=False))
[6]:
../../_images/examples_transforms_draw_15_0.png

Closed and not Filled

[7]:
img.apply(Draw(method = "polygon",
               points=[[50,50],[100,100],[50,100],[100,50]],
               color=(0,0,250),
               thickness=2,
               closed=True,
               filled=False))
[7]:
../../_images/examples_transforms_draw_17_0.png

Closed and Filled

[8]:
img.apply(Draw(method = "polygon",
               points=[[50,50],[100,100],[50,100],[100,50]],
               color=(100,0,70),
               thickness=2,
               closed=False,
               filled=True))
[8]:
../../_images/examples_transforms_draw_19_0.png

Rectangle

To draw a rectangle apply the method Draw and select the method rectangle, for more information check reference.

Not Filled

[9]:
img.apply(Draw(method="rectangle", rectangle=((95,50),(350,250)),filled=True))
[9]:
../../_images/examples_transforms_draw_23_0.png

Filled

[10]:
img.apply(Draw(method="rectangle", rectangle=((95,50),(350,250)),color=(50,100,200),filled=False))
[10]:
../../_images/examples_transforms_draw_25_0.png

Text

To draw Text apply the method Draw and select the method Text, for more information check reference.

[11]:
img.apply(Draw(method = "text", text="easyCV", org=(1,200), font="SIMPLEX", size=4, color=(0,150,250),thickness=5))
[11]:
../../_images/examples_transforms_draw_28_0.png

The text can be mirrored using x_mirror

[12]:
img.apply(Draw(method = "text", text="easyCV", org=(1,200), font="SIMPLEX", size=4, color=(0,150,250),thickness=5,x_mirror=True))
[12]:
../../_images/examples_transforms_draw_30_0.png