I am using this code for extracting text from image, First time the code runs perfectly after that its start giving this error message [coreml] Failed to get the home directory when checking model path. Here is the code that I am using to extract text form image. This is the same code that I have copied from that I have copied from apple documentation
func requestORC(image: UIImage) {
// guard let cgImage = UIImage(named: "test")?.cgImage else { return }
guard let cgImage = image.cgImage else { return }
// / Create a new image-request handler.
let requestHandler = VNImageRequestHandler(cgImage: cgImage)
// Create a new request to recognize text.
let request = VNRecognizeTextRequest(completionHandler: recognizeTextHandler)
do {
// Perform the text-recognition request.
try requestHandler.perform([request])
} catch {
print("Unable to perform the requests: \(error).")
}
}
func recognizeTextHandler(request: VNRequest, error: Error?) {
guard let observations =
request.results as? [VNRecognizedTextObservation] else {
return
}
let recognizedStrings = observations.compactMap { observation in
// Return the string of the top VNRecognizedText instance.
return observation.topCandidates(1).first?.string
}
// Process the recognized strings.
// print(recognizedStrings)
self.recognizedStrings = recognizedStrings
}
Getting rid of the error in simulator...
It may sound very strange but the
Failed to get the home directory when checking model patherror occurs in Xcode simulator only when you running a text recognition app with the default.accuratecase of a request's recognition level. Change the value to.fastand the error will disappear.It should also be said that when running the code on an actual device, the above error does not appear at all.
Here's the code: