svkcore.visualize

svkcore.visualize.visualize

svkcore.visualize.visualize.cv2image2pil(cv2_image: ndarray) Image[source]

Convert openCV format image to PIL.Image.Image

Parameters:

cv2_image – openCV format image instance

Returns:

converted Image.Image instance

svkcore.visualize.visualize.draw_annotation(image, annotation, name2cls, color_table=None, add_unknown_name=False)[source]

Draw DTAnnotation to an image

Parameters:
  • image (PIL.Image.Image) – A PIL.Image.Image object

  • annotation (DTAnnotation) – An instance of DTAnnotation

  • name2cls (dict) – a dict of name to its class id number

  • color_table (list) – each class colors

  • add_unknown_name (bool) – whether add a new name to name2cls, default is False

Returns:

drew image

Return type:

PIL.Image.Image

svkcore.visualize.visualize.draw_boxes(image, boxes, color='red', width=0, fullfill=False)[source]

Draw boxes on image

Parameters:
  • image – A PIL.Image object

  • boxes – a list of boxes

  • color – boxes color

  • width – line width

  • fullfill – full fill boxes or not

Returns:

drew image

svkcore.visualize.visualize.draw_boxes_texts(image, boxes, texts, width=1, color='red')[source]

Draw boxes and its text information on image

Parameters:
  • image – A PIL.Image object

  • boxes – A list of box

  • texts – A list of text

  • width – Line width, determines thickness of box and font size of text

  • color – Color of boxes and texts

Returns:

drew image

svkcore.visualize.visualize.draw_detection_result(image, boxes, classes, display_strings, color_nums=100, scale=-1.0)[source]

Draw detection result

Parameters:
  • image – A PIL.Image object

  • boxes – A list of box

  • classes – A list of detection class index

  • display_strings – A list of display string

  • color_nums – The max number of different colors

  • scale – visualize box and text scale. Default -1.0 means auto adjust scale by input image

Returns:

drew image

svkcore.visualize.visualize.draw_lines(image, lines, color='red', width=0)[source]

Draw boxes on lines

Parameters:
  • image – A PIL.Image object

  • lines – a list of lines

  • color – lines color

  • width – line width

Returns:

drew image

svkcore.visualize.visualize.draw_masks(image, masks, color='red', alpha=0.5)[source]

Draw masks on image

Parameters:
  • image – A PIL.Image object

  • masks – a list of masks

  • color – mask color

  • alpha – transport alpha

Returns:

drew image

svkcore.visualize.visualize.draw_points(image, points, color='red', scale=3, shape='.')[source]

Draw boxes on points

Parameters:
  • image – A PIL.Image object

  • points – a list of points

  • color – points color

  • scale – points scale

  • shape – visualize shape, ‘t’ for triangle else for circle

Returns:

drew image

svkcore.visualize.visualize.draw_polygons(image, polygons, color='red', width=0, fullfill=False)[source]

Draw polygons on image

Parameters:
  • image – A PIL.Image object

  • polygons – a list of polygons

  • color – mask color

  • width – line width

  • fullfill – full fill polygon or not

Returns:

drew image

svkcore.visualize.visualize.draw_texts(image, xys, texts, color='red', back_color=None, font_size=12, position='topleft', offset=(0, 0), margin=(0, 0, 0, 0))[source]

Draw texts on image

Parameters:
  • image – A PIL.Image object

  • xys – A list of corner’s coordinate where text align

  • texts – A list of texts

  • color – Text color

  • back_color

  • font_size – Font size

  • position – text align position, enum string like: topleft/topright/bottomleft/bottomright/manu

  • offset – A tuple vector of offset for ‘manu’ position

  • margin – A tuple (left, top, right, bottom) denotes the margins to back boarder

Returns:

drew image

svkcore.visualize.visualize.generate_colors(num)[source]

Generate colors for drawing bounding boxes

Paste a list of images into one panel for better visualize

Parameters:
  • image_list – A list of Image.Image instance.

  • n_cols – Max number of images to show in each row. If the number of image_list is less than n_cols, n_cols will be set as the number of image_list. Default value is 6.

  • n_rows

    Number of rows to show images. If n_cols is set, n_rows will be automatically calculated by

    \[ceil(\frac{N}{n\_cols})\]

    Otherwise n_cols will be automatically calculated. Default value is None.

  • cell_size – The size of cell where each image is placed in.

  • pad – The pad width/height between two cells.

  • align – The align mode. Set 0(center), 1(left/up), 2(right/bottom) to choose align mode in each cell.

  • back_color – Background color.

  • same_scale – A boolean value indicates whether to use a same scale factor to resize all images in image_list. Set it to be True if you want to visualize the sizes of different images.

Returns:

Pasted Image.Image instance.

svkcore.visualize.visualize.pil2cv2image(image: Image) ndarray[source]

Convert PIL.Image.Image to openCV format image

Parameters:

image – an instance of PIL.Image.Image

Returns:

converted openCV format image