swift/MLKit : how to initialize TextRecognizer?

标签 swift google-mlkit

我尝试在项目中使用 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对于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)

关于 swift/MLKit : how to initialize TextRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69091888/

相关文章:

android - 谷歌机器学习套件 : couldn't find "libbarhopper_v2.so"

cocoa - fatal error : unexpectedly found nil while unwrapping an Optional value in Swift when tried to parse JSON

ios - 按特定字段截断 firebase 项目

java - MLKit 对象检测未检测到对象

ios - Firebase MLKit 迁移 - 架构 x86_64 的 undefined symbol

android - `suspendCoroutine`抛出`This job has not completed yet`异常?

swift - 在不重复的情况下选择位图中每个像素的公式

ios - 如何在适用于 iOS 的 Google Material Design 上禁用水平滚动到选项卡

swift - 避免处理所有异常,直到它们到达全局处理程序

android - 无法在叠加 Surfaceview 上的正确位置获得条形码边界框