intelligentbee / FaceVision

Face Detection with Apple’s iOS 11 Vision Framework
49 stars 9 forks source link

13 compiler errors in the Face Detection Tutorial #3

Open dcaronson opened 6 years ago

dcaronson commented 6 years ago

Great Face Detection Vision Framework Tutorial!

There are a total of 13 compiler errors.

Cause of the 1st compiler error:

In the ImageViewController, I am receiving the following compiler error: Value of type 'VNFaceLandmarkRegion2D' has no member 'point'

Here is the line of code with the error: let point = landmark.point(at: i)

Here is the correction: let point = landmark.normalizedPoints[i]

Cause of the 2nd compiler error:

In the ImageViewController, I am receiving the following compiler error: Cannot convert value of type 'Int32' to expected argument type 'CGImagePropertyOrientation'

Here is the line of code with the error: let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, orientation: orientation ,options: [:])

Here is the correction: let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, orientation: CGImagePropertyOrientation(rawValue: CGImagePropertyOrientation.RawValue(orientation))! ,options: [:])

Sopheak0 commented 6 years ago

Do you have any solution to this error? I've got it too

FilipBulander commented 6 years ago

Hi, replace .point(at: i) with normalizedPoints[i]

and for the orientation replace snippet below:

var orientation:Int32 = 0        
 // detect image orientation, we need it to be accurate for the face detection to work
switch image.imageOrientation {
        case .up:
            orientation = 1
        case .right:
            orientation = 6
        case .down:
            orientation = 3
        case .left:
            orientation = 8
        default:
            orientation = 1
} 

with my one:

var orientation:CGImagePropertyOrientation = .down

// detect image orientation, we need it to be accurate for the face detection to work
switch image.imageOrientation {
        case .up:
            orientation = .up
        case .right:
            orientation = .right
        case .down:
            orientation = .down
        case .left:
            orientation = .left
        default:
            orientation = .down
 }

see PR https://github.com/intelligentbee/FaceVision/pull/4

tciuro commented 5 years ago

Also, you need to modify the following to in ViewController:imagePickerController():

dismiss(animated: true, completion: nil)
if let image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage {
    self.image = image
    performSegue(withIdentifier: "showImageSegue", sender: self)
}

Otherwise, the image view will not show the selected image.