Skip to main content

Drawline

Say goodbye to endless searching and trial-and-error with image overlays! Drawline makes it effortless to overlay polyggon contours, rectangles and even auto-handles label colors, font size and line thickness. With the option to override, Drawline takes the hassle out of image drawing customization

Install


pip install drawline

Screenshots

  1. Polygon draw (Normal mode): Good to use when there are less number of polygons to draw.
Cloud Image  
# Go to 'How to Use' section for detail code
result_image = draw_poly(image, {YOUR_CONTOURS}, label={YOUR_LABELS}, graph_mode=False, show_rect=False)

 

  1. Polygon draw (Graph mode): Good to use when there are many number of polygons to draw. Overcomes the overlay labels problem.

   

# Go to 'How to Use' section for detail code
result_image = draw_poly(image, {YOUR_CONTOURS}, label={YOUR_LABELS}, graph_mode=True)

 

  1. Rectangle draw (normal mode): You can also simlpy draw a rectangle instead of polygon.
Rect normal
# Go to 'How to Use' section for detail code
result_image = draw_rect(image, {YOUR_RECTANGLE_COORDINATES}, label={YOUR_LABELS})

How to use


Checkout the example: Notebook Example (NB viewer) or Github Viewer

OR

from drawline import draw_poly, draw_rect
import cv2

img_pth = '/PATH/TO/IMAGE.jpg'
image = cv2.imread(img_pth)

# Single  Rectangle example
result_image = draw_rect(image, [XMIN, YMIN, XMAX, YMAX], labels='label_1')

# Multiple Rectangles example
result_image = draw_rect(image,
                         [[XMIN_1, YMIN_1, XMAX_1, YMAX_1],
                          [XMIN_2, YMIN_2, XMAX_2, YMAX_2]],
                         labels=['Label_1', 'Label_2'])


# Single Contours Polygon example 
result_image = draw_poly(image, CONTOUR, label='label_1')

# Multiple Contours Polygon points
result_image = draw_poly(image, CONTOURS, label=['label_1', 'label_2', ...])

# Assigning Labels is optional, if not given no label name will be displayed

Default options


def draw_rect(image, points, rgb=None, label_transparency=0.1, thickness=None, labels=None,
              label_rgb=None, label_bg_rgb=None, label_font_size=None,
              random_color=False, graph_mode=False):
    """
    Draws rectangle from given coordinates
    :param image: (Numpy) numpy matrix image
    :param points: (List) List of rectangle coordinates: [[xmin, ymin, xmax, ymax]]
    :param rgb: (Tuple) RGB values: (R, G, B)
    :param label_transparency: (float) transparency for the labels
    :param thickness: (Integer) of line in px: eg: 2
    :param labels: (List) list of strings: []
    :param label_rgb: (Tuple) RGB text color for labels: (R,G,B)
    :param label_bg_rgb: (Tuple) RGB label background color: (R,G,B)
    :param label_font_size: (Integer) Font size of label in px: 2
    :param random_color: (Boolean) pick random colors for lines.
    :param graph_mode: (Boolean) Writes labels to a border instead in the image itself (Good to use when to many boxes
     obstructing the view)

    :return: (numpy) drawn rectangles on image
    """
    
    
def draw_poly(image, contours, fill_in=True, label_transparency=0.1, fill_transparency=0.4, rgb=None, thickness=None,
              show_rect=True, labels=None, label_rgb=None, label_bg_rgb=None, label_font_size=None, random_color=False,
              graph_mode=False):
    """
    Draws polygon and fills in color from given contours
    :param image: (Numpy) numpy matrix image
    :param contours: (List) of contours
    :param fill_in: (Boolean) fill color inside the polygon.
    :param label_transparency: (float) transparency for the labels
    :param fill_transparency: (Float) transparency of fill_in color.
    :param rgb: RGB values: (Tuple) rgb color of line and polyfgon (R, G, B)
    :param thickness: (Int) Thickness of line
    :param show_rect: (Boolean) Show rectangle
    :param labels: (List of strings) List of label names
    :param label_rgb: (Tuple) RGB color of labels
    :param label_bg_rgb: (Tuple) RGB color of Label background
    :param label_font_size: (Int) Label font size
    :param random_color: (Boolean) Randomize RGB color
    :param graph_mode: (Boolean) Writes labels to a border instead in the image itself (Good to use when to many boxes
     obstructing the view)

    :return: (Numpy) drawn polygon on image
    """

Release files for drawline 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drawline 0.3.4
File Size Uploaded
drawline-0.3.4.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drawline 0.3.4
File Interpreter ABI Platform
drawline-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / drawline-0.3.4.tar.gz

Download URL drawline-0.3.4.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
eb8d3d0d8208be3889bfeda4f7241b1fd258df34b397f0e3254a40dd7554a98e
BLAKE2b-256 checksum
How to use checksums
5a101f1df0aa4487be4a55f464c0b7e8ebcd569455589e9bddb51e9e6b88da16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Release files / drawline-0.3.4-py3-none-any.whl

Download URL drawline-0.3.4-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55e9814a94dbb1a1ed32fee1844b8570126339bdd2d1787bc65c643d572e8021
BLAKE2b-256 checksum
How to use checksums
2edec610bfe0cd10fd9e5a9f8155f9a90950dfab17c21b86acfd7dea755498cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.1

2 release files

0.2.2

2 release files

0.1.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page