gpt4 book ai didi

ios - 如何在实时帧捕获中使用 GoogleMobileVision?

转载 作者:行者123 更新时间:2023-11-28 07:58:16 29 4
gpt4 key购买 nike

我正在尝试实时检测微笑概率。使用 GoogleMobileVision,但由于我在 GMVDetector 中传递的 options 参数导致应用程序崩溃。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue intValue]

此外,当我将选项作为 nil 传递时,它会出现内存问题。

我的代码:

import UIKit
import GoogleMobileVision

class ViewController: UIViewController, FrameExtractorDelegate {

@IBOutlet weak var lblSmiling: UILabel!
var frameExtractor: FrameExtractor!
var faceDetector = GMVDetector()

@IBOutlet weak var imageView: UIImageView!

@IBAction func flipButton(_ sender: UIButton) {
frameExtractor.flipCamera()
}

override func viewDidLoad() {
super.viewDidLoad()
frameExtractor = FrameExtractor()
frameExtractor.delegate = self
let options: NSDictionary = [GMVDetectorFaceLandmarkType: GMVDetectorFaceLandmark.all, GMVDetectorFaceClassificationType: GMVDetectorFaceClassification.all, GMVDetectorFaceTrackingEnabled: true]

self.faceDetector = GMVDetector(ofType: GMVDetectorTypeFace, options: options as! [AnyHashable : Any])
}

// Getting individual frame image here
func captured(image: UIImage) {
processImage(image: image)
imageView.image = image
}

func processImage(image: UIImage) {

let faces : [GMVFaceFeature] = faceDetector.features(in: image, options: nil) as! [GMVFaceFeature]

for face in faces {

if face.hasSmilingProbability && face.smilingProbability > 0.4 {
lblSmiling.text = String(describing: face.smilingProbability)
}
}
}

最佳答案

我认为您正在使用一些可选值,您需要编写此代码才能正常工作。

let options: NSDictionary = [GMVDetectorFaceLandmarkType: GMVDetectorFaceLandmark.all.rowValue, GMVDetectorFaceClassificationType: GMVDetectorFaceClassification.all.rowValue, GMVDetectorFaceTrackingEnabled: true]

关于ios - 如何在实时帧捕获中使用 GoogleMobileVision?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47348537/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com