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"))]
88unsafe impl NSCopying for VNTrackOpticalFlowRequest {}
89
90#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
91unsafe impl CopyingHelper for VNTrackOpticalFlowRequest {
92 type Result = Self;
93}
94
95#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
96unsafe impl NSObjectProtocol for VNTrackOpticalFlowRequest {}
97
98#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
99impl VNTrackOpticalFlowRequest {
100 extern_methods!(
101 /// Create a new request that can statefully track the optical from from one image to another.
102 ///
103 /// This is a convenience initializer for a frame analysis spacing of kCMTimeZero and a nil completion handler.
104 #[unsafe(method(init))]
105 #[unsafe(method_family = init)]
106 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
107
108 #[cfg(feature = "block2")]
109 /// Create a new request that can statefully track the optical from from one image to another.
110 ///
111 /// This is a convenience initializer for a frame analysis spacing of kCMTimeZero.
112 #[unsafe(method(initWithCompletionHandler:))]
113 #[unsafe(method_family = init)]
114 pub unsafe fn initWithCompletionHandler(
115 this: Allocated<Self>,
116 completion_handler: VNRequestCompletionHandler,
117 ) -> Retained<Self>;
118
119 /// The level of accuracy used to compute the optical flow. Default is VNTrackOpticalFlowRequestComputationAccuracyMedium.
120 ///
121 /// The computational time typically trends with the accuracy level. This parameter allows for selective tuning by the client application.
122 #[unsafe(method(computationAccuracy))]
123 #[unsafe(method_family = none)]
124 pub unsafe fn computationAccuracy(&self) -> VNTrackOpticalFlowRequestComputationAccuracy;
125
126 /// Setter for [`computationAccuracy`][Self::computationAccuracy].
127 #[unsafe(method(setComputationAccuracy:))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn setComputationAccuracy(
130 &self,
131 computation_accuracy: VNTrackOpticalFlowRequestComputationAccuracy,
132 );
133
134 /// Pixel format type of the output buffer. Valid values are `kCVPixelFormatType_TwoComponent32Float` and `kCVPixelFormatType_TwoComponent16Half`. Default is `kCVPixelFormatType_TwoComponent32Float`.
135 #[unsafe(method(outputPixelFormat))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn outputPixelFormat(&self) -> OSType;
138
139 /// Setter for [`outputPixelFormat`][Self::outputPixelFormat].
140 #[unsafe(method(setOutputPixelFormat:))]
141 #[unsafe(method_family = none)]
142 pub unsafe fn setOutputPixelFormat(&self, output_pixel_format: OSType);
143
144 /// Setting this to `YES` will keep the raw pixel buffer coming from the the ML network. The default is `NO`.
145 ///
146 /// When set to `YES`, the outputPixelFormat is ignored.
147 #[unsafe(method(keepNetworkOutput))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn keepNetworkOutput(&self) -> bool;
150
151 /// Setter for [`keepNetworkOutput`][Self::keepNetworkOutput].
152 #[unsafe(method(setKeepNetworkOutput:))]
153 #[unsafe(method_family = none)]
154 pub unsafe fn setKeepNetworkOutput(&self, keep_network_output: bool);
155
156 #[cfg(feature = "VNObservation")]
157 /// VNPixelBufferObservation results.
158 #[unsafe(method(results))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn results(&self) -> Option<Retained<NSArray<VNPixelBufferObservation>>>;
161 );
162}
163
164/// Methods declared on superclass `VNStatefulRequest`.
165#[cfg(all(feature = "VNRequest", feature = "VNStatefulRequest"))]
166impl VNTrackOpticalFlowRequest {
167 extern_methods!(
168 #[unsafe(method(new))]
169 #[unsafe(method_family = new)]
170 pub unsafe fn new() -> Retained<Self>;
171
172 #[cfg(all(feature = "block2", feature = "objc2-core-media"))]
173 /// Create a new video-based stateful request.
174 ///
175 ///
176 /// 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.
177 ///
178 /// 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.
179 #[unsafe(method(initWithFrameAnalysisSpacing:completionHandler:))]
180 #[unsafe(method_family = init)]
181 pub unsafe fn initWithFrameAnalysisSpacing_completionHandler(
182 this: Allocated<Self>,
183 frame_analysis_spacing: CMTime,
184 completion_handler: VNRequestCompletionHandler,
185 ) -> Retained<Self>;
186 );
187}
188
189/// [Apple's documentation](https://developer.apple.com/documentation/vision/vntrackopticalflowrequestrevision1?language=objc)
190pub static VNTrackOpticalFlowRequestRevision1: NSUInteger = 1;