问题
I want to use VNDetectTextRectanglesRequest
from a Vision framework to detect regions in an image containing only one character, number '9', with the white background. I'm using following code to do this:
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")
}
Number of observations results I get is 0, however if I provide an image with text '123' on black background, '123' is detected as a region with text. The described problem also occurs for 2 digit numbers, '22' on white background also doesn't get detected.
Why does a Vision API detect only 3 digits+ numbers on white background in my case?
来源:https://stackoverflow.com/questions/48127045/vision-vndetecttextrectanglesrequest-cant-recognize-single-number-as-region