こんにちは私はAffectiva Affdex ios SDKを使用しています。今私は2つのビューがあります。カメラが感情検出機能を起動するとフリーズする
UIView - >ここではカメラストリームを実行します。そのためのコードはここにある:
func allConfig(withCamView cams:UIView) { let captureDevice = AVCaptureDeviceDiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: .unspecified) for device in (captureDevice?.devices)! { if device.position == .front{ do { let input = try AVCaptureDeviceInput(device: device) if session.canAddInput(input) { session.addInput(input) } if session.canAddOutput(previewOutput) { session.addOutput(previewOutput) } previewLayer = AVCaptureVideoPreviewLayer(session: session) previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill previewLayer.connection.videoOrientation = .portrait cams.layer.addSublayer(previewLayer) previewLayer.position = CGPoint(x: cams.frame.width/2, y: cams.frame.height/2) previewLayer.bounds = cams.frame session.startRunning() } catch let avError { print(avError) } } } }
私は検出器を始めています別のUICollectionViewセル。そのためのコードはここにある:
func createDetector() { destroyDetector() let captureDevice = AVCaptureDeviceDiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera], mediaType: AVMediaTypeVideo, position: .unspecified) for device in (captureDevice?.devices)! { if device.position == .front{ EMDetector = AFDXDetector(delegate: self, using: device, maximumFaces: 2, face: LARGE_FACES) EMDetector.maxProcessRate = 5 // turn on all classifiers (emotions, expressions, and emojis) EMDetector.setDetectAllExpressions(true) EMDetector.setDetectAllEmotions(true) EMDetector.setDetectAllAppearances(true) EMDetector.setDetectEmojis(true) // turn on gender and glasses EMDetector.gender = true EMDetector.glasses = true // start the detector and check for failure let error: Error? = EMDetector.start() if nil != error { print("Some Faliure in detector") print("root cause of error ------------------------- > \(error.debugDescription)") } } } }
これらのビューは、50-50画面スペースを取ります。
問題:私は試してみて、アプリケーションを実行するたびに
、カメラのストリームは、1秒後にフリーズします。そしてそれは検出器が始まるからです。 githubサンプルアプリ(https://github.com/Affectiva/affdexme-ios/tree/master/apps/AffdexMe)をチェックすると、アプリストアでも利用できます。感情を検出してもカメラビューはオンのままです。
2つの関数をマージして関数を呼び出そうとしましたが、何とか1つの関数がもう一方の関数を取り消すことさえありました。
どうしたらいいですか?
おかげ
を使用して検出器にあなたのキャプチャセッションからのために多くの多くのおかげで画像を渡すこの
EMDetector = AFDXDetector(delegate: self, discreteImages: false, maximumFaces: 2, face: LARGE_FACES)
のようなあなたの検出器を初期化します回答。私は本当に解決策が必要でした。 質問がありました。最初の方法で行った場合、両方のビューでデリゲートメソッドと他の処理済みImageメソッドを定義する必要があります –
両方のビューでデリゲートメソッドを定義するとどういう意味ですか?あなたの検出器は1つだけの代理人を持っている必要がありますし、両方のビューに画像を渡します –
ちょっと、ちょっと!私は私のカムセッションを通して画像を検出器に通す別の方法を使用しています。画像から顔を見つけることができません。ここで問題になるのは何ですか? –