Skip to content

Commit

Permalink
apply correct aspectRatio when faceDetection fails to find face (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Mar 23, 2023
1 parent 34b1a45 commit 433b0b0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Sources/BrightroomEngine/Core/EditingStack.CropModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,31 @@ extension EditingStack {

public static func faceDetection(paddingBias: CGFloat = 1.3, aspectRatio: PixelAspectRatio? = nil) -> Self {
return .init { image, crop, completion in

var fallbackCrop: EditingCrop {
guard let aspectRatio = aspectRatio else {
return crop
}
var new = crop
new.updateCropExtentIfNeeded(toFitAspectRatio: aspectRatio)
return new
}

let request = VNDetectFaceRectanglesRequest { request, error in

if let error = error {
EngineLog.debug(error)
completion(crop)
completion(fallbackCrop)
return
}

guard let results = request.results as? [VNFaceObservation] else {
completion(crop)
completion(fallbackCrop)
return
}

guard let first = results.first else {
completion(crop)
completion(fallbackCrop)
return
}

Expand Down

0 comments on commit 433b0b0

Please sign in to comment.