Vision Framework Accessing Text as String

Does Vision API in iOS 11 have the ability to return the actual text as string which it is detecting.


    let textDetectionRequest = VNDetectTextRectanglesRequest(completionHandler: {(request, error) in
           
            guard let observations = request.results as? [VNTextObservation]
                else { fatalError("unexpected result type from VNDetectTextRectanglesRequest") }
           
            for observation in observations {
               
                for characterBox in observation.characterBoxes! {
                    print(characterBox)
                }
            }
           
        })
       
        textDetectionRequest.reportCharacterBoxes = true
       
        let handler = VNImageRequestHandler(cgImage: textImage.cgImage!, options: [:])
       
        guard let _ = try? handler.perform([textDetectionRequest]) else {
            return print("Could not perform text Detection Request!")
        }


Also looks like it only detect strings and not numbers. This means if the image contains 5,6 or any number it will NOT detect that.

Replies

i've tried to use your code but i can't print the text detected. Can you explain better how can I access text as String?