0

I want to extracted the selected text from image.

What I am doing right now.

Step 1: Capture the image using camera.

Step 2: Creating cgImage of captured image as following

     guard let cgImage = caputuredImage.cgImage else { return }

Step 3: Processing above image in the following Vision framework code snippet:

        //Hanlder
        let handler = VNImageRequestHandler(cgImage: cgImage, options: [:])
        
        //Request
        let request = VNRecognizeTextRequest { request, error in
            guard let observation = request.results as? [VNRecognizedTextObservation], error == nil else {
                return
            }
            
            let text = observation.compactMap({
                $0.topCandidates(1).first?.string
            }).joined(separator: " ")
           
            print(text) // here I got the extracted text from image.
            
            self.extractedTextView.text = text
        }
        
        //Process Request
        do {
            try handler.perform([request])
        } catch {
            
            Debug.log(message: "Failed to perform request with error: ", variable: error.localizedDescription)
        }

I have got the extracted text, but I don't want like above steps.

What I want now is:
Step 1: Capture picture from camera of some textbook page.
Step 2: Select portion of text from that picture, and then only that selected text should be extracted like we do in google lens.

An example question of stack overflow is here, but this is in flutter. I want that in swift or in objective c.

Any help would be appreciated.

Aafaq
  • 202
  • 1
  • 13
  • It's not clear what you're asking. Tip: when you post a question, don't say *"like we do in [some other app]"* or *"like some other code in some other answer"*. Describe exactly what you want to do. If you're talking about allowing the user to drag to draw a rect around the recognized text, then the `VNRecognizedTextObservation` object has a `.boundingBox` property (coordinates in percentages) that you can use. – DonMag Jan 17 '22 at 22:10
  • Hey man, I am new here. Thanks for your tip and answer. I will check how to use that. Thanks. – Aafaq Jan 18 '22 at 02:18
  • @Aafaq Please take a [tour] and check out [ask] for tips how to write a good question. – koen Jan 18 '22 at 03:41
  • Okay @koen thanks! – Aafaq Jan 18 '22 at 06:30

0 Answers0