私はこのhttps://www.raywenderlich.com/79149/grand-central-dispatch-tutorial-swift-part-1からGCD
チュートリアルを読んでいます。私が始めたプロジェクトをダウンロードして、ビルドするCIFeatureにはメンバーがありませんhasLeftEyePosition
、私はいくつかのエラーました:この行faceFeature.hasLeftEyePosition
で
private extension PhotoDetailViewController {
func faceOverlayImageFromImage(image: UIImage) -> UIImage {
let detector = CIDetector(ofType: CIDetectorTypeFace,
context: nil,
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
// Get features from the image
let newImage = CIImage(CGImage: image.CGImage!)
let features = detector.featuresInImage(newImage)
UIGraphicsBeginImageContext(image.size)
let imageRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
// Draws this in the upper left coordinate system
image.drawInRect(imageRect, blendMode: CGBlendMode.Normal, alpha: 1.0)
let context = UIGraphicsGetCurrentContext()
for faceFeature in features {
let faceRect = faceFeature.bounds
CGContextSaveGState(context)
// CI and CG work in different coordinate systems, we should translate to
// the correct one so we don't get mixed up when calculating the face position.
CGContextTranslateCTM(context, 0.0, imageRect.size.height)
CGContextScaleCTM(context, 1.0, -1.0)
if faceFeature.hasLeftEyePosition {
let leftEyePosition = faceFeature.leftEyePosition
let eyeWidth = faceRect.size.width/FaceBoundsToEyeScaleFactor
let eyeHeight = faceRect.size.height/FaceBoundsToEyeScaleFactor
let eyeRect = CGRect(x: leftEyePosition.x - eyeWidth/2.0,
y: leftEyePosition.y - eyeHeight/2.0,
width: eyeWidth,
height: eyeHeight)
drawEyeBallForFrame(eyeRect)
}
if faceFeature.hasRightEyePosition {
let leftEyePosition = faceFeature.rightEyePosition
let eyeWidth = faceRect.size.width/FaceBoundsToEyeScaleFactor
let eyeHeight = faceRect.size.height/FaceBoundsToEyeScaleFactor
let eyeRect = CGRect(x: leftEyePosition.x - eyeWidth/2.0,
y: leftEyePosition.y - eyeHeight/2.0,
width: eyeWidth,
height: eyeHeight)
drawEyeBallForFrame(eyeRect)
}
CGContextRestoreGState(context);
}
let overlayImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return overlayImage
}
を、それは言う:
Value of type 'CIFeature' has no member 'hasLeftEyePosition'
これを解決するために、どのように。
いずれかが認識されるであろうことができます。ありがとう。
のみ[ 'CIFaceFeature'](HTTPSを:あなたがクラッシュしたことがないことを確認したい場合は、あなたがそれを守る代わりに、入力画像を返すことができます(場合には、誰かが何か他のものに「顔」から
CIDetectorType
に変更します): //developer.apple.com/library/ios/documentation/CoreImage/Reference/CIFaceFeature/index.html#//apple_ref/occ/cl/CIFaceFeature)にはこのようなプロパティがあります。あなたはそれをキャストする必要があります。 – HAS