How to get rect / coordinate object from VNClassificationObservation

there is a problem getting out VNClassificationObservation.

My target identifier is to recognize the object and display a pop-up window with the name of the object, I can get the name, but I can not get the coordinates of the object or frame.

Here is the code:

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

Then i process

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
    }
  }
}

UPDATED:

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)")
    }
}()
+4
source share
2 answers

This is because classifiers do not return object coordinates or frames. The classifier gives only a probability distribution over a list of categories.

What model are you using here?

+1
source

" ?", . Apple ( Inception v3) .

Vision , , MLModel, VNClassificationObservation .

, , , Vision. Core ML, MLModel . Vision , VNCoreMLFeatureValueObservation - .

, , . , , , , ..

+4

Source: https://habr.com/ru/post/1679902/


All Articles