前提・実現したいこと
プログラミング初心者です。
このサイトのコードを参考にして顔認証アプリを作成しようとしています
(https://qiita.com/tfactory/items/f03c77a29ddfae805b87)
カメラを起動する→写真撮影→写真の顔と機械学習させた顔を認証→誰なのか判別する
このような手順で作りたいのですが、写真撮影をする方法、撮影した写真の顔と機械学習させた顔を認証させるためのコードをどこに書き込むべきなのか、全く分かりません。
全てお教えいただくのが厳しいようでしたら、参考になるサイトやヒントだけでもありがたいです。
よろしくお願い致します。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
swift
1 import UIKit 2 import AVFoundation 3 import Vision 4 5 class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { 6 7 let recognitionLabel: UILabel = { 8 let recognitionLabel = UILabel() 9 recognitionLabel.textColor = .white 10 recognitionLabel.translatesAutoresizingMaskIntoConstraints = false 11 recognitionLabel.text = "" 12 recognitionLabel.font = recognitionLabel.font.withSize(24) 13 return recognitionLabel 14 }() 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 setupCaptureSession() 19 20 print("in viewDidLoad") 21 22 view.addSubview(recognitionLabel) 23 recognitionLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 24 recognitionLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -50).isActive = true 25 } 26 27 func setupCaptureSession() { 28 let captureSession = AVCaptureSession() 29 30 print("in setupcap") 31 32 let availableDevices = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .front).devices 33 34 do { 35 if let captureDevice = availableDevices.first { 36 captureSession.addInput(try AVCaptureDeviceInput(device: captureDevice)) 37 38 print("入力") 39 40 } 41 } catch { 42 print(error.localizedDescription) 43 } 44 45 let captureOutput = AVCaptureVideoDataOutput() 46 captureSession.addOutput(captureOutput) 47 48 captureOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue")) 49 50 let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) 51 previewLayer.frame = view.frame 52 view.layer.addSublayer(previewLayer) 53 54 captureSession.startRunning() 55 } 56 57 func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 58 // 機械学習モデルの取得 59 //modelを変換してる 60 guard let model = try? VNCoreMLModel(for: ImageClassifier().model) else { return } 61 62 guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } 63 64 // 機械学習モデルを利用して画像認識 65 let request = VNCoreMLRequest(model: model) { (finishedRequest, error) in 66 guard let results = finishedRequest.results as? [VNClassificationObservation] else { return } 67 guard let Observation = results.first else { return } 68 69 DispatchQueue.main.async(execute: { 70 self.recognitionLabel.text = "(Observation.identifier)" 71 }) 72 } 73 74 try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request]) 75 } 76 } 77
試したこと
これらのサイトを参考にいろいろ試しましたが解決しませんでした
https://qiita.com/renchild8/items/b2e04fe48cb2cf60bcbc
https://dev.classmethod.jp/smartphone/iphone/ios-11-core-ml-2/
https://blog.codecamp.jp/programming-iphone-app-development-camera
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/12 09:13