【发布时间】:2018-06-16 01:25:37
【问题描述】:
我想使用 Vision 框架中的 VNDetectTextRectanglesRequest 来检测图像中的区域,该图像仅包含一个字符,数字“9”,背景为白色。我正在使用以下代码来执行此操作:
private func performTextDetection() {
let textRequest = VNDetectTextRectanglesRequest(completionHandler: self.detectTextHandler)
textRequest.reportCharacterBoxes = true
textRequest.preferBackgroundProcessing = false
let handler = VNImageRequestHandler(cgImage: loadedImage.cgImage!, options: [:])
DispatchQueue.global(qos: .userInteractive).async {
do {
try handler.perform([textRequest])
} catch {
print ("Error")
}
}
}
func detectTextHandler(request: VNRequest, error: Error?) {
guard let observations = request.results, !observations.isEmpty else {
fatalError("no results")
}
print("there is result")
}
我得到的观察结果数为 0,但是如果我在黑色背景上提供带有文本“123”的图像,则“123”被检测为带有文本的区域。所描述的问题也会出现在 2 位数字上,白色背景上的“22”也不会被检测到。
在我的情况下,为什么 Vision API 只能检测到白色背景上的 3 位数字+数字?
【问题讨论】:
-
好问题,我也有同样的问题。
-
我遇到了类似的问题。它还有待解决。 stackoverflow.com/questions/54282757/…
-
单个字符在占用更多空间时往往会更好地阅读。即使单个字符的字体大小比包含多个字符的文本大,当单个字符变大时也会为我阅读。只是一个猜测:对于单个字符,没有足够的边缘(或匹配的边缘,可能像笔画宽度变换的输出)来说服 OCR 算法存在字符。
标签: swift machine-learning mobile ocr apple-vision