0

I am detecting text with Vision and it is working ok I have it use a completion when something detected and call a function, but the text is still being detected.

How can I stop the text detection

To start it i am using:

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
    }
Tony Merritt
  • 1,177
  • 11
  • 35
  • What do you mean by "stop" ? The request will run until the asset (image, video, etc.) is analyzed completely. You can't pause/resume it's progress. – nathan Sep 05 '17 at 20:53
  • there is a start text detection when it detects text i call a function I want the text detection to stop running at the same time the function is called. i don't want to pause it, I want it to stop totally detecting – Tony Merritt Sep 05 '17 at 20:54
  • A few questions. First, are we talking a source of a single image or something else? Second, what is the goal of "stopping" text detection? Like @nathan, I'm confused. If you take a *single* image and use Vision to *detect* the text in it, it's obviously "all or nothing". What you do with *that* is up to you. I'm sensing that the issue is something we don't understand. –  Sep 05 '17 at 21:55
  • One more note. For text detection (and much more) remember that the Vision Framework is actually something of a "wrapper" around CoreML, which *itself* is simply a specific implementation of Machine Learning (ML). For images, that means both (a) post processing of sorts and (b) I guess full processing. Vision will detect *all* of the text it's able to - based on the ML or CoreML model used and trained/imported. It can (and should) have a probability threshold also. Thus, it's up to *you* to process that output - once it's done. So please, what's your concept of "stopping" mean? –  Sep 05 '17 at 22:00
  • Thank you for your time on this. I have a preview layer that detects text when the detection shows a set number of boxes on screen it calls a function all this works but the text detection carries on detecting so keeps calling he function. I’m not detecting on a single image but a live video feed. – Tony Merritt Sep 05 '17 at 22:06

1 Answers1

0

I was able to figure this out by adding the following functions and call it when detection is reached.

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
    }
}
Tony Merritt
  • 1,177
  • 11
  • 35