compareDistance in Vision not working as expected

Hi,

When using VNFeaturePrintObservation and then computing the distance using two images, the values that it returns varies heavily. When two identical images (same image file) is inputted into function (below) that I have used to compare the images, the distance does not return 0 while it is expected to, since they are identical images.

Also, what is the upper limit of computeDistance? I am trying to find the percentage similarity between the two images. (Of course, this cannot be done unless the issue above is resolved).

Code that I have used is below

func featureprintObservationForImage(image: UIImage) -> VNFeaturePrintObservation? {
    let requestHandler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:])
    let request = VNGenerateImageFeaturePrintRequest()
    request.usesCPUOnly = true // Simulator Testing

    do {
      try requestHandler.perform([request])
      return request.results?.first as? VNFeaturePrintObservation
    } catch {
      print("Vision Error: \(error)")
      return nil
    }
  }

  func compare(origImg: UIImage, drawnImg: UIImage) -> Float? {
    let oImgObservation = featureprintObservationForImage(image: origImg)
    let dImgObservation = featureprintObservationForImage(image: drawnImg)

    if let oImgObservation = oImgObservation {
      if let dImgObservation = dImgObservation {
        var distance: Float = -1

        do {
          try oImgObservation.computeDistance(&distance, to: dImgObservation)
        } catch {
          fatalError("Failed to Compute Distance")
        }

        if distance == -1 {
          return nil
        } else {
          return distance
        }
      } else {
        print("Drawn Image Observation found Nil")
      }
    } else {
      print("Original Image Observation found Nil")
    }
    return nil
  }

Thanks for all the help!

I am having same issue. It always returns 19.737993, irrespective of what images I pass. Did you hear back?

Is there anything new in this subject ? I am getting same number too! ( 19.737993 ) @VipulArvind @chewethan

Am also having the same issue mentioned twice above (the 19.737993 magic number).

In the simulator, it's showing as 19.737993, but it's working correctly on a real device with usesCPUOnly = false.

compareDistance in Vision not working as expected
 
 
Q