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
21unsafe impl NSObjectProtocol for VNCoreMLModel {}
22
23impl VNCoreMLModel {
24    extern_methods!(
25        #[unsafe(method(init))]
26        #[unsafe(method_family = init)]
27        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
28
29        #[cfg(feature = "objc2-core-ml")]
30        /// 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.
31        ///
32        ///
33        /// Parameter `model`: The MLModel from CoreML to be used.
34        ///
35        ///
36        /// Parameter `error`: Returns the error code and description, if the model is not supported.
37        #[unsafe(method(modelForMLModel:error:_))]
38        #[unsafe(method_family = none)]
39        pub unsafe fn modelForMLModel_error(
40            model: &MLModel,
41        ) -> Result<Retained<Self>, Retained<NSError>>;
42
43        /// 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.
44        #[unsafe(method(inputImageFeatureName))]
45        #[unsafe(method_family = none)]
46        pub unsafe fn inputImageFeatureName(&self) -> Retained<NSString>;
47
48        /// Setter for [`inputImageFeatureName`][Self::inputImageFeatureName].
49        #[unsafe(method(setInputImageFeatureName:))]
50        #[unsafe(method_family = none)]
51        pub unsafe fn setInputImageFeatureName(&self, input_image_feature_name: &NSString);
52
53        #[cfg(feature = "objc2-core-ml")]
54        /// 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.
55        #[unsafe(method(featureProvider))]
56        #[unsafe(method_family = none)]
57        pub unsafe fn featureProvider(
58            &self,
59        ) -> Option<Retained<ProtocolObject<dyn MLFeatureProvider>>>;
60
61        #[cfg(feature = "objc2-core-ml")]
62        /// Setter for [`featureProvider`][Self::featureProvider].
63        #[unsafe(method(setFeatureProvider:))]
64        #[unsafe(method_family = none)]
65        pub unsafe fn setFeatureProvider(
66            &self,
67            feature_provider: Option<&ProtocolObject<dyn MLFeatureProvider>>,
68        );
69    );
70}
71
72/// Methods declared on superclass `NSObject`.
73impl VNCoreMLModel {
74    extern_methods!(
75        #[unsafe(method(new))]
76        #[unsafe(method_family = new)]
77        pub unsafe fn new() -> Retained<Self>;
78    );
79}
80
81extern_class!(
82    /// 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
83    /// 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
84    ///
85    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequest?language=objc)
86    #[unsafe(super(VNImageBasedRequest, VNRequest, NSObject))]
87    #[derive(Debug, PartialEq, Eq, Hash)]
88    #[cfg(feature = "VNRequest")]
89    pub struct VNCoreMLRequest;
90);
91
92#[cfg(feature = "VNRequest")]
93unsafe impl NSCopying for VNCoreMLRequest {}
94
95#[cfg(feature = "VNRequest")]
96unsafe impl CopyingHelper for VNCoreMLRequest {
97    type Result = Self;
98}
99
100#[cfg(feature = "VNRequest")]
101unsafe impl NSObjectProtocol for VNCoreMLRequest {}
102
103#[cfg(feature = "VNRequest")]
104impl VNCoreMLRequest {
105    extern_methods!(
106        /// The model from CoreML wrapped in a VNCoreMLModel.
107        #[unsafe(method(model))]
108        #[unsafe(method_family = none)]
109        pub unsafe fn model(&self) -> Retained<VNCoreMLModel>;
110
111        #[cfg(feature = "VNTypes")]
112        #[unsafe(method(imageCropAndScaleOption))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn imageCropAndScaleOption(&self) -> VNImageCropAndScaleOption;
115
116        #[cfg(feature = "VNTypes")]
117        /// Setter for [`imageCropAndScaleOption`][Self::imageCropAndScaleOption].
118        #[unsafe(method(setImageCropAndScaleOption:))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn setImageCropAndScaleOption(
121            &self,
122            image_crop_and_scale_option: VNImageCropAndScaleOption,
123        );
124
125        /// Create a new request with a model.
126        ///
127        ///
128        /// Parameter `model`: The VNCoreMLModel to be used.
129        #[unsafe(method(initWithModel:))]
130        #[unsafe(method_family = init)]
131        pub unsafe fn initWithModel(this: Allocated<Self>, model: &VNCoreMLModel)
132            -> Retained<Self>;
133
134        #[cfg(feature = "block2")]
135        /// Create a new request with a model.
136        ///
137        ///
138        /// Parameter `model`: The VNCoreMLModel to be used.
139        ///
140        ///
141        /// Parameter `completionHandler`: The block that is invoked when the request has been performed.
142        #[unsafe(method(initWithModel:completionHandler:))]
143        #[unsafe(method_family = init)]
144        pub unsafe fn initWithModel_completionHandler(
145            this: Allocated<Self>,
146            model: &VNCoreMLModel,
147            completion_handler: VNRequestCompletionHandler,
148        ) -> Retained<Self>;
149
150        #[unsafe(method(init))]
151        #[unsafe(method_family = init)]
152        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
153
154        #[cfg(feature = "block2")]
155        #[unsafe(method(initWithCompletionHandler:))]
156        #[unsafe(method_family = init)]
157        pub unsafe fn initWithCompletionHandler(
158            this: Allocated<Self>,
159            completion_handler: VNRequestCompletionHandler,
160        ) -> Retained<Self>;
161    );
162}
163
164/// Methods declared on superclass `NSObject`.
165#[cfg(feature = "VNRequest")]
166impl VNCoreMLRequest {
167    extern_methods!(
168        #[unsafe(method(new))]
169        #[unsafe(method_family = new)]
170        pub unsafe fn new() -> Retained<Self>;
171    );
172}
173
174/// [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequestrevision1?language=objc)
175pub static VNCoreMLRequestRevision1: NSUInteger = 1;