0

我指的是示例代码

[ 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
            )
          }
        }
      }
    }
  }
4

0 回答 0