objc2-vision 0.3.2

Bindings to the Vision framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-ml")]
use objc2_core_ml::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// The VNCoreMLModel uses an CoreML based model and prepares it for use with VNCoreMLRequests.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlmodel?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct VNCoreMLModel;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for VNCoreMLModel {}
);

impl VNCoreMLModel {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "objc2-core-ml")]
        /// 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.
        ///
        ///
        /// Parameter `model`: The MLModel from CoreML to be used.
        ///
        ///
        /// Parameter `error`: Returns the error code and description, if the model is not supported.
        #[unsafe(method(modelForMLModel:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn modelForMLModel_error(
            model: &MLModel,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// 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.
        #[unsafe(method(inputImageFeatureName))]
        #[unsafe(method_family = none)]
        pub unsafe fn inputImageFeatureName(&self) -> Retained<NSString>;

        /// Setter for [`inputImageFeatureName`][Self::inputImageFeatureName].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setInputImageFeatureName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setInputImageFeatureName(&self, input_image_feature_name: &NSString);

        #[cfg(feature = "objc2-core-ml")]
        /// 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.
        #[unsafe(method(featureProvider))]
        #[unsafe(method_family = none)]
        pub unsafe fn featureProvider(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn MLFeatureProvider>>>;

        #[cfg(feature = "objc2-core-ml")]
        /// Setter for [`featureProvider`][Self::featureProvider].
        #[unsafe(method(setFeatureProvider:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFeatureProvider(
            &self,
            feature_provider: Option<&ProtocolObject<dyn MLFeatureProvider>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl VNCoreMLModel {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// 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
    /// 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
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequest?language=objc)
    #[unsafe(super(VNImageBasedRequest, VNRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "VNRequest")]
    pub struct VNCoreMLRequest;
);

#[cfg(feature = "VNRequest")]
extern_conformance!(
    unsafe impl NSCopying for VNCoreMLRequest {}
);

#[cfg(feature = "VNRequest")]
unsafe impl CopyingHelper for VNCoreMLRequest {
    type Result = Self;
}

#[cfg(feature = "VNRequest")]
extern_conformance!(
    unsafe impl NSObjectProtocol for VNCoreMLRequest {}
);

#[cfg(feature = "VNRequest")]
impl VNCoreMLRequest {
    extern_methods!(
        /// The model from CoreML wrapped in a VNCoreMLModel.
        #[unsafe(method(model))]
        #[unsafe(method_family = none)]
        pub unsafe fn model(&self) -> Retained<VNCoreMLModel>;

        #[cfg(feature = "VNTypes")]
        #[unsafe(method(imageCropAndScaleOption))]
        #[unsafe(method_family = none)]
        pub unsafe fn imageCropAndScaleOption(&self) -> VNImageCropAndScaleOption;

        #[cfg(feature = "VNTypes")]
        /// Setter for [`imageCropAndScaleOption`][Self::imageCropAndScaleOption].
        #[unsafe(method(setImageCropAndScaleOption:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setImageCropAndScaleOption(
            &self,
            image_crop_and_scale_option: VNImageCropAndScaleOption,
        );

        /// Create a new request with a model.
        ///
        ///
        /// Parameter `model`: The VNCoreMLModel to be used.
        #[unsafe(method(initWithModel:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithModel(this: Allocated<Self>, model: &VNCoreMLModel)
            -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// Create a new request with a model.
        ///
        ///
        /// Parameter `model`: The VNCoreMLModel to be used.
        ///
        ///
        /// Parameter `completionHandler`: The block that is invoked when the request has been performed.
        ///
        /// # Safety
        ///
        /// `completion_handler` must be a valid pointer or null.
        #[unsafe(method(initWithModel:completionHandler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithModel_completionHandler(
            this: Allocated<Self>,
            model: &VNCoreMLModel,
            completion_handler: VNRequestCompletionHandler,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// # Safety
        ///
        /// `completion_handler` must be a valid pointer or null.
        #[unsafe(method(initWithCompletionHandler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCompletionHandler(
            this: Allocated<Self>,
            completion_handler: VNRequestCompletionHandler,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "VNRequest")]
impl VNCoreMLRequest {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/vision/vncoremlrequestrevision1?language=objc)
pub static VNCoreMLRequestRevision1: NSUInteger = 1;