Docs_iOS_FD_FaceDetection
Docs_iOS_FD_FaceDetection
0
Installation
Drag and drop the file into the Frameworks, Libraries and Embedded Content section of
the project settings.
With CocoaPods
Coming soon!
Bounding boxes
In order to detect bounding boxes on a photo, all you need is an UIImage or CMSampleBuffer
containing an image loaded into the memory. Detector can be initialized ad hoc - like in the example - or
you can cache it and use the same detector for multiple images.
func detectBboxes(in image: UIImage) {
guard let detection = PNBoundingBoxDetector() else {
// Handle error
return
}
do {
let result = try detection.getBoundingBoxes(image: image) // or buffer: for CMSample
for bbox in result { // CGRect
// Handle
}
} catch {
// Handle error
}
}
The result of quality estimator will always be an array of the same length as the input bounding boxes
array, with the corresponding quality/acceptability values at the same indexes as their bounding boxes.
Landmarks
In order to detect the landmarks of the faces in a photo you need to provide, aside from the image also a
set of bounding boxes represented by CGRect type.
func detectLandmarks(for boundingBoxes: [CGRect], image: UIImage) {
guard let landmarkDetection = PNLandmarkDetector() else {
// Handle error
return
}
do {
let landmarks = try landmarkDetection.getLandmarks(image: image, boundingBoxes: boun
let landmarksAndBboxes = zip(landmarks, boundingBoxes)
// Parse result
} catch {
// Handle error
}
}
The result of landmark detector will always be an array of the same length as the input bounding boxes
array, with the corresponding landmark values at the same indexes as their bounding boxes.
Types
PNBoundingBoxDetector
CLASS
PNBoundingBoxDetector
Methods
init()
Convenience init. Will return nil only in case internal module initialization failed.
getBoundingBoxes()
public func getBoundingBoxes(image: UIImage? = nil, buffer: CMSampleBuffer? = nil, data: Dat
Parameter image: UIImage initialized with the image that's intended to be analyzed (alternatively
parameter buffer: or data:).
Returns: An array of bounding boxes detected on the image. If no face detected, array will be empty.
The array is sorted by face size (from largest to smallest).
Throws: Can throw in case of any undesired internal behaviour.
Parameters
Name Description
STRUCT
PNLandmarks
Properties
eyeRight
eyeLeft
nose
mouthRight
mouthLeft
public let mouthLeft: CGPoint
Methods
init(eyeRight:eyeLeft:nose:mouthRight:mouthLeft:)
public init(eyeRight: CGPoint, eyeLeft: CGPoint, nose: CGPoint, mouthRight: CGPoint, mouthLe
Default initializer.
asCGPointArray()
CLASS
PNLandmarkDetector
Landmark detector. Finds face landmarks on a provided image, given bounding boxes as input.
Methods
init()
Convenience init. Will return nil only in case internal module initialization failed.
getLandmarks(boundingBoxes:)
public func getLandmarks(image: UIImage? = nil, buffer: CMSampleBuffer? = nil, data: Data? =
Parameter image: UIImage initialized with the image that's intended to be analyzed (alternatively
parameter buffer: or data:).
Parameter boundingBoxes: Previously detected bounding boxes. These don't necessarily have to be
a result of PNBoundingBoxDetector , but they should represent an actual face on the image.
Parameters
Name Description
CLASS
PNQualityEstimator
Quality estimator. Calculates face image quality and acceptability on a provided image, given bounding
boxes as input.
Methods
init()
Convenience init. Will return nil only in case internal module initialization failed.
getQualities (boundingBoxes:)
public func getQualities(image: UIImage? = nil, buffer: CMSampleBuffer? = nil, data: Data? =
Parameter image: UIImage initialized with the image that's intended to be analyzed (alternatively
parameter buffer: or data:).
Parameter boundingBoxes: Previously detected bounding boxes. These don't necessarily have to be
a result of PNBoundingBoxDetector , but they should represent an actual face on the image.
Parameters
Name Description
STRUCT
PNQuality
Properties
quality
acceptability
Methods
init(quality:acceptability:)
Default initializer.
Release notes
v2.0
Date
01 Mar 2023
Description
Monolithic SDK has been split up into three separate SDKs: Face Detection (iOS FD SDK), Face
Recognition (iOS FR SDK), and Liveness 2D RGB (iOS FL SDK)
API changes have been applied in order to align the SDK with other Paravision SDKs:
PNBoundingBoxDetector.getBoundingBoxes replaced
PNBoundingBoxDetector.detect