objc2_vision/generated/VNTrackOpticalFlowRequest.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-media")]
7use objc2_core_media::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// The level of optical flow computational accuracy.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vntrackopticalflowrequestcomputationaccuracy?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct VNTrackOpticalFlowRequestComputationAccuracy(pub NSUInteger);
19impl VNTrackOpticalFlowRequestComputationAccuracy {
20 #[doc(alias = "VNTrackOpticalFlowRequestComputationAccuracyLow")]
21 pub const Low: Self = Self(0);
22 #[doc(alias = "VNTrackOpticalFlowRequestComputationAccuracyMedium")]
23 pub const Medium: Self = Self(1);
24 #[doc(alias = "VNTrackOpticalFlowRequestComputationAccuracyHigh")]
25 pub const High: Self = Self(2);
26 #[doc(alias = "VNTrackOpticalFlowRequestComputationAccuracyVeryHigh")]
27 pub const VeryHigh: Self = Self(3);
28}
29
30unsafe impl Encode for VNTrackOpticalFlowRequestComputationAccuracy {
31 const ENCODING: Encoding = NSUInteger::ENCODING;
32}
33
34unsafe impl RefEncode for VNTrackOpticalFlowRequestComputationAccuracy {
35 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38extern_class!(
39 /// `VNTrackOpticalFlowRequest` will determine directional change vectors for each pixel from a previous to current image, reporting this result with a single `VNPixelBufferObservation`.
40 ///
41 ///
42 /// Because this request works at the pixel level, both images must have the same dimensions in order for the request to be successfully performed.
43 /// Setting a region of interest will isolate where the change determination is performed; however, the resultant observation will still be reported
44 /// with a full resolution `VNPixelBufferObservation.
45 ///
46 /// Being a stateful request, at least two images must me processed in order to produce an observation.
47 ///
48 /// Optical flow requests are very resource intensive, so it is recommended that only one request at a time be created and that the handler
49 /// where the request was issued be released immediately after generating optical flows.
50 ///
51 /// Example usage:
52 ///
53 /// - (nullable VNPixelBufferObservation*) opticalFlowFromImage:(CVPixelBufferRef)fromImage toImage:(CVPixelBuffer)toImage error:(NSError**)error
54 /// {
55 /// VNTrackOpticalFlowRequest* request = [[VNTrackOpticalFlowRequest alloc] init];
56 ///
57 /// VNImageRequestHandler* imageRequestHandler = [[VNImageRequestHandler alloc] initWithCVPixelBuffer:fromImage options:
58 /// @
59 /// {}];
60 /// if (![imageRequestHandler performRequests:
61 /// @
62 /// [ request ] error:error])
63 /// {
64 /// return nil;
65 /// }
66 ///
67 /// imageRequestHandler = [[VNImageRequestHandler alloc] initWithCVPixelBuffer:toImage options:
68 /// @
69 /// {}];
70 /// if (![imageRequestHandler performRequests:
71 /// @
72 /// [ request ] error:error])
73 /// {
74 /// return nil;
75 /// }
76 ///
77 /// return [[request results] firstObject];
78 /// }
79 ///
80 /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vntrackopticalflowrequest?language=objc)
81 #[unsafe(super(VNStatefulRequest, VNImageBasedRequest, VNRequest, NSObject))]
82 #[derive(Debug, PartialEq, Eq, Hash)]
83 #[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
84 pub struct VNTrackOpticalFlowRequest;
85);
86
87#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
88extern_conformance!(
89 unsafe impl NSCopying for VNTrackOpticalFlowRequest {}
90);
91
92#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
93unsafe impl CopyingHelper for VNTrackOpticalFlowRequest {
94 type Result = Self;
95}
96
97#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
98extern_conformance!(
99 unsafe impl NSObjectProtocol for VNTrackOpticalFlowRequest {}
100);
101
102#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
103impl VNTrackOpticalFlowRequest {
104 extern_methods!(
105 /// Create a new request that can statefully track the optical from from one image to another.
106 ///
107 /// This is a convenience initializer for a frame analysis spacing of kCMTimeZero and a nil completion handler.
108 #[unsafe(method(init))]
109 #[unsafe(method_family = init)]
110 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
111
112 #[cfg(feature = "block2")]
113 /// Create a new request that can statefully track the optical from from one image to another.
114 ///
115 /// This is a convenience initializer for a frame analysis spacing of kCMTimeZero.
116 #[unsafe(method(initWithCompletionHandler:))]
117 #[unsafe(method_family = init)]
118 pub unsafe fn initWithCompletionHandler(
119 this: Allocated<Self>,
120 completion_handler: VNRequestCompletionHandler,
121 ) -> Retained<Self>;
122
123 /// The level of accuracy used to compute the optical flow. Default is VNTrackOpticalFlowRequestComputationAccuracyMedium.
124 ///
125 /// The computational time typically trends with the accuracy level. This parameter allows for selective tuning by the client application.
126 #[unsafe(method(computationAccuracy))]
127 #[unsafe(method_family = none)]
128 pub unsafe fn computationAccuracy(&self) -> VNTrackOpticalFlowRequestComputationAccuracy;
129
130 /// Setter for [`computationAccuracy`][Self::computationAccuracy].
131 #[unsafe(method(setComputationAccuracy:))]
132 #[unsafe(method_family = none)]
133 pub unsafe fn setComputationAccuracy(
134 &self,
135 computation_accuracy: VNTrackOpticalFlowRequestComputationAccuracy,
136 );
137
138 /// Pixel format type of the output buffer. Valid values are `kCVPixelFormatType_TwoComponent32Float` and `kCVPixelFormatType_TwoComponent16Half`. Default is `kCVPixelFormatType_TwoComponent32Float`.
139 #[unsafe(method(outputPixelFormat))]
140 #[unsafe(method_family = none)]
141 pub unsafe fn outputPixelFormat(&self) -> OSType;
142
143 /// Setter for [`outputPixelFormat`][Self::outputPixelFormat].
144 #[unsafe(method(setOutputPixelFormat:))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn setOutputPixelFormat(&self, output_pixel_format: OSType);
147
148 /// Setting this to `YES` will keep the raw pixel buffer coming from the the ML network. The default is `NO`.
149 ///
150 /// When set to `YES`, the outputPixelFormat is ignored.
151 #[unsafe(method(keepNetworkOutput))]
152 #[unsafe(method_family = none)]
153 pub unsafe fn keepNetworkOutput(&self) -> bool;
154
155 /// Setter for [`keepNetworkOutput`][Self::keepNetworkOutput].
156 #[unsafe(method(setKeepNetworkOutput:))]
157 #[unsafe(method_family = none)]
158 pub unsafe fn setKeepNetworkOutput(&self, keep_network_output: bool);
159
160 #[cfg(feature = "VNObservation")]
161 /// VNPixelBufferObservation results.
162 #[unsafe(method(results))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn results(&self) -> Option<Retained<NSArray<VNPixelBufferObservation>>>;
165 );
166}
167
168/// Methods declared on superclass `VNStatefulRequest`.
169#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
170impl VNTrackOpticalFlowRequest {
171 extern_methods!(
172 #[unsafe(method(new))]
173 #[unsafe(method_family = new)]
174 pub unsafe fn new() -> Retained<Self>;
175
176 #[cfg(all(feature = "block2", feature = "objc2-core-media"))]
177 /// Create a new video-based stateful request.
178 ///
179 ///
180 /// Parameter `frameAnalysisSpacing`: The reciprocal of maximum rate at which buffers will be processed. The request will not process buffers that fall within the frameAnalysisSpacing after it has performed the analysis. The analysis is not done by wall time but by analysis of of the time stamps of the samplebuffers being processed.
181 ///
182 /// Parameter `completionHandler`: The block to be invoked after the request has completed its processing. The completion handler gets executed on the same dispatch queue as the request being executed.
183 #[unsafe(method(initWithFrameAnalysisSpacing:completionHandler:))]
184 #[unsafe(method_family = init)]
185 pub unsafe fn initWithFrameAnalysisSpacing_completionHandler(
186 this: Allocated<Self>,
187 frame_analysis_spacing: CMTime,
188 completion_handler: VNRequestCompletionHandler,
189 ) -> Retained<Self>;
190 );
191}
192
193/// [Apple's documentation](https://developer.apple.com/documentation/vision/vntrackopticalflowrequestrevision1?language=objc)
194pub static VNTrackOpticalFlowRequestRevision1: NSUInteger = 1;