問題是我的代碼只能用於一張臉。如果我拍了兩張臉的照片,它不會檢測到第二張臉,而對於兩張以上的臉也是如此。這裏是我的代碼:CIFaceFeature只檢測一張臉
if let inputImage = imageView.image {
let ciImage = CIImage(CGImage: inputImage.CGImage!)
let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)
let faces = faceDetector.featuresInImage(ciImage)
if let face = faces.first as? CIFaceFeature {
print("Found face at \(face.bounds)")
if face.hasLeftEyePosition {
print("Found left eye at \(face.leftEyePosition)")
}
if face.hasRightEyePosition {
print("Found right eye at \(face.rightEyePosition)")
}
if face.hasMouthPosition {
print("Found mouth at \(face.mouthPosition)")
}
}
print("\(faces.count)")
}
'if let face = faces.first'確實只有一張臉,因爲*你*只能在第一張臉上工作。 ;) – Moritz
@EricD,所以我需要通過運行一個循環來修復它,直到計算完面的數量爲止? –