0

我正在使用 Vision 检测文本,它工作正常我让它在检测到某些东西并调用函数时使用完成,但仍在检测到文本。

如何停止文本检测

要开始它,我正在使用:

func startTextDetection() {
    let textRequest = VNDetectTextRectanglesRequest(completionHandler: self.detectTextHandler)
    textRequest.reportCharacterBoxes = true
    self.requests = [textRequest]

}

// I tried this to stop it but it only hides the boxes around the text.
//func stopTextDetection() {
//  let textRequest = VNDetectTextRectanglesRequest(completionHandler: //self.detectTextHandler)
//  textRequest.reportCharacterBoxes = false
//  self.requests = [textRequest]
//}

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

1 回答 1

0

我能够通过添加以下函数来解决这个问题,并在检测到时调用它。

func stopTextDetection() {
    let textRequest = VNDetectTextRectanglesRequest(completionHandler: self.detectTextHandlerStop)
    textRequest.reportCharacterBoxes = false
    self.requests = [textRequest]


}

func detectTextHandlerStop(request: VNRequest, error: Error?) {
    guard request.completionHandler != nil else {
        print("no result")
        return
    }
}
于 2017-09-06T14:55:12.290 回答