objc2_vision/generated/
VNRecognizeTextRequest.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Text recognition level options to favor speed over recognition accuracy. The VNRequestTextRecognitionLevelAccurate is the default option used by VNRecognizeTextRequest.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequesttextrecognitionlevel?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct VNRequestTextRecognitionLevel(pub NSInteger);
17impl VNRequestTextRecognitionLevel {
18    #[doc(alias = "VNRequestTextRecognitionLevelAccurate")]
19    pub const Accurate: Self = Self(0);
20    #[doc(alias = "VNRequestTextRecognitionLevelFast")]
21    pub const Fast: Self = Self(1);
22}
23
24unsafe impl Encode for VNRequestTextRecognitionLevel {
25    const ENCODING: Encoding = NSInteger::ENCODING;
26}
27
28unsafe impl RefEncode for VNRequestTextRecognitionLevel {
29    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
30}
31
32extern_class!(
33    /// A request that will detect regions of text and recognize the containing text in an image.
34    ///
35    ///
36    /// This request will generate VNRecognizedTextObservation objects describing the locations of text and the actual text recognized.
37    ///
38    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequest?language=objc)
39    #[unsafe(super(VNImageBasedRequest, VNRequest, NSObject))]
40    #[derive(Debug, PartialEq, Eq, Hash)]
41    #[cfg(feature = "VNRequest")]
42    pub struct VNRecognizeTextRequest;
43);
44
45#[cfg(feature = "VNRequest")]
46extern_conformance!(
47    unsafe impl NSCopying for VNRecognizeTextRequest {}
48);
49
50#[cfg(feature = "VNRequest")]
51unsafe impl CopyingHelper for VNRecognizeTextRequest {
52    type Result = Self;
53}
54
55#[cfg(feature = "VNRequest")]
56extern_conformance!(
57    unsafe impl NSObjectProtocol for VNRecognizeTextRequest {}
58);
59
60#[cfg(feature = "VNRequest")]
61extern_conformance!(
62    unsafe impl VNRequestProgressProviding for VNRecognizeTextRequest {}
63);
64
65#[cfg(feature = "VNRequest")]
66impl VNRecognizeTextRequest {
67    extern_methods!(
68        /// Returns all the supported languages for a given text recognition level. Note that a language supported in one recognition level might not be available in another.
69        #[deprecated]
70        #[unsafe(method(supportedRecognitionLanguagesForTextRecognitionLevel:revision:error:_))]
71        #[unsafe(method_family = none)]
72        pub unsafe fn supportedRecognitionLanguagesForTextRecognitionLevel_revision_error(
73            recognition_level: VNRequestTextRecognitionLevel,
74            request_revision: NSUInteger,
75        ) -> Result<Retained<NSArray<NSString>>, Retained<NSError>>;
76
77        /// Obtain the collection of supported recognition languages.
78        ///
79        /// This method will return the collection of all possible language identifiers that are recognized by the target request based on its current state of configuration at the time of the call.
80        ///
81        ///
82        /// Parameter `error`: The address of the variable that will be populated with the error if the call fails.
83        ///
84        ///
85        /// Returns: The collection of language identifiers, or nil if a failure occurs.
86        #[unsafe(method(supportedRecognitionLanguagesAndReturnError:_))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn supportedRecognitionLanguagesAndReturnError(
89            &self,
90        ) -> Result<Retained<NSArray<NSString>>, Retained<NSError>>;
91
92        /// Specify the languages used for the detection. The order of the languages in the array defines the order in which languages will be used during the language processing.
93        /// The languages are specified as ISO language codes.
94        #[unsafe(method(recognitionLanguages))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn recognitionLanguages(&self) -> Retained<NSArray<NSString>>;
97
98        /// Setter for [`recognitionLanguages`][Self::recognitionLanguages].
99        ///
100        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
101        #[unsafe(method(setRecognitionLanguages:))]
102        #[unsafe(method_family = none)]
103        pub fn setRecognitionLanguages(&self, recognition_languages: &NSArray<NSString>);
104
105        /// An array of strings that will be used at the word recognition stage in addition to the recognition languages. The customWords list takes precedence over the standard lexicon.
106        #[unsafe(method(customWords))]
107        #[unsafe(method_family = none)]
108        pub fn customWords(&self) -> Retained<NSArray<NSString>>;
109
110        /// Setter for [`customWords`][Self::customWords].
111        ///
112        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
113        #[unsafe(method(setCustomWords:))]
114        #[unsafe(method_family = none)]
115        pub fn setCustomWords(&self, custom_words: &NSArray<NSString>);
116
117        /// The recognition level selects which techniques will be used during the text recognition. There are trade-offs between performance and accuracy.
118        #[unsafe(method(recognitionLevel))]
119        #[unsafe(method_family = none)]
120        pub fn recognitionLevel(&self) -> VNRequestTextRecognitionLevel;
121
122        /// Setter for [`recognitionLevel`][Self::recognitionLevel].
123        #[unsafe(method(setRecognitionLevel:))]
124        #[unsafe(method_family = none)]
125        pub fn setRecognitionLevel(&self, recognition_level: VNRequestTextRecognitionLevel);
126
127        /// Determines whether language correction should be applied during the recognition process. Disabling this will return the raw recognition results providing performance benefits but less accurate results.
128        #[unsafe(method(usesLanguageCorrection))]
129        #[unsafe(method_family = none)]
130        pub fn usesLanguageCorrection(&self) -> bool;
131
132        /// Setter for [`usesLanguageCorrection`][Self::usesLanguageCorrection].
133        #[unsafe(method(setUsesLanguageCorrection:))]
134        #[unsafe(method_family = none)]
135        pub fn setUsesLanguageCorrection(&self, uses_language_correction: bool);
136
137        /// Language detection will try to automatically identify the script/langauge during the detection and use the appropiate model for recognition and language correction. This can be particularly helpful, if the nature of the content is unkown and with this flag being set it will for instance determine if text is latin vs chinese so you don't have to pick the language model in the first case. But as the language correction cannot always guarantee the correct detection, it is advisable to set the languages, if you have domain knowledge of what language to expect. The default value is NO. Also note that this feature is only available since VNRecognizeTextRequestRevision3 and is a no-op before that.
138        #[unsafe(method(automaticallyDetectsLanguage))]
139        #[unsafe(method_family = none)]
140        pub fn automaticallyDetectsLanguage(&self) -> bool;
141
142        /// Setter for [`automaticallyDetectsLanguage`][Self::automaticallyDetectsLanguage].
143        #[unsafe(method(setAutomaticallyDetectsLanguage:))]
144        #[unsafe(method_family = none)]
145        pub fn setAutomaticallyDetectsLanguage(&self, automatically_detects_language: bool);
146
147        #[unsafe(method(minimumTextHeight))]
148        #[unsafe(method_family = none)]
149        pub fn minimumTextHeight(&self) -> c_float;
150
151        /// Setter for [`minimumTextHeight`][Self::minimumTextHeight].
152        #[unsafe(method(setMinimumTextHeight:))]
153        #[unsafe(method_family = none)]
154        pub fn setMinimumTextHeight(&self, minimum_text_height: c_float);
155
156        #[cfg(feature = "VNObservation")]
157        /// VNRecognizedTextObservation results.
158        #[unsafe(method(results))]
159        #[unsafe(method_family = none)]
160        pub fn results(&self) -> Option<Retained<NSArray<VNRecognizedTextObservation>>>;
161    );
162}
163
164/// Methods declared on superclass `VNRequest`.
165#[cfg(feature = "VNRequest")]
166impl VNRecognizeTextRequest {
167    extern_methods!(
168        /// Creates a new VNRequest with no completion handler.
169        #[unsafe(method(init))]
170        #[unsafe(method_family = init)]
171        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
172
173        #[cfg(feature = "block2")]
174        /// Creates a new VNRequest with an optional completion handler.
175        ///
176        ///
177        /// 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.
178        ///
179        /// # Safety
180        ///
181        /// `completion_handler` must be a valid pointer or null.
182        #[unsafe(method(initWithCompletionHandler:))]
183        #[unsafe(method_family = init)]
184        pub unsafe fn initWithCompletionHandler(
185            this: Allocated<Self>,
186            completion_handler: VNRequestCompletionHandler,
187        ) -> Retained<Self>;
188    );
189}
190
191/// Methods declared on superclass `NSObject`.
192#[cfg(feature = "VNRequest")]
193impl VNRecognizeTextRequest {
194    extern_methods!(
195        #[unsafe(method(new))]
196        #[unsafe(method_family = new)]
197        pub fn new() -> Retained<Self>;
198    );
199}
200
201#[cfg(feature = "VNRequest")]
202impl DefaultRetained for VNRecognizeTextRequest {
203    #[inline]
204    fn default_retained() -> Retained<Self> {
205        Self::new()
206    }
207}
208
209/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision1?language=objc)
210#[deprecated]
211pub static VNRecognizeTextRequestRevision1: NSUInteger = 1;
212
213/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision2?language=objc)
214#[deprecated]
215pub static VNRecognizeTextRequestRevision2: NSUInteger = 2;
216
217/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision3?language=objc)
218pub static VNRecognizeTextRequestRevision3: NSUInteger = 3;