2016-11-29 3 views
-1

Я делаю приложение для обнаружения лиц. Я написал код для обнаружения, но я получаю сообщение об ошибке. Пожалуйста, предложите мне альтернативное решение. Вот код, и ошибка в строке номер 3.Ошибка: «использование неразрешенного идентификатора»

import UIKit 
import CoreImage 

class ViewController: UIViewController ,UIAlertViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 

    @IBOutlet var imageView: UIImageView! 
    @IBAction func Moodify(_ sender: UIButton) { 

     let picker = UIImagePickerController() 
     picker.delegate = self 
     picker.allowsEditing = true 
     picker.sourceType = .camera 
     self.present(picker, animated: true, completion: { _ in }) 


     func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [AnyHashable: Any]) { 
      let chosenImage = info[UIImagePickerControllerEditedImage] 
      self.imageView!.image = chosenImage as? UIImage 
      picker.dismiss(animated: true, completion: { _ in }) 
     } 

     func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { 
      picker.dismiss(animated: true, completion: { _ in }) 
     } 

    } 

    func detect() { 

     guard let personciImage = CIImage(image: personPic.image!) else { 
      return 
     } 

     let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh] 
     let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy) 
     let faces = faceDetector.featuresInImage(personciImage) 

     for face in faces as! [CIFaceFeature] { 

      print("Found bounds are \(face.bounds)") 

      let faceBox = UIView(frame: face.bounds) 

      faceBox.layer.borderWidth = 3 
      faceBox.layer.borderColor = UIColor.redColor().CGColor 
      faceBox.backgroundColor = UIColor.clearColor() 
      personPic.addSubview(faceBox) 

      if face.hasLeftEyePosition { 
       print("Left eye bounds are \(face.leftEyePosition)") 
      } 

      if face.hasRightEyePosition { 
       print("Right eye bounds are \(face.rightEyePosition)") 
      } 
     } 
    }  

    override func viewDidLoad() { 

     let alert = UIAlertController(title: "Error", message: "Device has no camera", preferredStyle: UIAlertControllerStyle.alert) 
     alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil)) 
     self.present(alert, animated: true, completion: nil) 


    /* if !UIImagePickerController.isSourceTypeAvailable(.camera) { 
      let myAlertView = UIAlertView (title: "Error", message: "Device has no camera", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "") 
      myAlertView.show() 
     } */ 

     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

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

SEE ERROR IN THIS IMAGE

+0

Где определен 'personPic'? Откуда оно? – Larme

+0

Где произносится 'personPic'? –

+0

Также почему вы отклонили мое редактирование? Он исправляет разбитое форматирование в вашем вопросе. В настоящее время ваш образ не доступен. –

ответ

1

Вы должны объявить его и подключиться к UIImageView в раскадровке.

@IBOutlet weak var personPic: UIImageView! 

Это базовое программирование. Как вы можете использовать то, что вы не заявили, не так ли? Хорошо, удачи в вашем проекте.

+1

Спасибо, дорогой, я заменил personPic своим изображением, которое я связал как IBOutlet. теперь он не показывает никаких ошибок. –

Смежные вопросы