2016-10-01 11 views
0

このコードを使用して、CIFaceDetectorを使用して画像内の顔を検出したいとします。画像の向きによって画像内の顔を検出できない

let Orientation: Int! 

    switch ((info[UIImagePickerControllerOriginalImage] as? UIImage)?.imageOrientation)! { 
    case UIImageOrientation.up: 
     Orientation = 1 
    case UIImageOrientation.down: 
     Orientation = 3 
    case UIImageOrientation.left: 
     Orientation = 8 
    case UIImageOrientation.right: 
     Orientation = 6 
    case UIImageOrientation.upMirrored: 
     Orientation = 2 
    case UIImageOrientation.downMirrored: 
     Orientation = 4 
    case UIImageOrientation.leftMirrored: 
     Orientation = 5 
    case UIImageOrientation.rightMirrored: 
     Orientation = 7 
    } 

    let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorImageOrientation: Orientation] as [String : Any] 
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: options) 
    let faces = faceDetector?.features(in: personciImage) 

ただし、これは横向きにしか動作しません。なぜ私はそれが他のすべての方向ではうまくいかないのか分かりません。私は向きが正しく設定されるべきであることを意味する。私はUIImageをCIImageにキャストしています。

guard let personciImage = CIImage(image: (info[UIImagePickerControllerOriginalImage] as? UIImage)!) else { 
     return 
    } 

問題がありますか?

答えて

0

CIDetectorコンフィギュレーションドキュメントhereから、方向キーは実際にはこのクラスのオプションではないようです。画像を回転させる前に、顔検出クラスが実際に画像を回転させるのが実際に好きです。

画像を回転するのはかなり簡単で、SOでも検索することができます。私はもっ​​とあると確信しています! quick rotation search example

関連する問題