在Vision Framework中获取VNTextObservation矩形的图像部分

时间:2017-08-17 11:57:01

标签: ios apple-vision

我能够在iOS 11中获取在视觉框架视频源中检测到的文本矩形,但我试图将视频的图像部分识别为文本或字符。有人可以提供帮助吗?

 func detectTextHandler(request: VNRequest, error: Error?) {
    guard let observations = request.results else {
        print("no result")
        return
    }

    let result = observations.map({$0 as? VNTextObservation})

    DispatchQueue.main.async() {
        self.imageView.layer.sublayers?.removeSubrange(1...)
        for region in result {
            guard let rg = region else {
                continue
            }

            self.highlightWord(box: rg)

            if let boxes = region?.characterBoxes {
                for characterBox in boxes {
                    self.highlightLetters(box: characterBox)
                }
            }
        }
    }
}

那么如何才能获得region?.characterBoxes

的图像部分

0 个答案:

没有答案