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.