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
}
問題がありますか?