objc2_vision/generated/
VNCoreMLRequest.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-ml")]
7use objc2_core_ml::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13    /// The VNCoreMLModel uses an CoreML based model and prepares it for use with VNCoreMLRequests.
14    ///
15    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlmodel?language=objc)
16    #[unsafe(super(NSObject))]
17    #[derive(Debug, PartialEq, Eq, Hash)]
18    pub struct VNCoreMLModel;
19);
20
21extern_conformance!(
22    unsafe impl NSObjectProtocol for VNCoreMLModel {}
23);
24
25impl VNCoreMLModel {
26    extern_methods!(
27        #[unsafe(method(init))]
28        #[unsafe(method_family = init)]
29        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
30
31        #[cfg(feature = "objc2-core-ml")]
32        /// Create a model container to be used with VNCoreMLRequest based on a Core ML model. This can fail if the model is not supported. Examples for a model that is not supported is a model that does not take an image as any of its inputs.
33        ///
34        ///
35        /// Parameter `model`: The MLModel from CoreML to be used.
36        ///
37        ///
38        /// Parameter `error`: Returns the error code and description, if the model is not supported.
39        #[unsafe(method(modelForMLModel:error:_))]
40        #[unsafe(method_family = none)]
41        pub unsafe fn modelForMLModel_error(
42            model: &MLModel,
43        ) -> Result<Retained<Self>, Retained<NSError>>;
44
45        /// The name of the MLFeatureValue that Vision will set from the VNRequestHandler. Vision will use the first input it finds by default but it can be set to another featureName instead.
46        #[unsafe(method(inputImageFeatureName))]
47        #[unsafe(method_family = none)]
48        pub unsafe fn inputImageFeatureName(&self) -> Retained<NSString>;
49
50        /// Setter for [`inputImageFeatureName`][Self::inputImageFeatureName].
51        ///
52        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
53        #[unsafe(method(setInputImageFeatureName:))]
54        #[unsafe(method_family = none)]
55        pub unsafe fn setInputImageFeatureName(&self, input_image_feature_name: &NSString);
56
57        #[cfg(feature = "objc2-core-ml")]
58        /// An optional object conforming to the MLFeatureProvider protocol that is used by the model during the predict call to support inputs that are not supplied by Vision. Vision will provide the image for the inputImageFeatureName from the the VNRequestHandler. A feature provider is necessary for models that have more than one input and require those parameters to be set. Models that only have one image input will not use the feature provider as that input will be set by Vision.
59        #[unsafe(method(featureProvider))]
60        #[unsafe(method_family = none)]
61        pub unsafe fn featureProvider(
62            &self,
63        ) -> Option<Retained<ProtocolObject<dyn MLFeatureProvider>>>;
64
65        #[cfg(feature = "objc2-core-ml")]
66        /// Setter for [`featureProvider`][Self::featureProvider].
67        #[unsafe(method(setFeatureProvider:))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn setFeatureProvider(
70            &self,
71            feature_provider: Option<&ProtocolObject<dyn MLFeatureProvider>>,
72        );
73    );
74}
75
76/// Methods declared on superclass `NSObject`.
77impl VNCoreMLModel {
78    extern_methods!(
79        #[unsafe(method(new))]
80        #[unsafe(method_family = new)]
81        pub unsafe fn new() -> Retained<Self>;
82    );
83}
84
85extern_class!(
86    /// The VNCoreMLRequest uses a VNCoreMLModel, that is based on a CoreML MLModel object, to run predictions with that model. Depending on the model the returned
87    /// observation is either a VNClassificationObservation for classifier models, VNPixelBufferObservations for image-to-image models, VNRecognizedObjectObservation for object recognition models or VNCoreMLFeatureValueObservation for everything else. All -[VNObservation confidence] values are forwarded from relevant models as is, and do not conform to a common [0, 1] range rule
88    ///
89    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequest?language=objc)
90    #[unsafe(super(VNImageBasedRequest, VNRequest, NSObject))]
91    #[derive(Debug, PartialEq, Eq, Hash)]
92    #[cfg(feature = "VNRequest")]
93    pub struct VNCoreMLRequest;
94);
95
96#[cfg(feature = "VNRequest")]
97extern_conformance!(
98    unsafe impl NSCopying for VNCoreMLRequest {}
99);
100
101#[cfg(feature = "VNRequest")]
102unsafe impl CopyingHelper for VNCoreMLRequest {
103    type Result = Self;
104}
105
106#[cfg(feature = "VNRequest")]
107extern_conformance!(
108    unsafe impl NSObjectProtocol for VNCoreMLRequest {}
109);
110
111#[cfg(feature = "VNRequest")]
112impl VNCoreMLRequest {
113    extern_methods!(
114        /// The model from CoreML wrapped in a VNCoreMLModel.
115        #[unsafe(method(model))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn model(&self) -> Retained<VNCoreMLModel>;
118
119        #[cfg(feature = "VNTypes")]
120        #[unsafe(method(imageCropAndScaleOption))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn imageCropAndScaleOption(&self) -> VNImageCropAndScaleOption;
123
124        #[cfg(feature = "VNTypes")]
125        /// Setter for [`imageCropAndScaleOption`][Self::imageCropAndScaleOption].
126        #[unsafe(method(setImageCropAndScaleOption:))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn setImageCropAndScaleOption(
129            &self,
130            image_crop_and_scale_option: VNImageCropAndScaleOption,
131        );
132
133        /// Create a new request with a model.
134        ///
135        ///
136        /// Parameter `model`: The VNCoreMLModel to be used.
137        #[unsafe(method(initWithModel:))]
138        #[unsafe(method_family = init)]
139        pub unsafe fn initWithModel(this: Allocated<Self>, model: &VNCoreMLModel)
140            -> Retained<Self>;
141
142        #[cfg(feature = "block2")]
143        /// Create a new request with a model.
144        ///
145        ///
146        /// Parameter `model`: The VNCoreMLModel to be used.
147        ///
148        ///
149        /// Parameter `completionHandler`: The block that is invoked when the request has been performed.
150        ///
151        /// # Safety
152        ///
153        /// `completion_handler` must be a valid pointer or null.
154        #[unsafe(method(initWithModel:completionHandler:))]
155        #[unsafe(method_family = init)]
156        pub unsafe fn initWithModel_completionHandler(
157            this: Allocated<Self>,
158            model: &VNCoreMLModel,
159            completion_handler: VNRequestCompletionHandler,
160        ) -> Retained<Self>;
161
162        #[unsafe(method(init))]
163        #[unsafe(method_family = init)]
164        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
165
166        #[cfg(feature = "block2")]
167        /// # Safety
168        ///
169        /// `completion_handler` must be a valid pointer or null.
170        #[unsafe(method(initWithCompletionHandler:))]
171        #[unsafe(method_family = init)]
172        pub unsafe fn initWithCompletionHandler(
173            this: Allocated<Self>,
174            completion_handler: VNRequestCompletionHandler,
175        ) -> Retained<Self>;
176    );
177}
178
179/// Methods declared on superclass `NSObject`.
180#[cfg(feature = "VNRequest")]
181impl VNCoreMLRequest {
182    extern_methods!(
183        #[unsafe(method(new))]
184        #[unsafe(method_family = new)]
185        pub unsafe fn new() -> Retained<Self>;
186    );
187}
188
189/// [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequestrevision1?language=objc)
190pub static VNCoreMLRequestRevision1: NSUInteger = 1;