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        #[unsafe(method(setRecognitionLanguages:))]
100        #[unsafe(method_family = none)]
101        pub fn setRecognitionLanguages(&self, recognition_languages: &NSArray<NSString>);
102
103        /// 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.
104        #[unsafe(method(customWords))]
105        #[unsafe(method_family = none)]
106        pub fn customWords(&self) -> Retained<NSArray<NSString>>;
107
108        /// Setter for [`customWords`][Self::customWords].
109        #[unsafe(method(setCustomWords:))]
110        #[unsafe(method_family = none)]
111        pub fn setCustomWords(&self, custom_words: &NSArray<NSString>);
112
113        /// The recognition level selects which techniques will be used during the text recognition. There are trade-offs between performance and accuracy.
114        #[unsafe(method(recognitionLevel))]
115        #[unsafe(method_family = none)]
116        pub fn recognitionLevel(&self) -> VNRequestTextRecognitionLevel;
117
118        /// Setter for [`recognitionLevel`][Self::recognitionLevel].
119        #[unsafe(method(setRecognitionLevel:))]
120        #[unsafe(method_family = none)]
121        pub fn setRecognitionLevel(&self, recognition_level: VNRequestTextRecognitionLevel);
122
123        /// 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.
124        #[unsafe(method(usesLanguageCorrection))]
125        #[unsafe(method_family = none)]
126        pub fn usesLanguageCorrection(&self) -> bool;
127
128        /// Setter for [`usesLanguageCorrection`][Self::usesLanguageCorrection].
129        #[unsafe(method(setUsesLanguageCorrection:))]
130        #[unsafe(method_family = none)]
131        pub fn setUsesLanguageCorrection(&self, uses_language_correction: bool);
132
133        /// 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.
134        #[unsafe(method(automaticallyDetectsLanguage))]
135        #[unsafe(method_family = none)]
136        pub fn automaticallyDetectsLanguage(&self) -> bool;
137
138        /// Setter for [`automaticallyDetectsLanguage`][Self::automaticallyDetectsLanguage].
139        #[unsafe(method(setAutomaticallyDetectsLanguage:))]
140        #[unsafe(method_family = none)]
141        pub fn setAutomaticallyDetectsLanguage(&self, automatically_detects_language: bool);
142
143        #[unsafe(method(minimumTextHeight))]
144        #[unsafe(method_family = none)]
145        pub fn minimumTextHeight(&self) -> c_float;
146
147        /// Setter for [`minimumTextHeight`][Self::minimumTextHeight].
148        #[unsafe(method(setMinimumTextHeight:))]
149        #[unsafe(method_family = none)]
150        pub fn setMinimumTextHeight(&self, minimum_text_height: c_float);
151
152        #[cfg(feature = "VNObservation")]
153        /// VNRecognizedTextObservation results.
154        #[unsafe(method(results))]
155        #[unsafe(method_family = none)]
156        pub fn results(&self) -> Option<Retained<NSArray<VNRecognizedTextObservation>>>;
157    );
158}
159
160/// Methods declared on superclass `VNRequest`.
161#[cfg(feature = "VNRequest")]
162impl VNRecognizeTextRequest {
163    extern_methods!(
164        /// Creates a new VNRequest with no completion handler.
165        #[unsafe(method(init))]
166        #[unsafe(method_family = init)]
167        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
168
169        #[cfg(feature = "block2")]
170        /// Creates a new VNRequest with an optional completion handler.
171        ///
172        ///
173        /// 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.
174        #[unsafe(method(initWithCompletionHandler:))]
175        #[unsafe(method_family = init)]
176        pub unsafe fn initWithCompletionHandler(
177            this: Allocated<Self>,
178            completion_handler: VNRequestCompletionHandler,
179        ) -> Retained<Self>;
180    );
181}
182
183/// Methods declared on superclass `NSObject`.
184#[cfg(feature = "VNRequest")]
185impl VNRecognizeTextRequest {
186    extern_methods!(
187        #[unsafe(method(new))]
188        #[unsafe(method_family = new)]
189        pub fn new() -> Retained<Self>;
190    );
191}
192
193#[cfg(feature = "VNRequest")]
194impl DefaultRetained for VNRecognizeTextRequest {
195    #[inline]
196    fn default_retained() -> Retained<Self> {
197        Self::new()
198    }
199}
200
201/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision1?language=objc)
202pub static VNRecognizeTextRequestRevision1: NSUInteger = 1;
203
204/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision2?language=objc)
205pub static VNRecognizeTextRequestRevision2: NSUInteger = 2;
206
207/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision3?language=objc)
208pub static VNRecognizeTextRequestRevision3: NSUInteger = 3;