2016-11-29 4 views
-1

얼굴 인식 앱을 만들고 있습니다. 내가 탐지를위한 코드를 작성했지만 오류가 발생했습니다. 친절하게도 대체 솔루션을 제안 해주십시오. 다음은 코드이며, 오류가 행 번호 당신은 그것을 선언하고 스토리 보드에있는 UIImageView에 연결해야합니다 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

이다.

@IBOutlet weak var personPic: UIImageView! 

이것은 프로그래밍의 기본입니다. 당신이 선언하지 않은 것을 어떻게 사용할 수 있습니까? 프로젝트에서 행운을 빈다.

+1

로 편집 해 주셔서 대단히 감사합니다. 저는 personPic을 내 이미지로 바꿨습니다. IBOutlet으로 연결 한 것입니다. 이제 오류가 표시되지 않습니다. –

관련 문제