【发布时间】:2018-05-09 06:27:47
【问题描述】:
我正在尝试使用 Firebase MLKit 对我的图像进行 OCR,但它失败并返回错误
文本检测失败并出现错误:无法运行文本检测器,因为 self 为 nil。
/// Detects texts on the specified image and draws a frame for them.
func detectTexts() {
let image = #imageLiteral(resourceName: "testocr")
// Create a text detector.
let textDetector = vision.textDetector() // Check console for errors.
// Initialize a VisionImage with a UIImage.
let visionImage = VisionImage(image: image)
textDetector.detect(in: visionImage) { (features, error) in
guard error == nil, let features = features, !features.isEmpty else {
let errorString = error?.localizedDescription ?? "No results returned."
print("Text detection failed with error: \(errorString)")
return
}
// Recognized and extracted text
print("Detected text has: \(features.count) blocks")
let resultText = features.map { feature in
return "Text: \(feature.text)"
}.joined(separator: "\n")
print(resultText)
}
}
【问题讨论】:
-
在投反对票之前请帮助我或让我知道出了什么问题。
-
我没有看到
vision是在哪里声明的,但我希望你不要忘记声明它:lazy var vision = Vision.vision() -
您好,您解决了吗?我得到了同样的错误
标签: ios swift firebase firebase-mlkit