Skip to main content

Some useful extensions to thumbor - extra filters and detectors.

Project description

thumbor_extras

Some useful extensions to thumbor - extra filters and detectors.

pip install thumbor_extras

Detectors

Add these detectors to your thumbor.conf:

DETECTORS = [
    'thumbor_extras.detectors.dnn_face_detector',
    'thumbor_extras.detectors.dnn_object_detector'
]

dnn_face_detector

example of face detector on a lemur

http://localhost:8888/unsafe/smart/filters:draw_center_of_mass():draw_focal_points(2,.25)/https://farm2.static.flickr.com/1098/998604755_c2155161b3.jpg

An improved face detector that uses a deep neural network. More specifically, it uses the SSD object detection model, trained specifically on faces. According to the OpenCV repo, it was trained with "some huge and available online dataset." :/

For more information on how the normal thumbor face detector compares to this one in both accuracy and efficiency, see this comparison script.

dnn_object_detector

example of object detector on two cats

http://localhost:8888/unsafe/smart/filters:draw_center_of_mass():draw_focal_points(2)/https://farm2.static.flickr.com/1308/562554257_53f458e042.jpg

The full SSD object detection model, trained on the COCO dataset. It was built as a MobileNet, a class of efficient, light weight deep neural network models meant to work well in mobile and embedded applications.

Filters

Add these filters to your available filters in thumbor.conf:

FILTERS = [
    ...other filters,
    'thumbor_extras.filters.draw_center_of_mass',
    'thumbor_extras.filters.draw_focal_points'
]

draw_center_of_mass

Draws a circle at the calculated center of mass, according to the focal points.

Usage: draw_center_of_mass([r, g, b])

Examples:

  • draw_center_of_mass(): draws a circle with default red color.
  • draw_center_of_mass(0,0,255): draws a blue circle.

draw_focal_points

Draws a box around the focal points, for displaying the results of the detectors on a given image. Takes optional arguments for box color and line width.

Usage: draw_focal_points([line_width, label_height_percentage, show_heatmap, show_labels, show_rainbow, r, g, b])

Arguments:

  • line_width: the width of the box lines
  • label_height_percentage: the height of the class label as a percentage of the box
  • show_heatmap: make the box more opaque for higher-confidence detections, more transparent for less confident detections
  • show_labels: print the class label at the top of the box
  • show_rainbow: use a different color for each focal point box; pass false to provide a single color RGB value for all boxes
  • r: R component of RGB color of box, default 0
  • g: G component of RGB color of box, default 255
  • b: B component of RGB color of box, default 0

Examples:

  • draw_focal_points(): draws boxes with defaults (each box a different color, with opacity according to the detection confidence).
  • draw_focal_points(5,0,false,false,false,255,0,0): draws solid red boxes with 5 pixel line width, and no class labels.

TODO

  • Choose thresholds empirically

Development

Because I will definitely forget. Python development can be a pain.

# -- ENV --
# use python 2 - thumbor doesn't support 3 yet.
virtualenv thumbor_env --python=/path/to/python2
source thumbor_env/bin/activate

# -- DEVELOP --
pip install -e .

# -- TEST --
# i don't know why setup.py can't install pytest...but it fails without manual install.
# it could be a python2 / mac thing.
pip install pytest
python setup.py test

# -- DISTRIBUTE --
python setup.py sdist
# make a wheel from the source tarball (to use manifest correctly)
pip wheel --no-index --no-deps --wheel-dir dist dist/*.tar.gz
pip install twine
# make sure pip URLs are configured per https://truveris.github.io/articles/configuring-pypirc/
python -m twine upload --repository pypi dist/*

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

thumbor_extras-1.0.2.tar.gz (64.3 MB view details)

Uploaded Source

Built Distribution

thumbor_extras-1.0.2-py2-none-any.whl (64.3 MB view details)

Uploaded Python 2

File details

Details for the file thumbor_extras-1.0.2.tar.gz.

File metadata

  • Download URL: thumbor_extras-1.0.2.tar.gz
  • Upload date:
  • Size: 64.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16

File hashes

Hashes for thumbor_extras-1.0.2.tar.gz
Algorithm Hash digest
SHA256 385c60a91ca88bb2bf8a47470f86a7194b0479f6ed3a789546c12d2719f3946f
MD5 9acdbe645419a2a61e70b0d26325a542
BLAKE2b-256 15235a3f125dd3bd525b09f75e13e3abd39e614cd867105a8336a751288ef13a

See more details on using hashes here.

File details

Details for the file thumbor_extras-1.0.2-py2-none-any.whl.

File metadata

  • Download URL: thumbor_extras-1.0.2-py2-none-any.whl
  • Upload date:
  • Size: 64.3 MB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16

File hashes

Hashes for thumbor_extras-1.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 4907345fc32998f5d464535ec6a007546054b70a1d407ef6c0de10bdbaffd5d5
MD5 d3b37067561f797d45429b8f3ac633e1
BLAKE2b-256 4192ac85f838aef2130746415a2447f0f0916299b44429acb037a1b2afdeb01e

See more details on using hashes here.

Supported by

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