ios – 如何从VNClassificationObservation获取对象rect / coordinates

前端之家收集整理的这篇文章主要介绍了ios – 如何从VNClassificationObservation获取对象rect / coordinates前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
从VNClassificationObservation获取问题.

我的目标是识别对象并使用对象名称显示弹出窗口,我能够获得名称,但我无法获得对象坐标或框架.

这是代码

let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer,options: requestOptions)
do {
    try handler.perform([classificationRequest,detectFaceRequest])
} catch {
    print(error)
}

然后我处理

func handleClassification(request: VNRequest,error: Error?) {
      guard let observations = request.results as? [VNClassificationObservation] else {
          fatalError("unexpected result type from VNCoreMLRequest")
      }

    // Filter observation
    let filteredOservations = observations[0...10].filter({ $0.confidence > 0.1 })

    // Update UI
   DispatchQueue.main.async { [weak self] in

    for  observation in filteredOservations {
            print("observation: ",observation.identifier)
            //HERE: I need to display popup with observation name
    }
  }
}

更新:

lazy var classificationRequest: VNCoreMLRequest = {

    // Load the ML model through its generated class and create a Vision request for it.
    do {
        let model = try VNCoreMLModel(for: Inceptionv3().model)
        let request = VNCoreMLRequest(model: model,completionHandler: self.handleClassification)
        request.imageCropAndScaleOption = VNImageCropAndScaleOptionCenterCrop
        return request
    } catch {
        fatalError("can't load Vision ML model: \(error)")
    }
}()

解决方法

那是因为分类器不返回对象坐标或帧.分类器仅在类别列表上给出概率分布.

你在这里使用什么型号?

原文链接:https://www.f2er.com/iOS/327872.html

猜你在找的iOS相关文章