[swift] Swift에서 Core Image로 얼굴 인식을 할 수 있나요?

다음은 Swift에서 Core Image를 사용하여 얼굴을 감지하는 간단한 예제입니다:

import UIKit
import CoreImage

func detectFaces(image: UIImage) {
    if let ciImage = CIImage(image: image) {
        let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
        let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)
        let features = faceDetector?.features(in: ciImage)

        if let features = features {
            for feature in features as! [CIFaceFeature] {
                // 감지된 얼굴에 대한 작업 수행
                print("얼굴이 감지되었습니다. 위치: \(feature.bounds)")
                if feature.hasLeftEyePosition {
                    print("왼쪽 눈 위치: \(feature.leftEyePosition)")
                }
                if feature.hasRightEyePosition {
                    print("오른쪽 눈 위치: \(feature.rightEyePosition)")
                }
                // 추가적인 얼굴 특징을 처리
            }
        }
    }
}

let image = UIImage(named: "faceImage.jpg") // 감지할 이미지
detectFaces(image: image)

위의 예제에서는 CIDetector를 사용하여 이미지에서 얼굴을 찾고, 각 얼굴의 특징을 출력하는 간단한 함수를 보여줍니다.

더 많은 기능과 자세한 사용법은 Apple의 공식 문서를 참고하시기 바랍니다: https://developer.apple.com/documentation/coreimage/cidetector