嘿,我正在使用 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 个屏幕空间。
问题:
每当我尝试运行该应用程序时,相机流都会在一秒钟后冻结。那是因为探测器启动了。现在,如果您查看 github 示例应用程序 ( https://github.com/Affectiva/affdexme-ios/tree/master/apps/AffdexMe ),该应用程序商店也有提供。即使他们检测到情绪,相机视图仍然打开。
我什至尝试合并这两个函数,然后调用该函数,但不知何故,一个函数取消了另一个。
解决这个问题的方法是什么?
谢谢