はVNClassificationObservation
からの取得に問題があります。VNClassificationObservationからオブジェクトの矩形/座標を取得する方法
オブジェクトを認識してポップアップにオブジェクト名を表示する私の目標IDは、名前を取得できますが、オブジェクトの座標またはフレームを取得できません。
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)")
}
}()
私はInceptionv3()モデルを使用していますが、座標を取得できません。 – Svitlana
これは、Inception-v3では座標が与えられず、クラス名の辞書とこれらのクラスの確率しか与えられないからです。 –
ありがとう、他のモデルを検索します – Svitlana