CIDetector and UIImagePickerController

前端 未结 4 1186
借酒劲吻你
借酒劲吻你 2020-12-16 06:15

I\'m trying to implement the built-in iOS 5 face detection API. I\'m using an instance of UIImagePickerController to allow the user to take a photo and then I\'

4条回答
  •  温柔的废话
    2020-12-16 07:19

    Swift 3 Version

    var exifOrientation : Int
    switch (inputImage.imageOrientation)
    {
    case UIImageOrientation.up:
        exifOrientation = 1;
    case UIImageOrientation.down:
        exifOrientation = 3;
    case UIImageOrientation.left:
        exifOrientation = 8;
    case UIImageOrientation.right:
        exifOrientation = 6;
    case UIImageOrientation.upMirrored:
        exifOrientation = 2;
    case UIImageOrientation.downMirrored:
        exifOrientation = 4;
    case UIImageOrientation.leftMirrored:
        exifOrientation = 5;
    case UIImageOrientation.rightMirrored:
        exifOrientation = 7;
    }
    
    let ciImage = CIImage(cgImage: inputImage.cgImage!)
    let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options)!
    let faces = faceDetector.features(in: ciImage, options:["CIDetectorImageOrientation":exifOrientation])
    

提交回复
热议问题