【发布时间】:2021-05-27 11:30:55
【问题描述】:
我目前正在尝试从https://developers.google.com/ml-kit/vision/object-detection/ios跟随开发者将MLKit与iOS集成
当打开相机并开始检测物体时,出现运行时错误:
Precondition failed: NSArray element failed to match the Swift Array Element type
Expected MLKObject but found MLKObject: file Swift/ArrayBuffer.swift, line 354
如果我在本地模型中使用基本对象检测器而不是自定义对象检测器,则会出现同样的问题。
这是我用于设置和检测的内容:
1.
let options = ObjectDetectorOptions()
objectDetector = ObjectDetector.objectDetector(options: options)
guard let modelPath = Bundle.main.path(forResource: "mobilenet_v1_0.25_128_quantized_1_metadata_1", ofType: "tflite") else {
return
}
let localModel = LocalModel(path: modelPath)
let options = CustomObjectDetectorOptions(localModel: localModel)
objectDetector = ObjectDetector.objectDetector(options: options)
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
let image = VisionImage(buffer: sampleBuffer)
image.orientation = imageOrientation()
objectDetector?.process(image) { objects, error in
guard error == nil, let detectedObjects = objects else { return }
for object in detectedObjects { //error occurs here
let frame = object.frame
let trackingID = object.trackingID
let description = object.labels.enumerated().map { (index, label) in
"Label \(index): \(label.text), \(label.confidence)"
}.joined(separator:"\n")
}
}
}
【问题讨论】:
标签: ios swift google-mlkit