From 39ab06722b289b1c4def329b7d547c12c96081cc Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 11 Sep 2014 14:22:38 +0100 Subject: [PATCH] Set WAGTAILIMAGES_FEATURE_DETECTION_ENABLED to False by default in project template, and avoid importing OpenCV if it's false to avoid spurious errors about libdc1394 --- .../project_name/settings/base.py | 4 ++++ .../wagtailimages/utils/feature_detection.py | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/wagtail/project_template/project_name/settings/base.py b/wagtail/project_template/project_name/settings/base.py index 1571036c6..b0ad25c3b 100644 --- a/wagtail/project_template/project_name/settings/base.py +++ b/wagtail/project_template/project_name/settings/base.py @@ -158,3 +158,7 @@ WAGTAIL_SITE_NAME = "{{ project_name }}" # 'INDEX': '{{ project_name }}', # }, # } + + +# Whether to use face/feature detection to improve image cropping - requires OpenCV +WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = False diff --git a/wagtail/wagtailimages/utils/feature_detection.py b/wagtail/wagtailimages/utils/feature_detection.py index 6381fabf7..6aab45c97 100644 --- a/wagtail/wagtailimages/utils/feature_detection.py +++ b/wagtail/wagtailimages/utils/feature_detection.py @@ -1,16 +1,23 @@ import os +from django.conf import settings -try: - import cv - - opencv_available = True -except ImportError: +# only try to import OpenCV if WAGTAILIMAGES_FEATURE_DETECTION_ENABLED is True - +# avoids spurious "libdc1394 error: Failed to initialize libdc1394" errors on sites that +# don't even use OpenCV +if getattr(settings, 'WAGTAILIMAGES_FEATURE_DETECTION_ENABLED', False): try: - import cv2.cv as cv + import cv opencv_available = True except ImportError: - opencv_available = False + try: + import cv2.cv as cv + + opencv_available = True + except ImportError: + opencv_available = False +else: + opencv_available = False from wagtail.wagtailimages.utils.focal_point import FocalPoint, combine_focal_points