简体   繁体   中英

How to make sure the VisionImage (from Google's ML Kit in Firebase) object is processed right?

I am trying to read text from the image in Assets folder named "quote". But am getting the error "error 2: unable to process VisionImage" printed every time.

How do I make sure VisionImage is processed the right way and get the text from the image "quote"?

    let vision = Vision.vision()
    let textRecognizer = vision.cloudTextRecognizer()
    let options = VisionCloudTextRecognizerOptions()
    options.languageHints = ["en", "hi"]
    guard let img = UIImage(named: "quote")
        else {
            print("error 1: image not there")
            return
        }
    let visionImage = VisionImage(image: img)

    textRecognizer.process(visionImage) { result, error in
        guard error == nil, let result = result else {
            print("error 2: unable to process VisionImage")
            return
        }

There are many reasons that textRecognizer.process() can return an error. It would be helpful if you check the logcat trace to see what exactly went wrong.

Also, you may want to follow the mlkit quickstart app cloudtextrecognition implementation here to see if it works for you.

https://github.com/firebase/quickstart-android/tree/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/kotlin/cloudtextrecognition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM