Object tracking on iOS [Vision]

  1. Make a sequence handler for tracking.
let requestHandler = VNSequenceRequestHandler()
var inputObservation = VNDetectedObjectObservation(boundingBox: cgrect)
let request = VNTrackObjectRequest(detectedObjectObservation: inputObservation)
do {
try requestHandler.perform([request], on: pixelBuffer, orientation: videoOrientation)
} catch {
print("Tracking failed.")
guard let observation = request.results?.first as? VNDetectedObjectObservation else { return }
inputObservation = observation


・You can manually specify CGRect as the object observation, or you can directly specify the detection result of Face, body, hand, animal etc. of Vision, or the object detection result of Core ML.

request.trackingLevel = .fast



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store