Swift/MLKit: 如何初始化TextRecognizer?

Swift/MLKit: how to initialize TextRecognizer?

我正在尝试在我的项目中使用 MLKit,但我无法初始化 TextRecognizer。我试过这个:

textRecognizer = TextRecognizer.textRecognizer()

给出警告:

'textRecognizer()' is deprecated: Please use textRecognizer(options:) instead

但是,当我尝试以这种方式初始化它时:

let options = CommonTextRecognizerOptions.init()
textRecognizer = TextRecognizer.textRecognizer(options: options)

我收到这个错误:

'init()' is unavailable

那我该怎么初始化呢?

感谢您的帮助

来自 documentation for CommonTextRecognizerOptions:

-init
Unavailable. Use the initializers in subclasses.

因此您需要使用 CommonTextRecognizerOptions 的子类。这是我的发现:

/// Configurations for a text recognizer for Latin-based languages.
TextRecognizerOptions()

/// Configurations for a text recognizer for Chinese and Latin-based languages.
ChineseTextRecognizerOptions()

/// Configurations for a text recognizer for Devanagari and Latin-based languages.
DevanagariTextRecognizerOptions()

/// Configurations for a text recognizer for Japanese and Latin-based languages.
JapaneseTextRecognizerOptions()

/// Configurations for a text recognizer for Korean and Latin-based languages.
KoreanTextRecognizerOptions()

你会像这样使用它:

let options = TextRecognizerOptions() /// same thing as `TextRecognizerOptions.init()`
textRecognizer = TextRecognizer.textRecognizer(options: options)