Skip to main content

Vizualization for Detection and Tracking

Project description

VIZDET

PyPI version

CI

VIZDET - VIZualization for DEtection and Tracking. This library provides a simple interface to plot detection bounding boxes and their labels on an image. It enables the use of custom fonts, allowing you to create visually pleasing detection plots.

The purpose of this library is enable detection model creators to use an out-of-the-box library for presenting and visually evaluating their detection models, focusing their time on writing the detection models instead. Main features of vizdet are:

  • Easy to use, enabling you to create detection plots with ease with minimal code
  • Use of custom fonts to make the plots look beautiful and write special unicode characters and characters from non-latin scipts
  • Customizable graphical parameters - customize plots according to your taste
  • Out of the box options cover the main usecases for object detection, as well as (multi) object tracking - just plug in the detection/tracking results from your model, and you're ready to go
  • Lightweight, with the only dependency being OpenCV (and Numpy)

Road example

Installation instructions

This module requires the freetype OpenCV module, which is not included in the PyPI repository package, so I recommend you install the requirements with conda (create a conda environment first):

conda install libopencv opencv py-opencv -c conda-forge

From here you can install the package with pip, as usual

pip install vizdet

Quickstart

Let's create our first detection plot. Download this image and place it in your working directory. Then, execute this script (you'll also need to install matplotlib to visualize the results)

import cv2
import matplotlib.pyplot as plt
from vizdet import BBoxes, InfoBox

# Prepare our detection results
boxes = [
    [1267, 762, 1418, 889],
    [1225, 604, 1327, 693],
    [1789, 682, 1919, 790],
    [1595, 389, 1726, 514],
    [1670, 416, 1820, 566],
    [904, 440, 1043, 615],
    [504, 623, 876, 1142],
    [922, 611, 1213, 1107]
]
labels = ['car', 'car', 'car', 'truck', 'truck', 'truck', 'truck', 'truck']
info_title = '# Objects'
info_desc = ['3 cars', '5 trucks']

# Read image
img = cv2.imread('highway.png')

# Prepare objects to draw
bboxes = BBoxes(font_height=40, box_thickness=5, padding=10)
infobox = InfoBox(width=250, font_height_desc=40, font_height_title=50, padding=15)

# Draw detection results on the image
bboxes.draw(img, boxes, labels=labels)
infobox.draw(img, (1650, 20), info_desc, info_title)

# Plot results
plt.imshow(img[::-1])

The result should be similar to the image above (but with bounding box colors being different). We drew the detection boxes, as well as an information box given some information what is on the image - all with just the detection result from boxes and some custom text for the information box.

All the drawing is done by the BBoxes and InfoBox classes, which offer arguments to customize the visual appearance. The default font (FiraGO) is used, but this could also be modified. Note that this looks much better than what you would get with the default OpenCV Hershey font.

The result ( img ) is a simply numpy array - not some custom plot object that you would get with Matplotlib or similar libraries. This enables you to further customize the image using other tools, if you would like, or to compose multiple images into a video and so on. The possibilities are endless ; )

Labels as integers

A common situation is that your labels are actually integers, corresponding to some class names from a list. This is handled natively by vizdet. In this case your labels would be an integer list and you would also have a classes list of string class names:

labels = [0, 0, 0, 1, 1, 1, 1, 1]
classes = ['car', 'truck']

Then, all you need to do is to change the bboxes definition to

bboxes = BBoxes(
    labels_list=classes, font_height=40, box_thickness=5, padding=10
)

Showing probabilities

You migh also want to display probabilities (confidences) for each object. So say that you have the probabilities in a probs list

probs = [0.9978, 0.9951, 0.9974, 0.9757, 0.9766, 0.9937, 0.9936, 0.9923]

Then, to display them on the plot just modify the bboxes.draw function call to

bboxes.draw(img, boxes, labels=classes, labels_conf=probs)

The result should look like the image below

Road example probs

License

This source code of this project is released under the Apache 2.0 License, which is available in the LICENSE file.

The project also contains the FiraGO font, which is distributed under the SIL Open Font License. The test directory also includes the FiraMono font, also released under the SIL Open Font License. A copy of the Open Font License is included in the OFL.txt file.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog.

[Unreleased]

[0.1.2] - 2020-04-03

Added

  • The BBoxes, InfoBox, Label and Font classes, that can draw bouding objects on the image using custom TrueType fonts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vizdet-0.1.2.tar.gz (381.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vizdet-0.1.2-py3-none-any.whl (377.5 kB view details)

Uploaded Python 3

File details

Details for the file vizdet-0.1.2.tar.gz.

File metadata

  • Download URL: vizdet-0.1.2.tar.gz
  • Upload date:
  • Size: 381.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for vizdet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9f3fd1cd1dbb992e8355f3d24762652cb339267cb4dc8a0b6d4566ca4ab22ae2
MD5 7066642076687f754caf2edda8991d69
BLAKE2b-256 4a40bb3561fa790c01977da5508e422559ad4ea589f4d73ce38a9cf3aa3b94b4

See more details on using hashes here.

File details

Details for the file vizdet-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vizdet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 377.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for vizdet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 330e0eecebad79be18fc9e7b9fcc2c007a473855f8618859afabffe5e424956f
MD5 bd22d3b3d00ce1a1888b7f612d5ea997
BLAKE2b-256 5c909eef96c597f38f173961a26e853f23f0ca9a2802b57c43315182396e5d58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page