Object detection from image using vision framework

473 views Asked by At

I am trying to detect objects from a given image. From research I just found that we can detect and track an object for the videos using the following process:

private lazy var cameraLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession)

private func tapGestureAction(recognizer: UITapGestureRecognizer) 
 {
   highlightView.frame.size = CGSize(width: 200, height: 200)
   highlightView.center = recognizer.location(in: view)

   let originalRect = highlightView.frame
   var convertedRect = cameraLayer.metadataOutputRectConverted(fromLayerRect: originalRect)
   convertedRect.origin.y = 1 - convertedRect.origin.y

   previousObservation = VNDetectedObjectObservation(boundingBox: convertedRect)
 }

Can we have similar method like metadataOutputRectConverted for imageView? I am trying to detect the object rect whenever the user taps on that object. How can this be accomplished?

1

There are 1 answers

1
truongtho1603 On

this method to convert the camera output rect ( topleft(0,0) to bottomright(0,1)) to the UI rect. So, I think you do not need to convert it