2016-10-13 4 views
-1

エラーがのライン上にある私は、顔検出にVEAソフトウェアのオフに続いている問題であり、何スレッド1:「ガードしましょう顔画像= CIImage」EXC不正命令(コード= EXC_1386

override func viewDidLoad() { 
    super.viewDidLoad() 
    imageView.image = UIImage(named: "FaceDetection") // name of first image to check out 
    findFace() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func findFace() { 

    // guard function = if everything equals to nil, then code will break out of function 
    guard let faceImage = CIImage(image: imageView.image!) else {return} 
    let accuracy = [CIDetectorAccuracy:CIDetectorAccuracyHigh] // highest accuracy for facial recognition 
    let faceDector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy) // searches for faces in still image/video 
    let faces = faceDector?.features(in: faceImage, options: [CIDetectorSmile:true, CIDetectorEyeBlink:true]) 
    for face in faces as! [CIFaceFeature] { 
     if face.hasSmile { 
      // if face in picture is smiling 
      print("☺️") 
     } 
     if face.leftEyeClosed { 
      // if left eye is closed on the face in the picture 
      print("Left:") 
     } 
     if face.rightEyeClosed { 
      // if right eye is closed on the face in the picture 
      print("Right:") 
     } 
    } 
     if faces!.count != 0 { 
      // face is only detected 
     print("Number of Faces: \(faces!.count)") 
     } else { 
      // no faces detected 
      print("No Faces: ") 

答えて

0
。?

それは非常に簡単ですあなたはこのようなimageView.imageを設定されています

imageView.image = UIImage(named: "FaceDetection") 

その行が失敗している、あなたはそのようなイメージを持っていないこのように、imageView.imagenilであるあなたがimageView.image!を言うときそして、後であなたが強制的にアンラップnilをつまり。。。。スウィフトでのクラッシュ、あなたクラッシュ。

+0

私はプロジェクトで使用している顔が私の資産フォルダにあります。これは問題の一部ですか? – Terril320

+0

imageView.imageがnilで、強制アンラップされていると、「致命的なエラーが発生しません:オプションの値をアンラップすると予期せぬエラーが発生しました」 – penatheboss

+0

@penatheboss彼はそれを手に入れている。彼はそう言わない。 (彼はそれを探す場所を知らないかもしれません) – matt

関連する問題