1

我正在使用 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);
    }
  }
4

1 回答 1

2

你有没有包括这条线

pod 'Firebase/MLVisionTextModel'

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

于 2019-12-05T01:07:18.783 回答