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