diff --git a/docs/core_components/images/feature_detection.rst b/docs/core_components/images/feature_detection.rst index 38e80d1e6b..1d57b5a458 100644 --- a/docs/core_components/images/feature_detection.rst +++ b/docs/core_components/images/feature_detection.rst @@ -2,35 +2,53 @@ Feature Detection ================= -Wagtail has the ability to automatically detect faces and features inside your images and automatically crop the images to those features. +Wagtail has the ability to automatically detect faces and features inside your images and 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. +Feature detection uses OpenCV to detect faces/features in an image when the image is uploaded. The detected features stored internally as a focal point in the ``focal_point_{x, y, width, height}`` fields on the ``Image`` model. These fields are used by the ``fill`` image filter when an image is rendered in a template to crop the image. Setup ===== -Feature detection requires OpenCV which can be a bit tricky to set up as it is not currently pip-installable. +Feature detection requires OpenCV which can be a bit tricky to install as it's not currently pip-installable. Installing OpenCV on Debian/Ubuntu ---------------------------------- -Debian and ubuntu provide ``python-opencv`` as a package installable with apt-get: +Debian and ubuntu provide an apt-get package called ``python-opencv``: .. 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. - -For Python 3, go into your pyvenv directory and open the ``pyvenv.cfg`` file then set ``include-system-site-packages`` to ``true``. - -If you are using Virtualenv, go into your virtualenv directory and delete a file called ``lib/python-x.x/no-global-site-packages.txt``. +This will install PyOpenCV into your site packages. If you are using a virtual environment, you need to make sure site packages are enabled or Wagtail will not be able to import PyOpenCV. -You can test that it's all working by opening up a python shell (with your virtual environment active) and typing: +Enabling site packages in the virtual environment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you are not using a virtual envionment, you can skip this step. + +Enabling site packages is different depending on whether you are using pyvenv (Python 3.3+ only) or virtualenv to manage your virtual environment. + + +pyvenv +`````` + +Go into your pyvenv directory and open the ``pyvenv.cfg`` file then set ``include-system-site-packages`` to ``true``. + + +virtualenv +`````````` + +Go into your virtualenv directory and delete a file called ``lib/python-x.x/no-global-site-packages.txt``. + + +Testing the OpenCV installation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can test that OpenCV can be seen by Wagtail by opening up a python shell (with your virtual environment active) and typing: .. code-block:: python @@ -39,12 +57,10 @@ You can test that it's all working by opening up a python shell (with your virtu If you don't see an ``ImportError``, it worked. -Switching on feature detection ------------------------------- +Switching on feature detection in Wagtail +----------------------------------------- -Once OpenCV is installed, you need to switch on feature detection in Wagtail - -You can do this by seting the ``WAGTAILIMAGES_FEATURE_DETECTION_ENABLED`` setting to ``True``: +Once OpenCV is installed, you need to set the ``WAGTAILIMAGES_FEATURE_DETECTION_ENABLED`` setting to ``True``: .. code-block:: python @@ -53,13 +69,12 @@ You can do this by seting the ``WAGTAILIMAGES_FEATURE_DETECTION_ENABLED`` settin WAGTAILIMAGES_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: +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. + +You can manually run feature detection on all images by running the following code in the python shell: .. code-block:: python