前提・実現したいこと
参照サイトを参考に顔輪郭を認識するアプリを作成しようとしていますが、そのままサンブルコードをコンパイルしようとすると2種類のエラーが発生します。
一種類目のエラーはRequestを処理(ハンドル)するクラスのリクエストハンドラーでエラーが起こっています。画像やデータを保持し、解析処理を実行するクラスです。
2種類目のエラーは顔輪郭や目 鼻などのランドマークを描写する際に発生しています。
発生している問題・エラーメッセージ
Cannot convert value of type 'Int32' to expected argument type 'CGImagePropertyOrientation' int32型を CGImagePropertyOrientation'という引数タイプに変えられないということだと思います。 Value of type 'VNFaceLandmarkRegion2D' has no member 'point' VNFaceLandmarkRegion2Dの型の値はpointというメンバーを持っていない。
該当のソースコード
一部抜粋です
swift
1import UIKit 2import Vision 3 4class ImageViewController: UIViewController { 5 6 @IBOutlet weak var imageView: UIImageView! 7 8 var image: UIImage! 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 // Do any additional setup after loading the view. 14 imageView.image = image 15 } 16 17 @IBAction func process(_ sender: UIButton) { 18 var orientation:Int32 = 0 19 20 // detect image orientation, we need it to be accurate for the face detection to work 21 switch image.imageOrientation { 22 case .up: 23 orientation = 1 24 case .right: 25 orientation = 6 26 case .down: 27 orientation = 3 28 case .left: 29 orientation = 8 30 default: 31 orientation = 1 32 } 33 34 // vision 35 let faceLandmarksRequest = VNDetectFaceLandmarksRequest(completionHandler: self.handleFaceFeatures) 36 let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, orientation: orientation ,options: [:]) 37 do { 38 try requestHandler.perform([faceLandmarksRequest]) 39 } catch { 40 print(error) 41 } 42 } 43 44 45 46// face contour 47 context?.saveGState() 48 context?.setStrokeColor(UIColor.yellow.cgColor) 49 if let landmark = face.landmarks?.faceContour { 50 for i in 0...landmark.pointCount - 1 { // last point is 0,0 51 let point = landmark.point(at: i) 52 if i == 0 { 53 context?.move(to: CGPoint(x: x + CGFloat(point.x) * w, y: y + CGFloat(point.y) * h)) 54 } else { 55 context?.addLine(to: CGPoint(x: x + CGFloat(point.x) * w, y: y + CGFloat(point.y) * h)) 56 } 57 } 58 } 59 context?.setLineWidth(8.0) 60 context?.drawPath(using: .stroke) 61 context?.saveGState()
試したこと
エラーメッセージで調べ参照サイト
let point = landmark.normalizedPoints[i]
としても 同じエラーでした(Value of type 'VNFaceLandmarkRegion2D' has no member 'point')
何かわかる方はいらっしゃますか?
補足情報(FW/ツールのバージョンなど)
Version 10.1 (10B61)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。