Firebase Ml Vision无法识别Image Picker插件拍摄的图像

时间:2019-11-03 05:40:37

标签: firebase flutter ocr firebase-mlkit mlvision

我正在使用firebase_ml_vision包进行文本识别。它在Android方面正常工作,但是当我对其进行测试时,使用image_picker插件拍摄的真实IOS设备无法识别文本。我尝试将其转换为图像Unit8,但同样的问题导致无法读取图像。

我需要转换图像吗?

这里是我的图像选择器功能

    Future<Null> getImage(ImageSource source) async {
    try {
      var image = await ImagePicker.pickImage(source: source);

      var uuid = new Uuid();

      // Step 3: Get directory where we can duplicate selected file.
      Directory directory = await getApplicationDocumentsDirectory();
      String path = directory.path;
      String pathVar = path + '/' + uuid.v1() + '.png';
      await image.copy(pathVar);
      if (image != null) {
        _getImageSize(image);
        _imageFromGallery = image;
        _isLoaded = true;

        notifyListeners();
      } else {
        Flushbar(
          message: "Lütfen Resim Seçiniz",
        );
      }
    } catch (e) {
      _isLoaded = false;
      print(e.toString());
      notifyListeners();
    }
  }

这是我的ml_vision识别文本功能。

Future readText(BuildContext context) async {
    FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(
        Provider.of<CameraProvider>(context).imageFromSource);
    TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
    VisionText readText = await recognizeText.processImage(ourImage);
    List<TextLine> lines = List();
    List<TextElement> words = List();
    List<TextBlock> box = List();

    try {
      for (TextBlock block in readText.blocks) {
        if (block.text != null) {
          box.add(block);
        }
        _textBox = box;
        notifyListeners();

        for (TextLine line in block.lines) {
          if (line.text != null) {
            lines.add(line);
          }

          _textLines = lines;
          notifyListeners();

          for (TextElement word in line.elements) {
            if (word.text != null) {
              words.add(word);
            }

            _textWords = words;
            notifyListeners();
          }
        }
      }
    } catch (e) {
      print(e);
    }
  }

1 个答案:

答案 0 :(得分:2)

您添加了这一行

pod 'Firebase/MLVisionTextModel'
ios/Podfile

并在pod update中运行ios/?如果您不这样做,结果将返回空。