0

I hope you are doing well, I am stuck with an strange problem. I have implemented Vision Text Recogniser and after successfully extract the image and assign that image to visionImage but I am getting error = nil and also the result = nil. There is nil coming in result block i have followed the google documentation link https://firebase.google.com/docs/ml-kit/ios/recognize-text . but the result is nil.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {


            imgView.image = pickedImage

            // -----
            let visionImage = VisionImage(image: pickedImage)

            textRecognizer.process(visionImage) { (result, error) in

                guard error == nil, let result = result else {
                    // ...

                    return
                }

                print("THE RESULT", result?.text)

            // -----
        }
        dismiss(animated: true, completion: nil)
    }

Please help me with that or specify why reason of that nil coming in result block. so that I can fix it.

A big Thank you in advance, waiting for your response.

Regards, Azeem Usmani

azeem usmani
  • 517
  • 4
  • 9
  • What image are you using? Also, is the pickedImage there? Do you enter into the if let block? – Fogmeister Dec 30 '19 at 13:25
  • the image is picked from mobile gallery through imagePicker delegate. the pickedImage is the image i have picked from gallery. the type if UIImage. – azeem usmani Dec 30 '19 at 17:54
  • no, I mean, literally... what is the image? Does it actually contain text? Also, does the if let block actually run? – Fogmeister Dec 30 '19 at 18:45
  • You say your result isn’t printed. Does it actually print “THE RESULT nill” or something else? – Fogmeister Dec 30 '19 at 18:46
  • @Fogmeister yes it is printing "“THE RESULT nill”". And i am uploading a visiting card image. – azeem usmani Dec 31 '19 at 09:57
  • What is the output for `print(result)`? – Fogmeister Dec 31 '19 at 10:27
  • @Fogmeister it literally shows nil as output. – azeem usmani Dec 31 '19 at 10:37
  • If `result` was nil then your code wouldn't print "THE RESULT nil" (which you said it is printing). Your `guard let result = result else { return }` would stop that. So... `result.text` is `nil`. But what is the value of `result`? Put `print(result)` in your code and show the output. NOTE: NOT `print(result.text)`. – Fogmeister Dec 31 '19 at 11:11
  • I have printed result not result.text but it still showing same output nil. – azeem usmani Dec 31 '19 at 12:55
  • Can you put your updated code into the question. If result was nil then currently it shouldn’t print anything. Thanks – Fogmeister Dec 31 '19 at 14:02

0 Answers0