【问题标题】:Instance of 'Future<String>' How to solve it'Future<String>' 的实例如何解决
【发布时间】:2022-01-20 11:08:39
【问题描述】:

我正在使用颤振,我试图从我之前设置的 shared_preferences 中获取一个值,并将其显示在一个文本小部件中。但获取 Future 的实例而不是值。这是我的代码:

String _recog(imglib.Image img) {
    List input = imageToByteListFloat32(img, 112, 128, 128);
    input = input.reshape([1, 112, 112, 3]);
    List output = List(1 * 192).reshape([1, 192]);
    interpreter.run(input, output);
    output = output.reshape([192]);
    e1 = List.from(output);

    return compare(e1).toString();
  }

  Future<String> compare(List currEmb) async {
    var firdoc = await _firestore
        .collection('allfaces')
        .doc(_auth.currentUser.uid)
        .collection('faces')
        .get();
    if (data.length == 0) return Future.value("No Face saved");
    double minDist = 999;
    double currDist = 0.0;
    String predRes = "NOT RECOGNIZED";
    for (var doc in firdoc.docs) {
      currDist = 0.0;
      for (int i = 0; i < currEmb.length; i++) {
        currDist += (currEmb[i] - doc.data()['embedding'][i]).abs().toDouble();
      }
      if (currDist < minDist) {
        minDist = currDist;
        predRes = doc.data()['name'];
      }
    }
    print(minDist.toString() + " " + predRes);
    return predRes;
  }

【问题讨论】:

  • 欢迎来到 Stack Overflow。您在这里遇到的具体问题是什么?预期的行为是什么,实际的行为是什么?
  • 您在寻找return await compare(e1)吗?
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: android firebase flutter dart google-cloud-firestore


【解决方案1】:

如果我没记错的话,您尝试将图像保存在 shared_preferences 中。转换结果的字符串很长,但 shared_preferences 有存储限制

【讨论】:

    猜你喜欢
    • 2023-02-11
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 2021-07-26
    • 2019-08-12
    • 1970-01-01
    相关资源
    最近更新 更多