kopia lustrzana https://github.com/wagtail/wagtail
Moved some smartcropping code into feature_detection
rodzic
76a3e5bce4
commit
9ee089042d
|
@ -59,15 +59,10 @@ class BaseImageBackend(object):
|
|||
def smart_crop(self, image, size):
|
||||
image_mode, image_data = self.image_data_as_rgb(image)
|
||||
|
||||
# Face detection
|
||||
faces = feature_detection.detect_faces(image.size, image_mode, image_data)
|
||||
if faces:
|
||||
return self.crop_to_point(image, size, focal_point.combine_points(faces))
|
||||
|
||||
# Feature detection
|
||||
features = feature_detection.detect_features(image.size, image_mode, image_data)
|
||||
if features:
|
||||
return self.crop_to_point(image, size, focal_point.combine_points(features))
|
||||
# Use feature detection to find a focal point
|
||||
focal_point = feature_detection.get_focal_point(image.size, image_mode, image_data)
|
||||
if focal_point:
|
||||
return self.crop_to_point(image, size, focal_point)
|
||||
|
||||
# Fall back to crop to centre
|
||||
return self.crop_to_centre(image, size)
|
||||
|
|
|
@ -13,7 +13,7 @@ except ImportError:
|
|||
opencv_available = False
|
||||
|
||||
|
||||
from wagtail.wagtailimages.utils.focal_point import FocalPoint
|
||||
from wagtail.wagtailimages.utils.focal_point import FocalPoint, combine_points
|
||||
|
||||
|
||||
def get_cv_gray_image(image_size, image_mode, image_data):
|
||||
|
@ -65,3 +65,17 @@ def detect_faces(image_size, image_mode, image_data):
|
|||
return [FocalPoint.from_square(face[0][0], face[0][1], face[0][2], face[0][3]) for face in faces]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def get_focal_point(image_size, image_mode, image_data):
|
||||
# Face detection
|
||||
faces = feature_detection.detect_faces(image_size, image_mode, image_data)
|
||||
|
||||
if faces:
|
||||
return combine_points(faces)
|
||||
|
||||
# Feature detection
|
||||
features = feature_detection.detect_features(image_size, image_mode, image_data)
|
||||
|
||||
if features:
|
||||
return focal_point.combine_points(features)
|
||||
|
|
Ładowanie…
Reference in New Issue