Package apple.vision

Class VNGenerateOpticalFlowRequest

  • All Implemented Interfaces:
    NSCopying, NSObject

    public class VNGenerateOpticalFlowRequest
    extends VNTargetedImageRequest
    VNGenerateOpticalFlowRequest will determine directional change vectors for each pixel in the targeted image to transform it into the image processed by the request handler, reporting this result with a single VNPixelBufferObservation. Because this request works at the pixel level, both images must have the same dimensions in order for the request to be successfully performed. Setting a region of interest will isolate where the change determination is performed; however, the resultant observation will still be reported with a full resolution VNPixelBufferObservation. Optical flow requests are very resource intensive, so it is recommended that only one request at a time be created and that the handler where the request was issued be released immediately after generating optical flows. Example usage: - (nullable VNPixelBufferObservation*) opticalFlowFromImage:(CVPixelBufferRef)fromImage toImage:(CVPixelBuffer)toImage error:(NSError**)error { VNImageRequestHandler* imageRequestHandler = [[VNImageRequestHandler alloc] initWithCVPixelBuffer:fromImage options:@{}]; VNGenerateOpticalFlowRequest* request = [[VNGenerateOpticalFlowRequest alloc] initWithTargetedCVPixelBuffer:toImage options:@{}]; if (![imageRequestHandler performRequests:@[ request ] error:error]) { return nil; } return [[request results] firstObject]; }