2017-09-05 81 views
0

我使用Vision检测文本并且它工作正常当检测到某些东西并调用某个功能时,但它仍在使用完成,但文本仍在检测中。停止检测Apple Vision,iOS,Swift中的字母

如何停止的文本检测

要启动它,我使用:

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 
    } 
+0

“stop”是什么意思?该请求将一直运行,直到完成对资产(图像,视频等)的分析。你不能暂停/恢复它的进度。 – nathan

+0

当检测到文本时,会出现启动文本检测,我称之为函数我希望文本检测在调用此函数的同时停止运行。我不想暂停它,我希望它停止完全检测 –

+0

几个问题。首先,我们是在说一个单一的图像或其他东西的来源?其次,“停止”文本检测的目标是什么?像@nathan一样,我很困惑。如果您拍摄*单张*图片并使用视觉*检测*中的文字,则显然是“全部或全部”。你所做的* *取决于你。我感觉到这个问题是我们不明白的。 – dfd

回答

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 
    } 
}