应用程序用户界面将冻结iOS的Firebase MLKit

时间:2018-11-05 04:53:36

标签: ios swift ocr firebase-mlkit

我有以下代码用于使用Firebase mlkit for ios识别文本

func runTextRecognition(with image: UIImage) {

            let visionImage = VisionImage(image: image)
            textRecognizer?.process(visionImage){ result, error in
                guard error == nil, let result = result else {

                    self.addImageToView()

                    return
                }

                for block in result.blocks {
                    self.countDown = self.countDown + 1
                    let blockText = block.text

                    let blockFrame = block.frame

                 //do action
                        }
                        else{

                            print("Tag Total Block Count \(result.blocks.count)")
                            print("Tag Milena \(self.countDown)")

                 /*happen only with some images
                   countDown is less than result.blocks.count
                   UI will be freeze*/

                            if (result.blocks.count == self.countDown){
                                self.countDown = 0
                                print("Tag All Milena \(result.blocks.count)")
                                self.addImageToView()
                            }
                        }
                    }
                }
            }
        }

当在块内无法识别文本时,有时应用UI将在循环之间冻结。我在代码中也有注释。请任何人都可以帮助我解决这个问题。

0 个答案:

没有答案