FirebaseML Vision不适用于使用设备相机捕获的图像

时间:2018-09-04 10:59:53

标签: ios swift ocr firebase-mlkit

我指的是示例代码

[https://codelabs.developers.google.com/codelabs/mlkit-ios/#0

此处提供检测图像中的文本的功能。 如果我用发票图像(扫描的文档)运行此代码,则可以正常工作。但是,当我去捕获发票打印输出图像时,并不能给我任何准确的结果。 在给定的示例中,我刚刚启动了相机,并将捕获的图像提供给

runTextRecognition(with: imgSelectedImage)

帮我找出问题所在

更新

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    imgSelectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    runTextRecognition(with: imgSelectedImage)
    }


[![func runTextRecognition(with image: UIImage) {
  let visionImage = VisionImage(image: image)
    textDetector.detect(in: visionImage) { features, error in
      self.processResult(from: features, error: error)
    }
  }

 func processResult(from text: \[VisionText\]?, error: Error?) {
    removeFrames()
    guard let features = text, let image = imageView.image else {
      return
    }
    for text in features {
      if let block = text as? VisionTextBlock {
        for line in block.lines {
          for element in line.elements {
            self.addFrameView(
              featureFrame: element.frame,
              imageSize: image.size,
              viewFrame: self.imageView.frame,
              text: element.text
            )
          }
        }
      }
    }
  }

0 个答案:

没有答案