0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 03:31:04 +01:00
wagtail/docs/image_feature_detection.rst

72 lines
2.2 KiB
ReStructuredText
Raw Normal View History

2014-07-22 18:40:30 +02:00
=======================
Image Feature Detection
=======================
Wagtail has the ability to automatically detect faces and features inside your images and automatically crop the images to those features.
Feature detection is used by the ``fill`` image filter. An image that has had feature detection run on it would be cropped based on the features that were detected.
Setup
=====
Feature detection requires OpenCV which can be a bit tricky to set up as it is not currently pip-installable.
Installing OpenCV on Debian/Ubuntu
----------------------------------
Debian and ubuntu provide ``python-opencv`` as a package installable with apt-get:
2014-07-22 18:40:30 +02:00
.. code-block:: bash
sudo apt-get install python-opencv python-numpy
If you are using a Virtual environment, you will need to make sure that you have site packages enabled so python can see OpenCV.
2014-07-22 18:40:30 +02:00
For Python 3, go into your pyvenv directory and open the ``pyvenv.cfg`` file then set ``include-system-site-packages`` to ``true``.
2014-07-22 18:40:30 +02:00
If you are using Virtualenv, go into your virtualenv directory and delete a file called ``lib/python-x.x/no-global-site-packages.txt``.
You can test that it's all working by opening up a python shell (with your virtual environment active) and typing:
2014-07-22 18:40:30 +02:00
.. code-block:: python
import cv
If you don't see an ``ImportError``, it worked.
2014-07-22 18:40:30 +02:00
Switching on feature detection
------------------------------
Once OpenCV is installed, you need to switch on feature detection in Wagtail
You can do this by seting the ``WAGTAIL_FEATURE_DETECTION_ENABLED`` setting to ``True``:
2014-07-22 18:40:30 +02:00
.. code-block:: python
# settings.py
WAGTAIL_FEATURE_DETECTION_ENABLED = True
Feature detection runs when new images are uploaded in to Wagtail. If you already have images in your Wagtail site and would like to run feature detection on them, you will have to run it manually.
Manually running feature detection
----------------------------------
You can manually feature detection on all images by running the following code in the python shell:
.. code-block:: python
from wagtail.wagtailimages.models import Image
2014-07-22 18:40:30 +02:00
for image in Image.objects.all():
if image.focal_point is None:
image.focal_point = image.get_suggested_focal_point()
image.save()