VNDetectTrajectoriesRequest not returning any observations

I have a VNDetectTrajectoriesRequest

Code Block
private lazy var pathRequest: VNDetectTrajectoriesRequest = { return VNDetectTrajectoriesRequest(frameAnalysisSpacing: .zero, trajectoryLength: 5, completionHandler: trajectoryHandler)}()

and the request handler inside the captureoutput for the camera like so.
Code Block let pathHandler = VNImageRequestHandler(cmSampleBuffer: sampleBuffer, options: [:])
do {
            try requestHandler.perform([pathRequest])
        } catch {
            print("Unable to perform the request: \(error).")
        }

When I run the app I see the completion handler get called 5 times with empty observations and then nothing . Even if a ball is rolled through the video being captured the completion handler never shows an observation.

Code Block
func trajectoryHandler(request: VNRequest, error: Error?) {
        print("have trajectory observation")
        guard let observations =
                request.results as? [VNTrajectoryObservation] else { return }
        print(observations)
    }

Any thoughts on what might be going on?


Replies

There are usually 2 reasons why a trajectory is not detected:
  1. The scene is not stable - meaning either the camera moved or there is too much movement in the background

  2. The moving object is filtered out by the parameters for trajectory length too long, or outside the minimum/maximumObjectSize

So after mounting the iPad I am now getting continuous calls to the completion handler, however I am still not seeing any observations when rolling a soccer ball through the camera's view. I have not set any minimum or maximum size and the trajectory length is set to 5, so if I am understanding things should give me the most opportunities to detect a path. Any other thoughts on what could be happening?
At this stage it is best to file a bug report and attach a video capture.